usb_tc08_get_unit_info() from Python 3.9

Post general discussions on using our drivers to write your own software here
Post Reply
jro@team
Newbie
Posts: 0
Joined: Fri Jul 22, 2022 9:22 am

usb_tc08_get_unit_info() from Python 3.9

Post by jro@team »

Is there a working example of this? It seems totally broken to me. I'd expect this to sort of work:

Code: Select all

from picosdk.usbtc08 import usbtc08, USBTC08_INFO
from ctypes import byref

infs = USBTC08_INFO()
hdl = usbtc08.usb_tc08_open_unit()
ok = usbtc08.usb_tc08_get_unit_info(hdl,byref(infs))

print(infs)
print(hdl)
print(infs.HardwareVersion)
try:
    print(infs.szSerial)
except:
    print("fail")

usbtc08.usb_tc08_close_unit(hdl)
However, I always get a "fail" when printing the serial number string, - removing the try .. except says szSerial doesn't exist (!); and the values in infs don't change after the call to usb_tc08_get_unit_info(), even though there's no error returned

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: usb_tc08_get_unit_info() from Python 3.9

Post by Martyn »

Can you check the class structure definition for USBTC08_INFO in usbtco8.py as it looks like the wrong closing bracket is used in szSerial

I can't check if this is the issue as I don't have access to a TC08 to try.
Martyn
Technical Support Manager

NeilH
PICO STAFF
PICO STAFF
Posts: 265
Joined: Tue Jul 18, 2017 8:28 am

Re: usb_tc08_get_unit_info() from Python 3.9

Post by NeilH »

The repository on GitHub has had this fix applied now. If the issue persists please let us know and we can look into this further.
Neil
Technical Support Engineer

jro@team
Newbie
Posts: 0
Joined: Fri Jul 22, 2022 9:22 am

Re: usb_tc08_get_unit_info() from Python 3.9

Post by jro@team »

Thanks NeilH. That fix doesn't work, but I've had a look at what I think should work and come up with this:

Code: Select all

from picosdk.usbtc08 import usbtc08, USBTC08_INFO
from ctypes import Structure, byref, c_char, c_int16, sizeof

class myUSBTC08_INFO(Structure):
    _pack_ = 1
    _fields_ = [
        ("size", c_int16),
        ("DriverVersion", c_char * 12),
        ("PicoppVersion", c_int16),
        ("HardwareVersion", c_int16),
        ("Variant", c_int16),
        ("Serial", c_char * 11),
        ("CalDate", c_char * 9)
    ]
 
infs = myUSBTC08_INFO()
infs.size = sizeof(infs)  # figure out correct value of size field
hdl = usbtc08.usb_tc08_open_unit()
ok = usbtc08.usb_tc08_get_unit_info(hdl,byref(infs))
I've had to use "magic numbers" (12, 11, 9) for the string field lengths because the Python library doesn't expose the values that are available in the C header. I assume if you do a fix you'll do this properly!

Also, if I use usb_tc08_get_unit_info2() to get the fields individually, I get bytes() objects instead, and everything looks much the same except for PicoppVersion, which comes back as 256 from usb_tc08_get_unit_info() but b'1.0' from usb_tc08_get_unit_info2(). I can't find any documentation which shows the translation from a c_int16 to a bytes(), but I'm guessing the MSB is the major part of the version number, and the LSB is the minor part.

jro@team
Newbie
Posts: 0
Joined: Fri Jul 22, 2022 9:22 am

Re: usb_tc08_get_unit_info() from Python 3.9

Post by jro@team »

Bump. This still isn't officially fixed in the github repo, the "Fix typo" of July 22nd has no effect at all.

jro@team
Newbie
Posts: 0
Joined: Fri Jul 22, 2022 9:22 am

Re: usb_tc08_get_unit_info() from Python 3.9

Post by jro@team »

Bump again. Still no fix for a bug, though you're apparently happy enough to add new features.

Post Reply