Hey everyone. I'm new to the USB world and I'm trying to communicate
with the MTI RU-888 RFID Module USB using the python package PyUsb on my
Linux machine. I believe my configurations are all set properly? I'm not
getting any errors.
However, my problem or question is how to write and read (communicate)
with the RFID reader? I'm reading their manual and all the commands are
in hex but should I be sending my strings in decimals? Right now I'm
sending in hex (prefixed with '0x') and when I try to read from the
endpoint or device I get a timeout error. Moreover, once I've 'written'
once already, all subsequent attempts to write also results in a timeout
error. I'm not quite sure how I should proceed from here.
My script currently looks like this:
3 import usb.core
4 import usb.util
5
6 dev = usb.core.find(idVendor=0x1325, idProduct=0xC029)
7 # bInterfaceNumber
8 interface = 0
9 # bConfigurationValue
10 configuration = 1
11
12 # was it found?
13 if dev is None:
14 raise ValueError('Device not found')
15
16 if dev.is_kernel_driver_active(interface) is True:
17 print "Detach kernel driver"
18 dev.detach_kernel_driver(interface)
19 # set the active configuration. With no arguments, the first
20 # configuration will be the active one
21 dev.set_configuration(configuration)
22
23 # get an endpoint instance
24 cfg = dev.get_active_configuration()
25 interface_number = cfg[(0,0)].bInterfaceNumber
26 alternate_setting = usb.control.get_interface(dev, interface_number)
27 intf = usb.util.find_descriptor(
28 cfg, bInterfaceNumber = interface_number,
29 bAlternateSetting = alternate_setting
30 )
31
32 ep = usb.util.find_descriptor(
33 intf,
34 # match the first OUT endpoint
35 custom_match = \
36 lambda e: \
37 usb.util.endpoint_direction(e.bEndpointAddress) == \
38 usb.util.ENDPOINT_OUT
39 )
40
41 assert ep is not None
42
44 # write the data
45 print ep.write('0xC0 0x03 0x12')
The print command gives me '14' which according to the function
definition means I wrote 14 bytes to the endpoint. Now when i run
`ep.read(100)`
I get *** USBError: [Errno 110] Operation timed out
Please respond with any clues or ideas. Your help is much appreciated!
|