latency when trying to read temperature

Supporting 2.7 and 3.2+
Post Reply
garef
Fresh meat
Posts: 3
Joined: Sat Jan 01, 2022 8:12 am
Contact:

latency when trying to read temperature

Post by garef »

I am trying to use the PhidgetTemperatureSensor 4-Input, which directly talks to my computer with USB. I manage to read the temperatures but have a strong latency (5-6s) from the time the temperature changes to the time the computer reads this temperature change. This means that if I put my fingers on the termocouple, I have to wait 5 seconds for the computer to tell me the termocouple has become hotter.
This is the code I use to get the data:

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.TemperatureSensor import *
from time import *
y1=[]
y2=[]
y3=[]
def init_board():

    ch = TemperatureSensor()
    ch.setChannel(4)
    ch.openWaitForAttachment(1000)
    ch2 = TemperatureSensor()
    ch2.setChannel(0)
    ch2.openWaitForAttachment(1000)
    ch3 = TemperatureSensor()
    ch3.setChannel(1)
    ch3.openWaitForAttachment(1000)
    return ch, ch2, ch3
    
(ch, ch2, ch3)=init_board()
try :
    while True :
    
        temperature1 = ch.getTemperature()
        temperature2= ch2.getTemperature()
        temperature3= ch3.getTemperature()
        print(temperature1, temperature2, temperature3)
        sleep(1)
        
except(KeyboardInterrupt):
    ch.close()
    ch2.close()
    ch3.close()

I think this is a problem with the buffer of my phidget. In fact if I open and close the phidget each time I want to get a temperature value, I get no latency.
Thanks in advance for the help !
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: latency when trying to read temperature

Post by mparadis »

Do you get similar latency when you use the OnTemperatureChange event instead of polling in a loop?

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.TemperatureSensor import *
import time

def onTemperatureChange(self, temperature):
	print("Temperature: " + str(temperature))

def main():
	temperatureSensor0 = TemperatureSensor()

	temperatureSensor0.setOnTemperatureChangeHandler(onTemperatureChange)

	temperatureSensor0.openWaitForAttachment(5000)

	try:
		input("Press Enter to Stop\n")
	except (Exception, KeyboardInterrupt):
		pass

	temperatureSensor0.close()

main()
garef
Fresh meat
Posts: 3
Joined: Sat Jan 01, 2022 8:12 am
Contact:

Re: latency when trying to read temperature

Post by garef »

I tried using your code but the latency is still there. When I run you code without changing anything It shows me the temerature only once and then when I tap enter itshows a second one and stops.

Code: Select all

Temperature: 25.5247
Press Enter to Stop

Temperature: 25.5091
When I comment out the temperatureSensor0.close() it gives me the values every second but I have my 10 second latency.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: latency when trying to read temperature

Post by mparadis »

This is very strange behaviour- it should be giving you readings every second regardless of whether Close is called or not.

Do you see the same latency when using the Phidget Control Panel?
Do you have another computer you can try to run this script on?
garef
Fresh meat
Posts: 3
Joined: Sat Jan 01, 2022 8:12 am
Contact:

Re: latency when trying to read temperature

Post by garef »

I have tried both on a laptop and on my regular computer. Both have the same behavior.
I don't see any latency when using the Phidget control panel.
I will try to access my phidget with the C library today. Maybe it is just a problem with the python library.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests