How to read different thermocouples from 1048

Supporting 2.7 and 3.2+
Post Reply
brianz
Fresh meat
Posts: 3
Joined: Mon Apr 13, 2015 12:06 pm
Contact:

How to read different thermocouples from 1048

Post by brianz »

I'm trying to update my code from Phidgets21 to Phidget22 in Python and the APIs seem to have changed quite drastically. It's really confusing how to get different temperatures when the 4-input 1048 Temperature Sensor.

Previous, the temperature changed callback had a signature like this:

Code: Select all

def TemperatureChangeHandler(event):
    print(event.index, event.temperature)
...where `index` was the thermocouple number, from 0-3.

The callback now get's two variables, the event and temperature. However, "index" is now gone from the event object. How are we supposed to read all four temperature?

Code: Select all

def TemperatureChangeHandler(event, temperature):
    # no more event.index
I've looked through the docs and they are unhelpful...these details are completely missing from them, sadly. There is zero information on how to handle multiple TC inputs.

Help appreciated.
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: How to read different thermocouples from 1048

Post by mparadis »

In Phidget22, each channel needs to have it's handler function set. You can set them to the same function, or different functions. It might look like this:

Code: Select all

 ch0 = TemperatureSensor()
 ch1 = TemperatureSensor()
 ch2 = TemperatureSensor()
 ch3 = TemperatureSensor()
 
 ch0.setChannel(0)
 ch1.setChannel(1)
 ch2.setChannel(2)
 ch3.setChannel(3)
 
 ch0.setOnTemperatureChangeHandler(TemperatureChangeHandler)
 ch1.setOnTemperatureChangeHandler(TemperatureChangeHandler)
 ch2.setOnTemperatureChangeHandler(TemperatureChangeHandler)
 ch3.setOnTemperatureChangeHandler(TemperatureChangeHandler)
 
 ch0.openWaitForAttachment(5000)
 ch1.openWaitForAttachment(5000)
 ch2.openWaitForAttachment(5000)
 ch3.openWaitForAttachment(5000)
 
If you use the same event handler for all four channels, you can tell which channel triggered it by using the event argument:

Code: Select all


def TemperatureChangeHandler(e, temperature):
    print("Channel: %i  |  Temperature: %f" % (e.getChannel(), temperature))

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests