TC-08 Serial using the windows dll in python get_temp issue

Post any questions about our serial port products
Post Reply
Posts: 2
Joined: Thu Jul 02, 2009 4:06 am

TC-08 Serial using the windows dll in python get_temp issue

Post by derklempner »


I've been trying to nut out how to use the TC-08 serial version through python on windows. The device works fine in pico log.

Opening the device and setting up the channels appers to be okay (those functions return '1'), but I can't for the life of me figure out how to use get_temp..

The cold junction returns a value of ~2490, which seems about right sitting in my office, but get_temp always returns zero

Are there any python gurus out there who have acheived serial TC-08 glory on windows? Any pointers would be fantastic :)

Here's a basic version of what I've been fiddling with:
import ctypes as ct

## Interface with the dll
tc08 = ct.windll.LoadLibrary('tc0832')

## set_channel()
tc08_set_channel = tc08.tc08_set_channel
tc08_set_channel.restype = ct.c_short
tc08_set_channel.argtypes = (ct.c_ushort, ct.c_ushort, ct.c_char, ct.c_ushort, ct.c_short, ct.c_short)

def do_tc08_set_channel(port=1, channel=1, tc_type='K', filter_factor=10, offset=0, slope=0):
return tc08_set_channel(port, channel, ct.c_char(tc_type), filter_factor, offset, slope)

## get_temp()
tc08_get_temp = tc08.tc08_get_temp
tc08_get_temp.restype = ct.c_short
tc08_get_temp.argtypes = (ct.POINTER(ct.c_long), ct.c_ushort, ct.c_ushort, ct.c_short)
## argtypes are for (temp (pointer), port, channel, filtered)

## get_cold_junction()
tc08_get_cold_junction = tc08.tc08_get_cold_junction
tc08_get_cold_junction.restype = ct.c_short
tc08_get_cold_junction.argtypes = (ct.POINTER(ct.c_long), ct.c_short)

## End type setup ---------------------------------------------------------------------#

## Open the device
print "Device open:", tc08.tc08_open_unit(1)

## Set up the happy channel we want to use (6 in this case)
channel = 6
print "Channel:", str(channel), "status:", do_tc08_set_channel(1,6,'K',10,0,0)

## So far so good.. now to get a temperature
temp = ct.c_long()
print "get_temp returns:", tc08_get_temp(temp,1,6,0)
print "Temperature:", temp.value

## What about the cold junction?
coldtemp = ct.c_long()
print "get_cold_junction returns:", tc08_get_cold_junction(coldtemp,1)
print "Cold junction Temperature:", coldtemp.value

## Close the device

# End


The above will print out something like:
Device open: 1
Channel: 6 status: 1
get_temp returns: 0
Temperature: 0
get_cold_junction returns: 1
Cold junction Temperature: 2491

Cheers! :)

Posts: 2
Joined: Thu Jul 02, 2009 4:06 am

Post by derklempner »

Mystery solved!

If you call get_temp outside a loop you'll get 0 returned as it seems the pico needs to run through a few cycles before it starts returning temperatures.

I have attached a "How to use the serial TC-08 with python" script for anyone else who might be interested in getting their serial version to work with python in windows.

Cheers :)
How to use the serial TC-08 with python on Windows
(1.75 KiB) Downloaded 588 times

Post Reply