Le 16/09/2016 à 01:21, Joe a écrit :
> Am 15.09.2016 um 12:11 schrieb Joe:
>>>> What's the best method to install it?
>> Solved: pip install hidapi
>>
> This is now working with the usb hid interface of the UT61B DMM:
> hid.device.get_manufacturer_string,
> hid.device.get_product_string,
> hid.device.get_serial_number_string and
> hid.enumerate.
>
> But I could not find descriptions or documentation or samples of the
> following methods and properties of hid.device:
> error, close, open, open_path, read, write, send_feature_report.
> Unfortunetaly I see no source in the package, only a pyd file.
>
> Any hint, any idea?
> Thanx -- Joe
>
Even if it is not the right place (PyUSB mailing list) here is an example :

class MyDevice(object):
     def __init__(self, vendor_id=0xXXXX, product_id=0xYYYY, path=None):

         self.vendor_id = vendor_id
         self.product_id = product_id
         self.path = path

         if path :
             self.__dev = hid.Device(path=path)
         else :
             self.__dev = hid.Device(self.vendor_id, self.product_id)

         self.manufacturer = self.__dev.manufacturer
         self.product = self.__dev.product

     def GetFeature1(self):
         return struct.unpack("B", 
self.__dev.get_feature_report(HID_FEATURE_1, 5)[4])[0]

     def SetFeature2(self, value):
         self.__dev.send_feature_report(struct.pack("<BBBBL", 
HID_FEATURE_2 0,0,0, value))

     def RequestSomeData(self):
         self.__dev.write(struct.pack("BBBB", 
HID_REPORT_OUT_REQUEST_SOME_DATA, 0,0,0))

     def GetData(self):
         data = self.__dev.read(64, 1000)
         if data :
             report_id = struct.unpack("B", data[0])[0]
             if report_id == HID_REPORT_IN_MY_NOP :
                 return None,
             elif report_id == HID_REPORT_IN_1 :
                 value = struct.unpack("<L", data[4:8])[0]
                 return 1, value
             elif report_id == HID_REPORT_IN_2 :
                 value = struct.unpack("<LHHHHHHHHHHHH", data[4:])
                 return 2, value[0], value[1:]
             else :
                 print "???"

d = MyDevice()
d.SetFeature2(2)
while True :
     data = d.GetData()
     if data :
         if data[0] == None :
             print "NOP"
         elif data[0] == 1 :
             print "1 : %8.8X" % data[1]
         elif data[0] == 2 :
             print "2 : %3.3X" % data[1], data[2]

Hope this helps.

Nicolas

------------------------------------------------------------------------------
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to