PT-104 Python

Post any questions you may have about our current range of USB data loggers
Post Reply
laser-axel
Newbie
Posts: 1
Joined: Fri Jun 02, 2017 7:27 am

PT-104 Python

Post by laser-axel »

Hello,

I am trying to use a PT-104 from python 2.7. The PT-104 is connected via USB a operable
I could not find any good description of what to do to communitate with a PT-104, so I looked into https://github.com/picotech/picosdk-c-e ... pt104con.c
Conclusion: Set things up to use the enumerate function supplied by the usbpt104.dll and see what happens.

I also found the forum thread topic27941.html?hilit=python.

I tried to get the example in abovementioned thread running.
First I got an error from the section:
class CommunicationType(CtypesEnum):
CT_USB = 0x00000001
CT_ETHERNET = 0x00000002
CT_ALL = 0xFFFFFFFF

OverflowError: Python int too large to convert to C long

This is consistent with the usbPT104Api.h, but IIRC enums in C are mapped to int and not unsigned int ??
So I changed the 0xffffffff to 0x7fffffff.
The skript is running without errors but enum_string remains empty

Also changed the communication type resulting in
mydll.UsbPt104Enumerate (enum_string, ctypes.byref(enum_len),CommunicationType.CT_USB)

In the interactive console I get
IN[xx]: mydll.UsbPt104Enumerate (enum_string, ctypes.byref(enum_len),CommunicationType.CT_ALL)
Out[xx]: 315

So I think, I am close to get this up, but I messed up with setting the f*'#*ng datatypes in python. Maybe there is someone out there, to set me on track again.

Thanks in advance.
Axel

p.s. simply using C instead of python is not an option :-(

EDIT:
changed the call to the enumerate function to
status = mydll.UsbPt104Enumerate (enum_string, ctypes.byref(enum_len),CommunicationType.CT_ALL)
print('Found PicoTech at... %s' % enum_string.value)
print('status returned ' + format(status,'X'))

Which gets me the output
Found PicoTech at...
status returned 13B

In the PicoStatus.h I found:
// The serial buffer is too small for the required information.
#define PICO_SERIAL_BUFFER_TOO_SMALL 0x0000013BUL

laser-axel
Newbie
Posts: 1
Joined: Fri Jun 02, 2017 7:27 am

Re: PT-104 Python

Post by laser-axel »

A night of sleep and a few cups of coffe did it.

Will add the lines to get a temperature reading in the thread topic27941.html

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

Re: PT-104 Python

Post by Martyn »

Good to hear :)

The power of coffee :D
Martyn
Technical Support Manager

Post Reply