USB TC-08 in python

Post general discussions on using our drivers to write your own software here
colinb
Newbie
Posts: 0
Joined: Thu Dec 14, 2017 7:51 am

Re: USB TC-08 in python

Post by colinb »

Hello Hitesh,
Happy new year and thank you for the reply :D
typing python on the command line I get:
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
I believe it is the 64 bit python envirnoment...
when I run
import sys
print("%x" % sys.maxsize, sys.maxsize > 2**32)
I get '7fffffffffffffff True' as the response indicating it is a 64 bit python architectecture.
Thank you,
Colin

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh »

Hi Colin,

Happy New Year to you too :)

Please try the 32-bit dll with a 32-bit Python environment.

Regards,
Hitesh

Software Dev. Engineer

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

Re: USB TC-08 in python

Post by colinb »

Hi Hitesh,
Thank you, I can confirm that when I use 32 bit python with the 32 bit driver the program works fine.
However, the software I am using controls other devices that require me to use 64 bit python.
Do you know how I can fix the problem of using a 64 bit python using the 64 bit driver?
Kind regards,
Colin

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh »

Hi Colin,

Referring to this documentation page, you may wish to try the following when passing the array to the function call:

Code: Select all

temp.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
rather than

Code: Select all

temp.ctypes.data
The error is possibly due to how ctypes is trying to interpret a 64-bit pointer.

I hope this helps.

Please note that Pico Technology is not responsible for the content of external sites.
Hitesh

Software Dev. Engineer

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

Re: USB TC-08 in python

Post by colinb »

Dear Hitesh,
This helps so much, the suggestion you gave works well and the problem is solved.
The code which works is given below for reference

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)
mydll.usb_tc08_get_single(device, temp.ctypes.data_as(ctypes.POINTER(ctypes.c_float)), overflow_flags.ctypes.data_as(ctypes.POINTER(ctypes.c_float)), 0)
mydll.usb_tc08_close_unit(device)
print(temp[0],temp[1],temp[2])

Thank you again for your help.
Best regards,
Colin

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh »

Hi Colin,

Good to hear it worked :D

The solution came from a colleague who is experienced with Python.

Regards,
Hitesh

Software Dev. Engineer

VincentIZ
Newbie
Posts: 0
Joined: Mon Feb 26, 2018 6:01 pm

Re: USB TC-08 in python

Post by VincentIZ »

Hi,
I am using Python 3.6 on WIN10 64 bit. I also had problems with passing the arguments to the get_single dll function.
This is how I got things work without using numpy :
# usage of ctypes
from ctypes import *
# in def __init__ declaration of _temp and _overflow_flags which are used as callback args
self._temp=(c_float *9)()
self._overflow_flags=c_int16()
# usage in get single, function will return a list with the temperature of channel 1 .. 8
# self._temp and self._overflow_flags are passed by reference
def get_single(self):
self._dll.usb_tc08_get_single(self._handle, byref(self._temp), byref(self._overflow_flags), self._units.value)
return [self._temp[1],self._temp[2],self._temp[3],self._temp[4],self._temp[5],self._temp[6],self._temp[7],self._temp[8]]

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: USB TC-08 in python

Post by Hitesh »

Hi VincentIZ,

Thank you for this.

Are you checking the cold junction compensation value from index 0 in the array as well?

We are in the process of reviewing the content of our Python example repository on GitHub and hope to provide bindings for data logger support. You can also open a Pull request if you wish to contribute code - we can then review this and accept the change if it meets our guidelines.

Regards,
Hitesh

Software Dev. Engineer

Justin.Mai
Newbie
Posts: 0
Joined: Fri Aug 23, 2019 3:40 pm

Re: USB TC-08 in python

Post by Justin.Mai »

I'm looking to measure 16 channels (two TC-08's) every 100 milliseconds, but the only code I have found in the following places show how to make a single measurement with no option for measuring all at once; measuring single in a loop is not acceptable in my case:

- this forum thread's user-uploaded code
- the piclog github repository for python code (not updated anymore i think?)
- the piclog github repo for picosdk python wrapper

Does anyone have example code for measuring more than 8 channels at a time?

The code I've tried from this forum thread doesn't loop quick enough for my purposes. I would love to have all measurements within 100 milliseconds of each other but looping a single measurement doesn't cut it sadly.

Thank you!
Justin

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

Re: USB TC-08 in python

Post by Martyn »

You are aware that the TC08 only has one high resolution ADC chip and that the inputs are multiplexed. It takes 100msecs to do a single conversion, and therefore 900msecs to perform a conversion for each channel and the Cold Junction.
Martyn
Technical Support Manager

Justin.Mai
Newbie
Posts: 0
Joined: Fri Aug 23, 2019 3:40 pm

Re: USB TC-08 in python

Post by Justin.Mai »

Thank you, Martyn; I was not aware of this.

neoflash
Newbie
Posts: 0
Joined: Tue Nov 09, 2021 1:04 am

Re: USB TC-08 in python

Post by neoflash »

For Mac os python programming, how to set the resolution of the picolog?

In Mac, this command doesn't seem to work. It feels like Mac driver doesn't support full functions?

Code: Select all

tc08.usb_tc08_set_resolution(device, 15)
AttributeError: dlsym(0x7ff66dc16640, usb_tc08_set_resolution): symbol not found

Tomeref4
Newbie
Posts: 0
Joined: Tue Aug 16, 2022 8:59 am

Re: USB TC-08 in python

Post by Tomeref4 »

Hi, Im struggling with an error i get in get_single


File "C:\GitRep\pico_logger\tc08usb.py", line 105, in get_single
return (self._dll.usb_tc08_get_single(self._handle, self._temp.ctypes.data, self._overflow_flags.ctypes.data, self._units.value))
ctypes.ArgumentError: argument 2: : int too long to convert

Can someone help me with that?
running python 3.9 64bit

Post Reply