Test and Measurement Forum

USB TC-08 in python

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

Re: USB TC-08 in python

Postby colinb » Wed Jan 03, 2018 12:11 pm

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

Re: USB TC-08 in python

Postby Hitesh » Wed Jan 03, 2018 1:36 pm

Hi Colin,

Happy New Year to you too :)

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

Regards,
Hitesh

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

Re: USB TC-08 in python

Postby colinb » Tue Jan 16, 2018 8:34 am

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

Re: USB TC-08 in python

Postby Hitesh » Mon Jan 22, 2018 11:44 am

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

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

Re: USB TC-08 in python

Postby colinb » Wed Jan 24, 2018 9:17 am

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

Re: USB TC-08 in python

Postby Hitesh » Thu Jan 25, 2018 9:29 am

Hi Colin,

Good to hear it worked :D

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

Regards,
Hitesh

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

Re: USB TC-08 in python

Postby VincentIZ » Mon Feb 26, 2018 7:15 pm

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]]
VincentIZ
Newbie
 
Posts: 0
Joined: Mon Feb 26, 2018 6:01 pm

Re: USB TC-08 in python

Postby Hitesh » Wed Feb 28, 2018 10:25 am

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

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

Previous

Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 2 guests