1048 fail getTemperature

C, C++, and Visual C++
Post Reply
hulaomr
Phidgetsian
Posts: 7
Joined: Mon Oct 15, 2018 8:20 am
Contact:

1048 fail getTemperature

Post by hulaomr »

Hello,

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;
The results is good except in the line:

Code: Select all

prc = PhidgetTemperatureSensor_getTemperature(channels[i], &temperature[i]);
The channels 0 to 3 return EPHIDGET_UNKNOWNVAL (Unknown or Invalid Value)
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.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: 1048 fail getTemperature

Post by mparadis »

Sometimes you can get an unknown value error when you try to poll data from a Phidget immediately after opening the channel. Try putting a sleep after the open loop and getTemperature loop to see if that fixes it. You could also try switching to an event-driven system using the OnTemperatureChange event.
hulaomr
Phidgetsian
Posts: 7
Joined: Mon Oct 15, 2018 8:20 am
Contact:

Re: 1048 fail getTemperature

Post by hulaomr »

Thanks for your reply and suggestion. That fix the issue.

In my system the needed time is ~27ms to get the first correct value after open.

I will update the loop as below:

Code: Select all

    for(int i = 0; i < PHIDGET_1040_CHANNELS;) {
        prc = PhidgetTemperatureSensor_getTemperature(channels[i], &temperature[i]);
        if (prc != EPHIDGET_OK)
            sleep_ms(27);
        else
            i++;
    }
Probably will add a timeout condition as well.

If not event-driven is used, please, may I know if the previous code will have other issues?

Thanks
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: 1048 fail getTemperature

Post by mparadis »

I don't think you'll have any issues with this solution, although depending on how you're using this data, using events may be cleaner. For example, with events you can guarantee data comes in on regular intervals (e.g. every 8ms), while with this solution, one thermocouple can temporarily block the reading of every other one if getTemperature returns an error. If you're planning on graphing this data vs. time, events will result in easier to use data.

Also, you don't need to set HubPort when using the 1048; HubPort is only used to select which port you're using with a VINT Hub (HUB0000 or SBC3003).
hulaomr
Phidgetsian
Posts: 7
Joined: Mon Oct 15, 2018 8:20 am
Contact:

Re: 1048 fail getTemperature

Post by hulaomr »

Thanks mparadis.
I understand your concerns and thanks for pointing out those.
Currently, I'm recording the temperature with a sampling time of 1 sec or more, which is not important the accuracy in this case.
I would like to take this conversation and ask you about a situation, which happens sometimes and I discard because doesn't make sense in the test environment.
The situation is that some samples value seems incorrect, when I'm acquiring some variables as voltage, current or in this case, temperature.
Below a picture of the temperature with a sampling frequency variable (the minimum period is around 5 sec).
Image
https://ibb.co/kRGdkf
Usually, I discard the unknown values as measurement errors.
My questions is, assuming the probes are OK, and nothing is moving around during the test, which could be the cause of these values? And of course, which approach you consider I could apply to avoid this?
Thanks for your feedback,
fraser
Engineering
Posts: 324
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: 1048 fail getTemperature

Post by fraser »

Are you using a DataInterval of 1s-5s or are you opening, polling and closing them every 1s-5s ?
hulaomr
Phidgetsian
Posts: 7
Joined: Mon Oct 15, 2018 8:20 am
Contact:

Re: 1048 fail getTemperature

Post by hulaomr »

opening, polling and closing them every 1s-5s
hulaomr
Phidgetsian
Posts: 7
Joined: Mon Oct 15, 2018 8:20 am
Contact:

Re: 1048 fail getTemperature

Post by hulaomr »

Hi Fraser, any thought or suggestion regarding this situation? Thanks
fraser
Engineering
Posts: 324
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: 1048 fail getTemperature

Post by fraser »

I ran some code over the weekend but did not see any deviation from expected temperatures. I was doing the open, poll, close method as you mentioned. Which probe are you using?
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests