USB TC-08 in python

Post general discussions on using our drivers to write your own software here
cwhite00
Newbie
Posts: 0
Joined: Fri Jan 06, 2012 12:54 pm

USB TC-08 in python

Post by cwhite00 » Fri Jan 06, 2012 1:09 pm

Hi,

I am hoping someone a lot more clued up on programming can help me with this:

Here is the code I am using

Code: Select all

import ctypes

mydll = ctypes.windll.LoadLibrary('usbtc08.dll')
device = mydll.usb_tc08_open_unit()
mydll.usb_tc08_set_mains(device, 0)

import numpy as np
temp = np.zeros( (9,), dtype=np.float32)
overflow_flags = np.zeros( (9,), dtype=np.int16)


for i in range(0,9):
    mydll.usb_tc08_set_channel(device, i, 'K' )
    
mydll.usb_tc08_get_single( device, temp.ctypes.data, overflow_flags.ctypes.data, 0) 

temp
The result I get is:


1
1
0
0
0
0
0
0
0
0
1
array([ 22.58154488, nan, nan, nan,
nan, nan, nan, nan, nan], dtype=float32)

There seems to be a problem with the 'mydll.usb_tc08_set_channel command'
It will accept 0 but not 1 - 8. This is why I only get the cold junction temperature.

Does anyone have any ideas??

Hitesh
Site Admin
Site Admin
Posts: 2806
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh » Tue Jan 10, 2012 1:22 pm

Hi cwhite00,

Looking at your programming calls, it would be helpful if you can call usb_tc08_get_last_error after each call to set the channel and send in the error codes returned by the function.

Alternatively, just try setting the cold junction and channels 1 and 2, and send in the error codes.

Have you got thermocouples in all of the ports?

Unfortunately I have not programmed using Python before.

Regards,
Hitesh

Technical Support Engineer

sgunthr
Newbie
Posts: 0
Joined: Fri Jan 20, 2012 6:14 pm

Re: USB TC-08 in python

Post by sgunthr » Fri Jan 20, 2012 6:21 pm

Hello,
Using cwhite00's code I get an: "AttribueError: 'numpy.ndarray' object has no attribute 'ctypes'"

Any one know why?

miky
Newbie
Posts: 0
Joined: Mon May 27, 2013 3:22 pm

Re: USB TC-08 in python

Post by miky » Tue May 28, 2013 1:53 pm

did any one resolve this problem.
I get the same result. The error that i get after each channel settings is:
<_FuncPtr object at 0x03681D50>

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

Re: USB TC-08 in python

Post by Martyn » Tue Jun 04, 2013 9:45 am

This code, supplied by Miky, works.

Code: Select all

import ctypes
import numpy as np
from ctypes import *
mydll = ctypes.windll.LoadLibrary('usbtc08.dll')
device = mydll.usb_tc08_open_unit()
mydll.usb_tc08_set_mains(device,50)

temp = np.zeros( (9,), dtype=np.float32)
overflow_flags = np.zeros( (1,), dtype=np.int16)
mydll.usb_tc08_set_channel(device, 0, 0 )
tc_type=ord('K')
for i in xrange(1,3):
    mydll.usb_tc08_set_channel(device,i,tc_type)

mydll.usb_tc08_get_single( device, temp.ctypes.data, overflow_flags.ctypes.data, 0) 
mydll.usb_tc08_close_unit(device)
print temp[0],temp[1],temp[2]
Martyn
Technical Support Manager

scls19fr
Active User
Active User
Posts: 15
Joined: Fri Mar 13, 2009 1:14 pm

Re: USB TC-08 in python

Post by scls19fr » Mon Jun 15, 2015 8:53 am

Hello,

Here is some Python code to use Pico TC-08 USB with DLL in Python using usb_tc08_get_single.

[The extension py has been deactivated and can no longer be displayed.]

[The extension py has been deactivated and can no longer be displayed.]

TC08USB class should be improve to support other methods.

Kind regards
Last edited by scls19fr on Mon Jun 15, 2015 11:18 am, edited 2 times in total.

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

Re: USB TC-08 in python

Post by Martyn » Mon Jun 15, 2015 9:58 am

Thank you for uploading your code.

I have added .py as an allowable extension
Martyn
Technical Support Manager

Anonymoose
Newbie
Posts: 0
Joined: Thu Sep 07, 2017 4:18 pm

Re: USB TC-08 in python

Post by Anonymoose » Thu Sep 07, 2017 4:33 pm

For MacOS:

Install picoscope6. In the Applications right click on Picoscope6>Show Package Contents. Find the driver at Contents>Resources>lib>libusbtc08.2.dylib.

You can interface with the tc08 library via the python library ctypes.

Code: Select all

import ctypes as C

tc08=C.CDLL("libusbtc08.2.dylib")

temp_array_obj=C.c_float*9
overflow_obj=C.c_int16
chan_obj=C.c_int16
tc_obj=C.c_char
units_obj=C.c_int16

temp_array=temp_array_obj()
overflow=overflow_obj()
chan=chan_obj()
tc=tc_obj()
units=units_obj()

# Plug a type J thermocouple into channel 4 on the tc08

chan.value=4
tc.value='J'
units.value=0

# Find the tc08
handle=tc08.usb_tc08_open_unit()

# Initialize the channel
tc08.usb_tc08_set_channel(handle,chan,tc)

# Make a single measurement
tc08.usb_tc08_get_single(handle,temp_array,overflow,units)

print temp_array[4] # temp_array[0] is the cold junction temperature


Hitesh
Site Admin
Site Admin
Posts: 2806
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh » Mon Sep 11, 2017 8:36 am

Hi Anonymoose,

Thank you for sharing your code :D

Best wishes,
Hitesh

Technical Support Engineer

colinb
Newbie
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am

Re: USB TC-08 in python

Post by colinb » Thu Dec 14, 2017 7:57 am

Hello,
I have tried using the code as supplied by Martyn to control a TC-08 temperature logger, but am getting the following error
mydll.usb_tc08_get_single(device, temp.ctypes.data, overflow_flags.ctypes.data, 0)
ctypes.ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert
I am using Python 3.5.2 | Anaconda 4.2.0 (64-bit) on a windows 10 PC with 64 bit architecture, and the driver I am using is the 64 bit driver usbtc08.dll provided by the SDK PicoSDK 10.6.12 (64-bit)
I have also received the same error when using the code supplied by scls19fr
Any ideas what could be going wrong?
Many thanks for your help :)
Colin

Hitesh
Site Admin
Site Admin
Posts: 2806
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh » Fri Dec 15, 2017 10:37 am

Hi colinb,

The temp buffer should be an array of 9 floating point numbers. Please check the data type used for this array.

If you are still having trouble, please post your code here. You may also wish to refer to some of the Customer examples that we have linked to from our GitHub repository.

Regards,
Hitesh

Technical Support Engineer

colinb
Newbie
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am

Re: USB TC-08 in python

Post by colinb » Fri Dec 15, 2017 10:56 am

Hello Hitesh,
Thank you for your kind reply and help.

The code I am using is shown here

Code: Select all

import ctypes
import numpy as np
from ctypes import *
mydll = ctypes.windll.LoadLibrary('usbtc08.dll')
device = mydll.usb_tc08_open_unit()
mydll.usb_tc08_set_mains(device,50)

temp = np.zeros( (9,), dtype=np.float32)
overflow_flags = np.zeros( (1,), dtype=np.int16)
mydll.usb_tc08_set_channel(device, 0, 0 )
tc_type=ord('K')
for i in range(1,3):
    mydll.usb_tc08_set_channel(device,i,tc_type)
print(temp.ctypes.data)
mydll.usb_tc08_get_single( device, temp.ctypes.data, overflow_flags.ctypes.data, 0)
mydll.usb_tc08_close_unit(device)
print(temp[0],temp[1],temp[2])
The datatype used for the temp buffer is indeed an array of of 9 floating point numbers. And if I ask to print temp i get [ 0. 0. 0. 0. 0. 0. 0. 0. 0.].
However if I probe the query temp.ctypes.data, the the repsonse I get is 30910073648. I suspect this may be the issue but do not know what to do about it.
Best regards,
Colin

Hitesh
Site Admin
Site Admin
Posts: 2806
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh » Mon Dec 18, 2017 1:45 pm

Hi Colin,

Have you tried running the application with the 32-bit usbtc08.dll? Is the PicoLog application also installed on your PC?

Regards,
Hitesh

Technical Support Engineer

colinb
Newbie
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am

Re: USB TC-08 in python

Post by colinb » Thu Dec 21, 2017 1:19 pm

Hello Hitesh,
Thank you for your reply.
When I run with the 32 bit driver (and the picolog application installed) I get the following error

Traceback (most recent call last):
File "temp.py", line 4, in <module>
mydll = ctypes.windll.LoadLibrary('usbtc08.dll')
File "C:\Users\colinb\AppData\Local\Continuum\Anaconda3\lib\ctypes\__init__.py", line 425, in LoadLibrary
return self._dlltype(name)
File "C:\Users\colinb\AppData\Local\Continuum\Anaconda3\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

Thank you again for your help.
Colin

Hitesh
Site Admin
Site Admin
Posts: 2806
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh » Wed Jan 03, 2018 11:11 am

Hi Colin,

Did you use a 32-bit Python environment or a 64-bit Python environment for this test?

Regards,
Hitesh

Technical Support Engineer

Post Reply