Page 1 of 1

counting the number of channels with Phidgets22

Posted: Wed Jan 01, 2025 2:26 pm
by Dr.John
I'm trying to create a temperature logging system with the Phidgets TMP1101-1 in Ubuntu Linux. However, the hardware configuration will be dynamic, that is, there may be 1 or more TMP1101-1 units attached to the hub at a run time, and this number isn't known at compile time. My question is: how do I discover the number of channels that are available at run time?

I tried using the manager (using the HellowWorld example and some derivatives of it), but it reports 9 temperature channels, each with a different handle, when there are 4. So, it doesn't work.

Thanks for your help!

Re: counting the number of channels with Phidgets22

Posted: Thu Jan 02, 2025 9:28 am
by mparadis
When you run the HelloWorld manager example with a TMP1101 connected, you probably get output like this:

Code: Select all

>python HelloWorld.py
Opening....
Phidget Simple Playground (plug and unplug devices)
Press Enter to end anytime...
Hello to Device 6-Port USB VINT Hub Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808

Closing...
The reason the TMP1101 has nine channels is because it has five temperature channels (four thermocouples and one ambient sensor on the board for temperature correction) and four Voltage Input channels for reading the probes' raw voltage. If you want to be able to see what kind of channels these are, you can add the ChannelClass and ChannelSubClass properties to the attach handler:

Code: Select all

def AttachHandler(self, channel):

    attachedDevice = channel
    serialNumber = attachedDevice.getDeviceSerialNumber()
    deviceName = attachedDevice.getDeviceName()
    channelClass = attachedDevice.getChannelClass()
    subClass = attachedDevice.getChannelSubclass()
    print("Hello to Device " + str(deviceName) + ", Serial Number: " + str(serialNumber) + ", Class: " + str(ChannelClass.getName(channelClass)) + ", Subclass: " + str(ChannelSubclass.getName(subClass)))
Then the output will look like this:

Code: Select all

>python HelloWorld.py
Opening....
Phidget Simple Playground (plug and unplug devices)
Press Enter to end anytime...
Hello to Device 6-Port USB VINT Hub Phidget, Serial Number: 673808, Class: PHIDCHCLASS_HUB, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_TEMPERATURESENSOR, Subclass: PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_TEMPERATURESENSOR, Subclass: PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_TEMPERATURESENSOR, Subclass: PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_TEMPERATURESENSOR, Subclass: PHIDCHSUBCLASS_TEMPERATURESENSOR_THERMOCOUPLE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_TEMPERATURESENSOR, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device 4x Thermocouple Phidget, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALINPUT, Subclass: PHIDCHSUBCLASS_NONE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Digital Output Mode, Serial Number: 673808, Class: PHIDCHCLASS_DIGITALOUTPUT, Subclass: PHIDCHSUBCLASS_DIGITALOUTPUT_DUTY_CYCLE
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Input Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGEINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGEINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT
Hello to Device Hub Port - Voltage Ratio Mode, Serial Number: 673808, Class: PHIDCHCLASS_VOLTAGERATIOINPUT, Subclass: PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT

Closing...

Re: counting the number of channels with Phidgets22

Posted: Thu Jan 02, 2025 10:06 am
by Dr.John
Got it. Thanks! Didn't know about the on-board ambient temperature sensor, so that helps to explain things.

One more question: In the case of multiple TMP1101-1 temperature sensing devices, which may be attached or not depending upon the circumstances, is there a way to enforce the mapping between thermocouples and the channels as mapped by the attach process?

Re: counting the number of channels with Phidgets22

Posted: Thu Jan 02, 2025 1:22 pm
by mparadis
You can use the device serial number of the hub, and hub port number (getHubPort()) to identify the four channels of each TMP1101, and always grab channels 0 through 3 (getChannel()), since the ambient sensor is always channel 4. Combined with the channel class, you can know where each thermocouple channel is connecting from.