5

I'm trying to read voltages from a Tenma 72-7732 multimeter with a HID USB connection using PyUSB and libusb. This is my code so far:

def main():
    import usb.core
    import usb.util
    import usb.backend
    import sys

    #find device

    dev = usb.core.find(idVendor=0x1a86, idProduct=0xe008)

    # did you find it?
    if dev is None:
        raise ValueError('Device not found')
    else:
        print "Device found"


    dev.set_configuration()


    endpoint = dev[0][(0,0)][0]

    data = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, 0, 100000)

    print data

main()

This finds the device, but when it tries to read the data, it gives a timeout error. The multimeter has very bad documentation and support, so I can't go there for help. How can I read the device successfully?

Sophie
  • 85
  • 1
  • 1
  • 6
  • Usually after you have set the configuration for a USB device you have to bind all pipes. Then they are ready for read / write access. – fiscblog Jul 17 '13 at 13:01
  • Thanks! Do you know how to do that in PyUSB? – Sophie Jul 17 '13 at 13:15
  • Actually not, I'm sorry! But have you considered this [documentation of PyUSB](http://pyusb.sourceforge.net/docs/1.0/tutorial.html)? You could try to get the descriptor (like in the example) first. Consider tools like USBlyzer as well, like that you may find issues quite easily. – fiscblog Jul 17 '13 at 13:37
  • Yes, I've looked at the documentation but it doesn't help very much. Adding the descriptor part doesn't change anything; I can easily see descriptors like dev.bLength, but it doesn't help with reading data. Thanks for the advice about USBlyzer; I'll try it out. – Sophie Jul 17 '13 at 14:06
  • USBlyzer solved the problem; thanks! It turns out I had to send an initialization code to the multimeter. – Sophie Jul 22 '13 at 09:47
  • 1
    @Sophie could you please post your working code? I am having the same issue at the moment. – JosephGarrone Dec 17 '13 at 07:39
  • @Sophie If you have found a solution to your problem then please take some time to post it here and accept it as an answer. This will be a great convenience for other users. – ρss Feb 22 '14 at 15:49

1 Answers1

0

I use a simple IR to RS232 adapter which consists of an IR detector strapped Anode to pin 4 and cathode to pin 2 (RX data). When hooked up to my PC with a simple terminal set to 2400 Baud, 7 Data 1 Stop, No parity, No handshake it produces the following string

013651211

which repeats about every 400 ms. The first 5 digits are as read on the meter, digit 6 is decimal point location, digit 8 is function position

VDC = 1 AmpDC = 9

Last digit seems to be auto/manual mixed with sign; the rest I don't need (yet).

jscs
  • 63,694
  • 13
  • 151
  • 195
Will
  • 1