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
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.