phidget_manager.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #include <ros/ros.h>
00019 #include <cob_phidgets/phidget_manager.h>
00020 #include <stdlib.h>
00021 #include <unistd.h>
00022 
00023 PhidgetManager::PhidgetManager()
00024         : _manHandle(0)
00025 {
00026         CPhidgetManager_create(&_manHandle);
00027         CPhidgetManager_open((CPhidgetManagerHandle) _manHandle);
00028 
00029         sleep(2);
00030 }
00031 
00032 PhidgetManager::~PhidgetManager()
00033 {
00034         // Close the manager
00035         CPhidgetManager_close((CPhidgetManagerHandle) _manHandle);
00036         CPhidgetManager_delete((CPhidgetManagerHandle) _manHandle);
00037 
00038         usleep(500000); //0.5s
00039 }
00040 
00041 auto PhidgetManager::getAttachedDevices()-> std::vector<AttachedDevice>
00042 {
00043         CPhidgetHandle* phidgetList;
00044         int count;
00045         ROS_INFO("getting attached Devices");
00046         CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) _manHandle, &phidgetList, &count);
00047 
00048         std::vector<AttachedDevice> attachedDevices;
00049         int serialNumber;
00050         const char *name;
00051 
00052         // Iterate over the returned Phidget data
00053         for (int i = 0; i < count; i++) {
00054                 CPhidget_getDeviceName(phidgetList[i], &name);
00055                 CPhidget_getSerialNumber(phidgetList[i], &serialNumber);
00056                 ROS_INFO("Found %s, with serial: %d", name, serialNumber);
00057                 // Store name and serial number into a persistent variable
00058                 AttachedDevice device{serialNumber, name};
00059                 attachedDevices.push_back(device);
00060         }
00061 
00062         // Use the Phidget API to free the memory in the phidgetList Array
00063         CPhidgetManager_freeAttachedDevicesArray(phidgetList);
00064 
00065         return attachedDevices;
00066 }


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 21:02:14