Page 1 of 1

latency when trying to read temperature

Posted: Sat Jan 01, 2022 8:21 am
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 !

Re: latency when trying to read temperature

Posted: Tue Jan 04, 2022 12:52 pm
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()

Re: latency when trying to read temperature

Posted: Sat Jan 08, 2022 7:50 am
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.

Re: latency when trying to read temperature

Posted: Mon Jan 10, 2022 2:20 pm
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?

Re: latency when trying to read temperature

Posted: Sat Jan 15, 2022 7:48 am
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.