Reading the measured time out of a usb connected timer

Viewed 70

I'm new here and somewhere feel I don't have enough knowledge to have the right to ask my question (seeing all the complicated questions here) but I don't know what else to do.

First I'll explain my goal. We want to livestream competitions and in these competitions a timer is running (just like you would see in a running competition). There's a whole (working) setup behind this, but what it comes down to is the time is measured by a Hengstler Tico 773 counter, which has a USB-connection. I want to import the time the Tico counter is displaying on my windows pc.

I've gone a long way and have gotten to the point where my (mostly copied from tutorials and slightly adapted) python script can actually 'see' the connected tico counter using usblib and pyUSB. In the manual (link) from page 19 (further down there's English pages) it explains I should send an ASCII signal and then I would get a value back from it. it also gives codes you can send and what you then get in return.

I have no idea how to send a ASCII signal through usb or how to receive a signal that the Tico counter would send out. I've tried things like dev.read('ASCII signal that should get me a value') etc. but to no avail. The manual speaks of a generic interface, I'm not even sure what that is. Is there a way to 'create' a generic interface and then use that to talk with the Tico timer?

Here's the code I'm at now (which is not working, I'm getting an array with only zero's in return in the final print message). Is there anyone that can help with this?

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)

# was it found?
if dev is None:
    raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT)

assert ep is not None

# write the data
ep.write('test')

msg = 'CNT RCR'.encode('ascii')

dev.write(ep,msg)
msg2 = dev.read(ep, 13)
print(msg2)

#dev.ctrl_transfer(msg)

Edit: did some more tests. If I make the array longer (99 in stead of 13) I get an array with 99 zeros in stead of 13 also when I don't write anything to the endpoint. If I change the last lines to this:

msg = 'CNT RCR'.encode('ascii')

dev.write(ep,msg)
msg2 = dev.read(ep, 99)
print('message I send through dev.write is', msg)
print('dev,write(ep,msg) is', dev.write(ep,msg))
print('dev.read(ep,20 is', dev.read(ep, 20))

I get this as output:

message I send through dev.write is b'CNT RCR' dev,write(ep,msg) is 7 dev.read(ep,20 is array('B', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

0 Answers
Related