PT-104 Python Example
-
- Newbie
- Posts: 0
- Joined: Thu Jan 12, 2017 8:38 pm
PT-104 Python Example
Are there any programming examples to set up the PT104 using Python? I was able to load the .dll file and found the post from topic23281.html but a more explicit example that shows how to use the GetUnitInfo fuction would be helpful.
-
- Newbie
- Posts: 0
- Joined: Thu Jan 12, 2017 8:38 pm
Re: PT-104 Python Example
OK, found a working solution for the enumerate and getunitinfo functions on Python 3.5. Anyone able to get a value from the getvalue function?
import ctypes
from enum import IntEnum
import numpy as np
# load driver
mydll = ctypes.cdll.LoadLibrary('usbpt104.dll')
USBPT104_MIN_WIRES = 2
USBPT104_MAX_WIRES = 4
class CtypesEnum(IntEnum):
@classmethod
def from_param(cls, obj):
return int(obj)
class UsbPt104Channels(CtypesEnum):
USBPT104_CHANNEL_1 = 1
USBPT104_CHANNEL_2 = 2
USBPT104_CHANNEL_3 = 3
USBPT104_CHANNEL_4 = 4
USBPT104_CHANNEL_5 = 5
USBPT104_CHANNEL_6 = 6
USBPT104_CHANNEL_7 = 7
USBPT104_CHANNEL_8 = 8
USBPT104_MAX_CHANNELS = USBPT104_CHANNEL_8
class UsbPt104DataTypes(CtypesEnum):
USBPT104_OFF = 0
USBPT104_PT100 = 1
USBPT104_PT1000 = 2
USBPT104_RESISTANCE_TO_375R = 3
USBPT104_RESISTANCE_TO_10K = 4
USBPT104_DIFFERENTIAL_TO_115MV = 5
USBPT104_DIFFERENTIAL_TO_2500MV = 6
USBPT104_SINGLE_ENDED_TO_115MV = 7
USBPT104_SINGLE_ENDED_TO_2500MV = 8
class CommunicationType(CtypesEnum):
CT_USB = 0x00000001
CT_ETHERNET = 0x00000002
CT_ALL = 0xFFFFFFFF
class PICO_INFO(CtypesEnum):
PICO_DRIVER_VERSION = 0
PICO_USB_VERSION = 1
PICO_HARDWARE_VERSION = 2
PICO_VARIANT_INFO = 3
PICO_BATCH_AND_SERIAL = 4
PICO_CAL_DATE = 5
PICO_KERNEL_DRIVER_VERSION = 6
# define function argument types
mydll.UsbPt104CloseUnit.argtypes = [ctypes.c_short] #Close the port (do this each time you finish using the device!)
mydll.UsbPt104Enumerate.argtypes = [ctypes.POINTER(ctypes.c_char),ctypes.POINTER(ctypes.c_ulong),CommunicationType] #Get list of attached devices.
mydll.UsbPt104GetUnitInfo.argtypes = [ctypes.c_short, ctypes.POINTER(ctypes.c_char), ctypes.c_short, ctypes.POINTER(ctypes.c_short),PICO_INFO] #Get the batch number and serial number, or the calibration date, of this PT-104 Data Logger.
mydll.UsbPt104GetValue.argtypes = [ctypes.c_short, UsbPt104Channels, ctypes.POINTER(ctypes.c_long), ctypes.c_short] #Get the most recent data reading from a channel.
mydll.UsbPt104OpenUnit.argtypes = [ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_char)] #Open the device through its USB interface.
mydll.UsbPt104SetChannel.argtypes = [ctypes.c_short, UsbPt104Channels, UsbPt104DataTypes, ctypes.c_short] #Specify the sensor type and filtering for a channel.
mydll.UsbPt104SetMains.argtypes = [ctypes.c_short, ctypes.c_ushort]
enum_string = ctypes.create_string_buffer(256)
info_string = ctypes.create_string_buffer(256)
enum_len = ctypes.c_ulong()
info_len = ctypes.c_short(256)
req_len = ctypes.c_short()
handle = ctypes.c_short()
serial = ctypes.create_string_buffer(b'DZ168/050')
mydll.UsbPt104Enumerate (enum_string, ctypes.byref(enum_len),CommunicationType.CT_ALL)
print('Found PicoTech at... %s' % enum_string.value)
#output...
Found PicoTech at... b'USB:DZ168/050'
import ctypes
from enum import IntEnum
import numpy as np
# load driver
mydll = ctypes.cdll.LoadLibrary('usbpt104.dll')
USBPT104_MIN_WIRES = 2
USBPT104_MAX_WIRES = 4
class CtypesEnum(IntEnum):
@classmethod
def from_param(cls, obj):
return int(obj)
class UsbPt104Channels(CtypesEnum):
USBPT104_CHANNEL_1 = 1
USBPT104_CHANNEL_2 = 2
USBPT104_CHANNEL_3 = 3
USBPT104_CHANNEL_4 = 4
USBPT104_CHANNEL_5 = 5
USBPT104_CHANNEL_6 = 6
USBPT104_CHANNEL_7 = 7
USBPT104_CHANNEL_8 = 8
USBPT104_MAX_CHANNELS = USBPT104_CHANNEL_8
class UsbPt104DataTypes(CtypesEnum):
USBPT104_OFF = 0
USBPT104_PT100 = 1
USBPT104_PT1000 = 2
USBPT104_RESISTANCE_TO_375R = 3
USBPT104_RESISTANCE_TO_10K = 4
USBPT104_DIFFERENTIAL_TO_115MV = 5
USBPT104_DIFFERENTIAL_TO_2500MV = 6
USBPT104_SINGLE_ENDED_TO_115MV = 7
USBPT104_SINGLE_ENDED_TO_2500MV = 8
class CommunicationType(CtypesEnum):
CT_USB = 0x00000001
CT_ETHERNET = 0x00000002
CT_ALL = 0xFFFFFFFF
class PICO_INFO(CtypesEnum):
PICO_DRIVER_VERSION = 0
PICO_USB_VERSION = 1
PICO_HARDWARE_VERSION = 2
PICO_VARIANT_INFO = 3
PICO_BATCH_AND_SERIAL = 4
PICO_CAL_DATE = 5
PICO_KERNEL_DRIVER_VERSION = 6
# define function argument types
mydll.UsbPt104CloseUnit.argtypes = [ctypes.c_short] #Close the port (do this each time you finish using the device!)
mydll.UsbPt104Enumerate.argtypes = [ctypes.POINTER(ctypes.c_char),ctypes.POINTER(ctypes.c_ulong),CommunicationType] #Get list of attached devices.
mydll.UsbPt104GetUnitInfo.argtypes = [ctypes.c_short, ctypes.POINTER(ctypes.c_char), ctypes.c_short, ctypes.POINTER(ctypes.c_short),PICO_INFO] #Get the batch number and serial number, or the calibration date, of this PT-104 Data Logger.
mydll.UsbPt104GetValue.argtypes = [ctypes.c_short, UsbPt104Channels, ctypes.POINTER(ctypes.c_long), ctypes.c_short] #Get the most recent data reading from a channel.
mydll.UsbPt104OpenUnit.argtypes = [ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_char)] #Open the device through its USB interface.
mydll.UsbPt104SetChannel.argtypes = [ctypes.c_short, UsbPt104Channels, UsbPt104DataTypes, ctypes.c_short] #Specify the sensor type and filtering for a channel.
mydll.UsbPt104SetMains.argtypes = [ctypes.c_short, ctypes.c_ushort]
enum_string = ctypes.create_string_buffer(256)
info_string = ctypes.create_string_buffer(256)
enum_len = ctypes.c_ulong()
info_len = ctypes.c_short(256)
req_len = ctypes.c_short()
handle = ctypes.c_short()
serial = ctypes.create_string_buffer(b'DZ168/050')
mydll.UsbPt104Enumerate (enum_string, ctypes.byref(enum_len),CommunicationType.CT_ALL)
print('Found PicoTech at... %s' % enum_string.value)
#output...
Found PicoTech at... b'USB:DZ168/050'
Re: PT-104 Python Example
Can we see the code where you are setting up the PT104 and requesting the values.
Martyn
Technical Support Manager
Technical Support Manager
-
- Newbie
- Posts: 0
- Joined: Wed Aug 08, 2018 11:11 am
Re: PT-104 Python Example
Hello everybody,
i just want you to notice that i wrote a wrapper library for python based on the code from forum_name above and code from gruenst from topic31981.html. The git repository can be found at: https://github.com/trombastic/Pico_PT104 comments are welcome.
best wishes,
Martin
i just want you to notice that i wrote a wrapper library for python based on the code from forum_name above and code from gruenst from topic31981.html. The git repository can be found at: https://github.com/trombastic/Pico_PT104 comments are welcome.
best wishes,
Martin
-
- Newbie
- Posts: 0
- Joined: Wed Jan 30, 2019 3:26 pm
Re: PT-104 Python Example
hello trombastic,
Thanks a lot for your good work!
worked for me out of the box on windows.
with picolog installed and a version of python 3.7.2 64 bits:
- copied _init_ locally renamed it PT104.py
-created a test code and it worked fine!
unfortunately could not simply copy code to the forum because of safety issues....
Thanks a lot for your good work!
worked for me out of the box on windows.
with picolog installed and a version of python 3.7.2 64 bits:
- copied _init_ locally renamed it PT104.py
-created a test code and it worked fine!
unfortunately could not simply copy code to the forum because of safety issues....
Re: PT-104 Python Example
.py wasn't one of the accepted extensions, I have now added it.
Martyn
Technical Support Manager
Technical Support Manager