phidget_manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <ros/ros.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 
24  : _manHandle(0)
25 {
26  CPhidgetManager_create(&_manHandle);
27  CPhidgetManager_open((CPhidgetManagerHandle) _manHandle);
28 
29  sleep(2);
30 }
31 
33 {
34  // Close the manager
35  CPhidgetManager_close((CPhidgetManagerHandle) _manHandle);
36  CPhidgetManager_delete((CPhidgetManagerHandle) _manHandle);
37 
38  usleep(500000); //0.5s
39 }
40 
41 auto PhidgetManager::getAttachedDevices()-> std::vector<AttachedDevice>
42 {
43  CPhidgetHandle* phidgetList;
44  int count;
45  ROS_INFO("getting attached Devices");
46  CPhidgetManager_getAttachedDevices((CPhidgetManagerHandle) _manHandle, &phidgetList, &count);
47 
48  std::vector<AttachedDevice> attachedDevices;
49  int serialNumber;
50  const char *name;
51 
52  // Iterate over the returned Phidget data
53  for (int i = 0; i < count; i++) {
54  CPhidget_getDeviceName(phidgetList[i], &name);
55  CPhidget_getSerialNumber(phidgetList[i], &serialNumber);
56  ROS_INFO("Found %s, with serial: %d", name, serialNumber);
57  // Store name and serial number into a persistent variable
58  AttachedDevice device{serialNumber, name};
59  attachedDevices.push_back(device);
60  }
61 
62  // Use the Phidget API to free the memory in the phidgetList Array
63  CPhidgetManager_freeAttachedDevicesArray(phidgetList);
64 
65  return attachedDevices;
66 }
auto getAttachedDevices() -> std::vector< AttachedDevice >
#define ROS_INFO(...)
int i
Definition: tablet_leer.c:27
CPhidgetManagerHandle _manHandle


cob_phidgets
Author(s): Florian Weisshardt
autogenerated on Wed Apr 7 2021 02:11:43