Pico USB TC-08 Python Handle problem [SOLVED]

Having problems ? let us know the details here
Post Reply
YohannF
User
User
Posts: 2
Joined: Wed Feb 08, 2023 4:30 pm

Pico USB TC-08 Python Handle problem [SOLVED]

Post by YohannF »

Hello everyone,
I am experiencing problem with reading tc08 temperatures from a Python environment.

My environment:
Windows 10, 64 bits
Python 64 with Anaconda. Python v3.9.7
I've installed picolog-setup-6.2.7
I've installed PicoSDK_64_10.7.23.255
I've installed picosdk1.1 wrapper (pip install picosdk)

When launching the Pico software, I can read the temperature on ports where thermocouplers are attached (2 and 3).


Python code:

Code: Select all

import ctypes
import numpy as np
import time
from usbtc08 import usbtc08 as tc08
from functions import assert_pico2000_ok

# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}

# open unit
status["open_unit"] = tc08.usb_tc08_open_unit()
Problem 1:
If I do not have the Pico software one, when I reach the command ‘tc08.usb_tc08_open_unit()’, Python waits for 2 seconds and then kernel crashes (Kernel restart).
Kernel doesn’t restart if Pico software is running in the background.
Is it normal? Should Pico software be running in the background?

Problem 2:
If I have Pico software running in the background, the return of command ‘tc08.usb_tc08_open_unit()’ is 0.
If I have Pico software running in the background, the return of command ‘tc08.usb_tc08_open_unit_async()’ is 1.
So it seems like with open_unit_async, I do not have an error.

I then proceed to channel setting:

Code: Select all

import ctypes
import numpy as np
import time
from usbtc08 import usbtc08 as tc08
from functions import assert_pico2000_ok

# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}

# open unit
status["open_unit"] = tc08.usb_tc08_open_unit_async()
chandle = ctypes.c_int16(status["open_unit"])


# set up channel
Channel = ctypes.c_int16(2)
typeK = ctypes.c_int8(75)
status["set_channel"] = tc08.usb_tc08_set_channel(chandle, Channel, typeK) # It returns 0 => error
# Last error
tc08.usb_tc08_get_last_error(chandle) # It returns -1 => Invalid handle

So it it only working partially since the open_unit_async doesn’t crashes? Any suggestion anyone?
Seems like drivers are installed but did I miss other drivers to install?
Do I need to add drivers location to python environment? (seems like Python can access the functions)
The ID of our data logger is IJY36/123. I tried to put that as the handle but nothing worked.


Any suggestion are welcome.

I’ve tried the Testing code for the Pipy wrapper and I got the following error message:

Code: Select all

from picosdk.discover import find_all_units
scopes = find_all_units()
for scope in scopes:
    print(scope.info)
    scope.close()

Ps6000a.lib object has no attribute ‘DEFAULT_RESOLUTION’ but I think this is a different problem



Regards,
Yohann
Last edited by YohannF on Mon Feb 27, 2023 12:27 pm, edited 1 time in total.

Norkin
Newbie
Posts: 1
Joined: Wed Feb 15, 2023 6:29 am

Re: Pico USB TC-08 Python Handle problem

Post by Norkin »

Hello, :)
I have the exact same problem.

My environment:
Windows 10, 64 bits
Python 64 with Anaconda. Python v3.9
-picolog-setup-6.2.7
-PicoSDK_64_10.7.23.255
-picosdk1.1 wrapper (pip install picosdk).


When I executing the "tc08StreamingModeExample.py" program ( picosdk-python-wrappers - GitHub), it seems that there is a problem with the "#open unit" part.
I would like to know if anyone has found a solution to this problem.

Code: Select all

 #
# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms.
#
# TC-08 STREAMING MODE EXAMPLE


import ctypes
import numpy as np
import time
from picosdk.usbtc08 import usbtc08 as tc08
from picosdk.functions import assert_pico2000_ok

# Create chandle and status ready for use
chandle = ctypes.c_int16()
status = {}
print(status)

# open unit
status["open_unit"] = tc08.usb_tc08_open_unit()
assert_pico2000_ok(status["open_unit"])
chandle = status["open_unit"]
print(status)


# set mains rejection to 50 Hz
status["set_mains"] = tc08.usb_tc08_set_mains(chandle,0)
assert_pico2000_ok(status["set_mains"])
print(status)

# set up channel
# therocouples types and int8 equivalent
# B=66 , E=69 , J=74 , K=75 , N=78 , R=82 , S=83 , T=84 , ' '=32 , X=88 
typeK = ctypes.c_int8(75)
status["set_channel"] = tc08.usb_tc08_set_channel(chandle, 1, typeK)
assert_pico2000_ok(status["set_channel"])

# get minimum sampling interval in ms
status["get_minimum_interval_ms"] = tc08.usb_tc08_get_minimum_interval_ms(chandle)
assert_pico2000_ok(status["get_minimum_interval_ms"])

# set tc-08 running
status["run"] = tc08.usb_tc08_run(chandle, status["get_minimum_interval_ms"])
assert_pico2000_ok(status["run"])

time.sleep(2)

# collect data 
temp_buffer = (ctypes.c_float * 2 * 15)()
times_ms_buffer = (ctypes.c_int32 * 15)()
overflow = ctypes.c_int16()
status["get_temp"] = tc08.usb_tc08_get_temp(chandle, ctypes.byref(temp_buffer), ctypes.byref(times_ms_buffer), 15, ctypes.byref(overflow), 1, 0, 1)
assert_pico2000_ok(status["get_temp"])

# stop unit
status["stop"] = tc08.usb_tc08_stop(chandle)
assert_pico2000_ok(status["stop"])

# close unit
status["close_unit"] = tc08.usb_tc08_close_unit(chandle)
assert_pico2000_ok(status["close_unit"])

# display status returns
print(status)

 

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

Re: Pico USB TC-08 Python Handle problem

Post by Martyn »

There is an issue with the USB TC08 dll included with the current SDK that causes a problem with the Open Unit call, we are working on a fix for this.

Until we have released a new version please download and install the previous version from here https://www.picotech.com/download/softw ... 22.241.exe
Martyn
Technical Support Manager

YohannF
User
User
Posts: 2
Joined: Wed Feb 08, 2023 4:30 pm

Re: Pico USB TC-08 Python Handle problem

Post by YohannF »

Thank you Martyn for your help.
Using an older version of the SDK solved my issue.

To whoever it can help, below is the code that works for me.

Code: Select all

from picosdk.usbtc08 import usbtc08 as tc08
#import ctypes
import numpy as np

# open unit
status = {}
status["open_unit"] = tc08.usb_tc08_open_unit()
device = status["open_unit"]
print(status)


# set mains rejection to 50 Hz
status["set_mains"] =tc08.usb_tc08_set_mains(device,50)
print(status)

# set up channel
# therocouples types and int8 equivalent
# B=66 , E=69 , J=74 , K=75 , N=78 , R=82 , S=83 , T=84 , ' '=32 , X=88
tc_chan_num=8 
tc08.usb_tc08_set_channel(device, 0, 0 )
tc_type=ord('K')
status["set_channel"] = tc08.usb_tc08_set_channel(device,tc_chan_num,tc_type)
print(status)

# get minimum sampling interval in ms
status["get_minimum_interval_ms"] = tc08.usb_tc08_get_minimum_interval_ms(device)
print(status)

# collect data 
temp = np.zeros( (9,), dtype=np.float32) # [cold junction, det1, det2, det3, det4, det5, det6, det7, det8]
overflow_flags = np.zeros( (1,), dtype=np.int16)
status["get_single"] = tc08.usb_tc08_get_single( device, temp.ctypes.data, overflow_flags.ctypes.data, 0)
print(temp)

# stop and close unit
status["stop"] = tc08.usb_tc08_stop(device)
status["close_unit"] = tc08.usb_tc08_close_unit(device)
print(status)

frfaraldo
Newbie
Posts: 1
Joined: Sat Feb 24, 2024 3:40 pm

Re: Pico USB TC-08 Python Handle problem [SOLVED]

Post by frfaraldo »

Hi YohannF,
I still have issues with the TC-08 communication and the python code. Even using your code that you just posted provides strange outputs. The status printed returns '0' for all of them + the print(temp) also returns an array of 0.

Did you face this issue at some point ?

Thanks

Post Reply