Example #1
0
File: Ati.cpp Project: cyhd/HaCoE
void Ati::setVoltage(void)
{
	int i = 0;
	long errorcode;
	long idnum=-1;
	long demo=0;
	long stateIO=0;
	long numCh=4;
	long channel_1[4]={0,1,2,3};
	long channel_2[2]={4,5};
	long gains_1[4]={0,0,0,0};
	long gains_2[2]={0,0};
	long ov;
    float voltages_1[4];
	float voltages_2[4];

	for (i=0;i<4;i++)
	{
		voltages_1[i] = 0;
		voltages_2[i] = 0;
	}

	errorcode = AISample(&idnum,demo,&stateIO,0,1,4,channel_1,gains_1,0,&ov,voltages_1);
/*
	if(errorcode != 0)
	{
		cout << "Error Code 1 = " << errorcode << "\n";
		exit(1);		
	}
*/
    errorcode = AISample(&idnum,demo,&stateIO,0,1,2,channel_2,gains_2,0,&ov,voltages_2);
/*    
	if(errorcode != 0)
	{
		cout << "Error Code 2 = " << errorcode << "\n";
		exit(1);		
	}
*/
	voltages[0] = voltages_1[0];
	voltages[1] = voltages_1[1];
	voltages[2] = voltages_1[2];
	voltages[3] = voltages_1[3];
	voltages[4] = voltages_2[0];
	voltages[5] = voltages_2[1];
}
Example #2
0
int main (int argc, char *argv[])
{
	float version = 0.0;
	long errorcode = 0;

	long idnum = -1;  //Using first found U12
	long demo = 0;  //Normal operations
	long stateIO = 0;  //Output states for IO0-IO3

	//AOUpdate specific paramters
	long trisD = 0;  //Directions for D0-D15
	long trisIO = 0;  //Directions for IO0-IO3
	long stateD = 0;  //Output states for D0-D15
	long updateDigital = 0;  //Tris and state values are only being read
	long resetCounter = 0;  //Not resetting counter
	unsigned long count = 0;  //Returned current count value
	float analogOut0 = 0.8;  //Voltage for AO0
	float analogOut1 = 3.2;  //Voltage for AO1

	//AISample specific parameters
	long updateIO = 0;  //State values are only being read
	long ledOn = 0;  //Turning LED on
	long numChannels = 2;  //Reading 2 channels
	long channels[2] = {2, 3};  //Reading AI2 and AI3
	long gains[2] = {0, 0};  //Gains.  Does not matter in this case since we are
							 //performing single ended readings.
	long disableCal = 0;  //Will apply calibration constants
	long overVoltage = 0;  //Returns if overvoltage was detected (>1)
	float voltages[4] = {0};  //Returned voltage readings.  Pass an array of all zeros.

	version = GetDriverVersion();
	printf("Driver version: %.3f\n", version);

	version = GetFirmwareVersion(&idnum);
	printf("U12 Firmware version: %.3f\n\n", version);

	printf("Setting AO0 to %.3f V and AO1 to %.3f V\n", analogOut0, analogOut1);

	errorcode = AOUpdate(&idnum, demo, trisD, trisIO, &stateD,
					&stateIO, updateDigital, resetCounter, &count, analogOut0,
					analogOut1);
	handleError(errorcode, "AOUpdate");

	errorcode = AISample(&idnum, demo, &stateIO, updateIO, ledOn, 
					numChannels, channels, gains, disableCal, &overVoltage,
					voltages);
	handleError(errorcode, "AISample");

	printf("AI%ld = %.3fV\nAI%ld = %.3fV\n", channels[0], voltages[0], channels[1], voltages[1]);

	return 0;
}