Setting Data Interval

C, C++, and Visual C++
Post Reply
eeot
Fresh meat
Posts: 2
Joined: Wed Jan 27, 2021 12:27 pm
Contact:

Setting Data Interval

Post by eeot »

I need to change the data interval, but this code does not change the interval and it is still at the default interval. I need to save the voltage ratio for further calculations. How do I change the interval?

Code: Select all

#include <phidget22.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>

//Declare any event handlers here. These will be called every time the associated event occurs.

static void CCONV onVoltageRatioChange(PhidgetVoltageRatioInputHandle ch, void * ctx, double voltageRatio) {
	int channel;

	//Getting the channel number to distinguish between Phidgets
	Phidget_getChannel((PhidgetHandle)ch, &channel);
	//printf("VoltageRatio [%d]: %lf\n", channel, voltageRatio);
}

static void CCONV onAttach(PhidgetHandle ch, void * ctx) {
	int channel;

	//Getting the channel number to distinguish between Phidgets
	Phidget_getChannel(ch, &channel);
	printf("Attach [%d]!\n", channel);
}

static void CCONV onDetach(PhidgetHandle ch, void * ctx) {
	int channel;

	//Getting the channel number to distinguish between Phidgets
	Phidget_getChannel(ch, &channel);
	printf("Detach [%d]!", channel);
}


int main() {
	//Declare your Phidget channels and other variables
	PhidgetVoltageRatioInputHandle voltageRatioInput0;
	PhidgetVoltageRatioInputHandle voltageRatioInput1;
	PhidgetVoltageRatioInputHandle voltageRatioInput2;
	PhidgetVoltageRatioInputHandle voltageRatioInput3;

	//Create your Phidget channels
	PhidgetVoltageRatioInput_create(&voltageRatioInput0);
	PhidgetVoltageRatioInput_create(&voltageRatioInput1);
	PhidgetVoltageRatioInput_create(&voltageRatioInput2);
	PhidgetVoltageRatioInput_create(&voltageRatioInput3);

	//Set Data Interval
	PhidgetVoltageRatioInput_setDataInterval(voltageRatioInput0, 8);
	PhidgetVoltageRatioInput_setDataInterval(voltageRatioInput1, 8);
	PhidgetVoltageRatioInput_setDataInterval(voltageRatioInput2, 8);
	PhidgetVoltageRatioInput_setDataInterval(voltageRatioInput3, 8);

	//Set addressing parameters to specify which channel to open (if any)
	Phidget_setChannel((PhidgetHandle)voltageRatioInput0, 0);
	Phidget_setChannel((PhidgetHandle)voltageRatioInput1, 1);
	Phidget_setChannel((PhidgetHandle)voltageRatioInput2, 2);
	Phidget_setChannel((PhidgetHandle)voltageRatioInput3, 3);

	//Assign any event handlers you need before calling open so that no events are missed.
	PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler(voltageRatioInput0, onVoltageRatioChange, NULL);
	Phidget_setOnAttachHandler((PhidgetHandle)voltageRatioInput0, onAttach, NULL);
	Phidget_setOnDetachHandler((PhidgetHandle)voltageRatioInput0, onDetach, NULL);
	PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler(voltageRatioInput1, onVoltageRatioChange, NULL);
	Phidget_setOnAttachHandler((PhidgetHandle)voltageRatioInput1, onAttach, NULL);
	Phidget_setOnDetachHandler((PhidgetHandle)voltageRatioInput1, onDetach, NULL);
	PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler(voltageRatioInput2, onVoltageRatioChange, NULL);
	Phidget_setOnAttachHandler((PhidgetHandle)voltageRatioInput2, onAttach, NULL);
	Phidget_setOnDetachHandler((PhidgetHandle)voltageRatioInput2, onDetach, NULL);
	PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler(voltageRatioInput3, onVoltageRatioChange, NULL);
	Phidget_setOnAttachHandler((PhidgetHandle)voltageRatioInput3, onAttach, NULL);
	Phidget_setOnDetachHandler((PhidgetHandle)voltageRatioInput3, onDetach, NULL);

	//Open your Phidgets and wait for attachment
	Phidget_openWaitForAttachment((PhidgetHandle)voltageRatioInput0, 5000);
	Phidget_openWaitForAttachment((PhidgetHandle)voltageRatioInput1, 5000);
	Phidget_openWaitForAttachment((PhidgetHandle)voltageRatioInput2, 5000);
	Phidget_openWaitForAttachment((PhidgetHandle)voltageRatioInput3, 5000);

	double voltageRatio0;
	double voltageRatio1;
	double voltageRatio2;
	double voltageRatio3;
	while(!_kbhit()) {
	PhidgetVoltageRatioInput_getVoltageRatio(voltageRatioInput0, &voltageRatio0);
		PhidgetVoltageRatioInput_getVoltageRatio(voltageRatioInput1, &voltageRatio1);
		PhidgetVoltageRatioInput_getVoltageRatio(voltageRatioInput2, &voltageRatio2);
		PhidgetVoltageRatioInput_getVoltageRatio(voltageRatioInput3, &voltageRatio3);}
fraser
Engineering
Posts: 138
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: Setting Data Interval

Post by fraser »

You will need to set the interval after it is opened, currently you're setting it prior to calling open. A good place to set it is in the attach handler.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest