I'm trying to read the temperature in the 5 channels (0 to 4) of an 1048 device. Below the code:
Code: Select all
int serial = atoi(option1);
int timeout = atoi(option2);
#define PHIDGET_1040_CHANNELS 5
PhidgetTemperatureSensorHandle channels[PHIDGET_1040_CHANNELS];
PhidgetReturnCode prc = EPHIDGET_OK;
static double temperature[PHIDGET_1040_CHANNELS];
for(int i = 0; i < PHIDGET_1040_CHANNELS && prc == EPHIDGET_OK; i++) {
prc = PhidgetTemperatureSensor_create(&channels[i]);
if (prc != EPHIDGET_OK)
continue;
if(serial > 0) {
prc = Phidget_setDeviceSerialNumber((PhidgetHandle)channels[i], 0);
if (prc != EPHIDGET_OK)
continue;
}
prc = Phidget_setHubPort((PhidgetHandle)channels[i], 0);
if (prc != EPHIDGET_OK)
continue;
prc = Phidget_setChannel((PhidgetHandle)channels[i], i);
if (prc != EPHIDGET_OK)
continue;
prc = Phidget_openWaitForAttachment((PhidgetHandle)channels[i], timeout);
if (prc != EPHIDGET_OK)
continue;
}
for(int i = 0; i < PHIDGET_1040_CHANNELS; i++) {
prc = PhidgetTemperatureSensor_getTemperature(channels[i], &temperature[i]);
if (prc != EPHIDGET_OK) <<<<< Fail here
temperature[i] = -1;
}
for(int i = 0; i < PHIDGET_1040_CHANNELS; i++) {
prc = Phidget_close((PhidgetHandle)channels[i]);
if (prc != EPHIDGET_OK)
continue;
prc = PhidgetTemperatureSensor_delete(&channels[i]);
if (prc != EPHIDGET_OK)
continue;
}
if(prc != EPHIDGET_OK)
return -1;
Code: Select all
prc = PhidgetTemperatureSensor_getTemperature(channels[i], &temperature[i]);
The channel 4 results EPHIDGET_OK and the temperature seem ok.
I appreciated any suggestion,
Thanks
PS: the Phidget control panel is working as expected.