Test and Measurement Forum

USB TC-08 in python

Post general discussions on using our drivers to write your own software here

USB TC-08 in python

Postby 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??
cwhite00
Newbie
 
Posts: 0
Joined: Fri Jan 06, 2012 12:54 pm

Re: USB TC-08 in python

Postby 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
Hitesh
Site Admin
Site Admin
 
Posts: 2518
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Postby 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?
sgunthr
Newbie
 
Posts: 0
Joined: Fri Jan 20, 2012 6:14 pm

Re: USB TC-08 in python

Postby 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>
miky
Newbie
 
Posts: 0
Joined: Mon May 27, 2013 3:22 pm

Re: USB TC-08 in python

Postby 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
Martyn
Site Admin
Site Admin
 
Posts: 2819
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: USB TC-08 in python

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

tc08usb.py
(3.88 KiB) Downloaded 442 times

sample_tc08usb.py
(360 Bytes) Downloaded 385 times


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.
scls19fr
Active User
Active User
 
Posts: 15
Joined: Fri Mar 13, 2009 1:14 pm

Re: USB TC-08 in python

Postby 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
Martyn
Site Admin
Site Admin
 
Posts: 2819
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: USB TC-08 in python

Postby 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

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

Re: USB TC-08 in python

Postby Hitesh » Mon Sep 11, 2017 8:36 am

Hi Anonymoose,

Thank you for sharing your code :D

Best wishes,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2518
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Postby 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
colinb
Newbie
 
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am

Re: USB TC-08 in python

Postby 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
Hitesh
Site Admin
Site Admin
 
Posts: 2518
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Postby 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
colinb
Newbie
 
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 2 guests