HIDDevice.cpp
Go to the documentation of this file.
00001 /*
00002  * HIDDevice.cpp
00003  *
00004  *  Created on: Oct 24, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <telekyb_hid/HIDDevice.hpp>
00009 
00010 #include <ros/console.h>
00011 
00012 namespace TELEKYB_NAMESPACE
00013 {
00014 
00015 HIDDevice::HIDDevice(unsigned short int vendorID_ , unsigned short int productID_)
00016         : handle(NULL)
00017 {
00018         vendorID = vendorID_;
00019         productID = productID_;
00020 
00021         init();
00022 }
00023 
00024 HIDDevice::~HIDDevice()
00025 {
00026         close();
00027 }
00028 
00029 bool HIDDevice::init()
00030 {
00031         handle = hid_open(vendorID, productID, NULL);
00032         if (handle) {
00033 
00034         } else {
00035                 ROS_ERROR("Unable to open HID Device %04hx %04hx", vendorID, productID);
00036                 return false;
00037         }
00038 
00039         wchar_t wstr[256];
00040         int res;
00041 
00042         wstr[0] = 0x0000;
00043         res = hid_get_manufacturer_string(handle,wstr,256);
00044         if (res < 0) {
00045                 ROS_ERROR("Unable to get manufacturer string from HID Device %04hx %04hx", vendorID, productID);
00046         } else {
00047                 manufacturerString = std::wstring(wstr);
00048         }
00049 
00050         wstr[0] = 0x0000;
00051         res = hid_get_product_string(handle,wstr,256);
00052         if (res < 0) {
00053                 ROS_ERROR("Unable to get product string from HID Device %04hx %04hx", vendorID, productID);
00054         } else {
00055                 productString = std::wstring(wstr);
00056         }
00057 
00058         wstr[0] = 0x0000;
00059         res = hid_get_serial_number_string(handle,wstr,256);
00060         if (res < 0) {
00061                 ROS_ERROR("Unable to get serial number string from HID Device %04hx %04hx", vendorID, productID);
00062         } else {
00063                 serialNumber = std::wstring(wstr);
00064         }
00065 
00066 
00067         ROS_INFO("Opened HID Device: %ls", productString.c_str());
00068         return true;
00069 }
00070 
00071 bool HIDDevice::isOpen() const
00072 {
00073         return (handle != NULL);
00074 }
00075 
00076 void HIDDevice::close()
00077 {
00078         if (handle) {
00079                 hid_close(handle);
00080         }
00081 }
00082 
00083 std::wstring HIDDevice::getWSerialNumber() const
00084 {
00085         return serialNumber;
00086 }
00087 
00088 std::wstring HIDDevice::getWManufacturerString() const
00089 {
00090         return manufacturerString;
00091 }
00092 
00093 std::wstring HIDDevice::getWProductString() const
00094 {
00095         return productString;
00096 }
00097 
00098 
00099 std::string HIDDevice::getSerialNumber() const
00100 {
00101         std::string temp;
00102         temp.assign(serialNumber.begin(),serialNumber.end());
00103         return temp;
00104 }
00105 
00106 std::string HIDDevice::getManufacturerString() const
00107 {
00108         std::string temp;
00109         temp.assign(manufacturerString.begin(),manufacturerString.end());
00110         return temp;
00111 }
00112 
00113 std::string HIDDevice::getProductString() const
00114 {
00115         std::string temp;
00116         temp.assign(productString.begin(),productString.end());
00117         return temp;
00118 }
00119 
00120 
00121 } /* namespace telekyb */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_hid
Author(s): mriedel
autogenerated on Mon Nov 11 2013 11:14:51