Test and Measurement Forum

PT-104 Python Example

Post any questions you may have about our current range of USB data loggers

PT-104 Python Example

Postby forum_name » Thu Jan 12, 2017 8:43 pm

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.
forum_name
Newbie
 
Posts: 0
Joined: Thu Jan 12, 2017 8:38 pm

Re: PT-104 Python Example

Postby forum_name » Tue Jan 17, 2017 6:48 pm

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'
forum_name
Newbie
 
Posts: 0
Joined: Thu Jan 12, 2017 8:38 pm

Re: PT-104 Python Example

Postby Martyn » Tue Jan 24, 2017 11:41 am

Can we see the code where you are setting up the PT104 and requesting the values.
Martyn
Technical Support Manager
Martyn
Site Admin
Site Admin
 
Posts: 2690
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to USB PC Data Loggers

Who is online

Users browsing this forum: No registered users and 0 guests