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 am trying to change the data interval in my code, but when I run my code, it does not change and keeps the default sample rate. I need to save the voltage ratio for each channel to use for other calculations. How do I change the data 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);}
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Setting Data Interval

Post by Patrick »

You need to set the data interval after attach - a good place to do this is in the attach handler.

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests