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 Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2009
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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2291
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 168 times

sample_tc08usb.py
(360 Bytes) Downloaded 134 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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2291
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 1 guest