DHD-API 3.2.2 documentation
 

multiple_devices.cpp

Simple example of multiple-devices programming.

#include <stdio.h>
#include "dhdc.h"



int
main (int  argc,
      char **argv)
{
  int done = 0;
  int deviceCount;
  int deviceID0;
  int deviceID1;



  // get device count
  deviceCount = dhdGetDeviceCount ();
  if (deviceCount < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
    return 0;
  }
  else if (deviceCount < 1) {
    printf ("error: no device detected\n");
  }
  else if (deviceCount < 2) {
    printf ("error: single device detected\n");
  }

  // open the first available device
  if ((deviceID0 = dhdOpenID (0)) < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }

  // open the second available device
  if ((deviceID1 = dhdOpenID (1)) < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }


  // haptic loop
  while (!done) {

    // apply a null force to put the first device in gravity compensation
    if (dhdSetForce (0.0, 0.0, 0.0, deviceID0) < 0) {
      printf ("error: %s\n", dhdErrorGetLastStr ());
      done = 1;
    }

    // apply a null force to put the second device in gravity compensation
    if (dhdSetForce (0.0, 0.0, 0.0, deviceID1) < 0) {
      printf ("error: %s\n", dhdErrorGetLastStr ());
      done = 1;
    }

    // detect button click to quit the haptic loop
    if (dhdGetButton (0)) {
      printf ("exiting...\n");
    }
  }

  // close the connection to the first device
  if (dhdClose (0) < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }

  // close the connection to the second device
  if (dhdClose (1) < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }


  return 0;
}


DHD-API 3.2.2 documentation
Please address any questions to support@forcedimension.com
(C) 2001-2010 - Force Dimension
All Rights Reserved.