Temperature Sensor 4 Channel output loop

C, C++, and Visual C++
Post Reply
JEarley12
Fresh meat
Posts: 2
Joined: Tue Jul 30, 2019 8:37 am
Contact:

Temperature Sensor 4 Channel output loop

Post by JEarley12 »

Hey everyone,
Currently attempting to code on codeblocks a program that allows all four 4 channels to be displayed. I was able to create a loop that allows the program to loop four times but you have to enter the channel number every time. I was unable to get the program to switch from channel to channel automatically. I'm a newbie to Phidget so any help is appreciated. I attached my current attempt on it using the example code.
Attachments
PhidgetHelperFunctions.c
(6.24 KiB) Downloaded 2742 times
TemperatureSensor_Example.c
(9.85 KiB) Downloaded 2720 times
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Temperature Sensor 4 Channel output loop

Post by mparadis »

Instead of looping through the example four times, you should create four different PhidgetTemperatureSensorHandle variables, one for each channel. Instead of using the AskForDeviceParameters function, you can hard-code the values for setDeviceSerialNumber and setChannel. If you want to see an example of how to do this cleanly, check the "Similar Phidgets" section on this page.
JEarley12
Fresh meat
Posts: 2
Joined: Tue Jul 30, 2019 8:37 am
Contact:

Re: Temperature Sensor 4 Channel output loop

Post by JEarley12 »

Thank you for the help, your suggestion worked. The only issues is the output for the channels are staggered. I attached the output and my new code. I'm trying to create a table format.
Attachments
Current output.PNG
PhidgetHelperFunctions.c
(3.59 KiB) Downloaded 2701 times
TemperatureSensor_Example.c
(10.63 KiB) Downloaded 2612 times
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Temperature Sensor 4 Channel output loop

Post by mparadis »

This is because each event happens at a slightly different time and you're printing a new line each time the event comes in.
There are a couple ways around this:

- You could have all four channels share the same change handler. You could store the most recent value for each channel and then only print a line once you have a new value for all four channels. In order to do this method you'll need to be able to differentiate which channel called the handler, which you can find in the "Distinguishing Events" section of the page I linked earlier.

- You could have four global variables which your four change handlers constantly update with the latest temperature value for each channel. Then, in your main function, you can have a loop that prints the most recent value for each channel all in one line and then waits a certain amount of time each iteration.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests