00001 00060 #include <ros/ros.h> 00061 #include <cob_phidgets/phidget_manager.h> 00062 #include <stdlib.h> 00063 #include <unistd.h> 00064 00065 PhidgetManager::PhidgetManager() 00066 : _manHandle(0) 00067 { 00068 CPhidgetManager_create(&_manHandle); 00069 CPhidgetManager_open((CPhidgetManagerHandle) _manHandle); 00070 00071 sleep(2); 00072 } 00073 00074 PhidgetManager::~PhidgetManager() 00075 { 00076 // Close the manager 00077 CPhidgetManager_close((CPhidgetManagerHandle) _manHandle); 00078 CPhidgetManager_delete((CPhidgetManagerHandle) _manHandle); 00079 00080 sleep(0.5); 00081 } 00082 00083 auto PhidgetManager::getAttachedDevices()-> std::vector<AttachedDevice> 00084 { 00085 CPhidgetHandle* phidgetList; 00086 int count; 00087 ROS_INFO("getting attached Devices"); 00088 CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) _manHandle, &phidgetList, &count); 00089 00090 std::vector<AttachedDevice> attachedDevices; 00091 int serialNumber; 00092 const char *name; 00093 00094 // Iterate over the returned Phidget data 00095 for (int i = 0; i < count; i++) { 00096 CPhidget_getDeviceName(phidgetList[i], &name); 00097 CPhidget_getSerialNumber(phidgetList[i], &serialNumber); 00098 ROS_INFO("Found %s, with serial: %d", name, serialNumber); 00099 // Store name and serial number into a persistent variable 00100 AttachedDevice device{serialNumber, name}; 00101 attachedDevices.push_back(device); 00102 } 00103 00104 // Use the Phidget API to free the memory in the phidgetList Array 00105 CPhidgetManager_freeAttachedDevicesArray(phidgetList); 00106 00107 return attachedDevices; 00108 }