int main (int argc, char *argv[]) { float version = 0.0; long errorcode; long idnum = -1; //Using first found U12 long demo = 0; //Normal operations long trisD = 0; //Directions for D0-D15 long trisIO = 0; //Directions for IO0-IO3 long stateD = 0; //Output states for D0-D15 long stateIO = 0; //Output states for IO0-IO3 long updateDigital = 0; //Indicates is tris states will be written long outputD = 0; //Returns of the output registers for D0-D15 long outputIO = 0; //Output states of IO0-IO3. Cannot be read. version = GetDriverVersion(); printf("Driver version: %.3f\n", version); version = GetFirmwareVersion(&idnum); printf("U12 Firmware version: %.3f\n\n", version); /* Setting and reading directions and states */ trisD = (long)0x4800; //Setting D0-7 to outputs, D8-15 to inputs (b0000000011111111) trisIO = (long)0x0; //Setting IO0-1 to outputs, IO2-3 to inputs (b0011) stateD = (long)0x4800; //Setting D0-3 to low. D4-7 to high (b0000000011110000) stateIO = (long)0x0; //Setting IO0 to low. IO1 to high (b0010) outputIO = trisIO & stateIO; updateDigital = 1; //Updating D and IO lines errorcode = DigitalIO(&idnum, demo, &trisD, trisIO, &stateD, &stateIO, updateDigital, &outputD); handleError(errorcode, "DigitalIO (update)"); printf("DigitalIO, updating lines\n"); printf("D directions (read) = 0x%.4lx, states (read) = 0x%.4lx, output registers (read) = 0x%.4lx\n", trisD, stateD, outputD); printf("IO directions (set) = 0x%lx, states (read) = 0x%lx, output (set) = 0x%lx\n\n", trisIO, stateIO, outputIO); /* Only reading current directions (D lines only) and states */ trisD = 0; trisIO = 0; stateD = 0; stateIO = 0; updateDigital = 0; //Only read performed errorcode = DigitalIO(&idnum, demo, &trisD, trisIO, &stateD, &stateIO, updateDigital, &outputD); handleError(errorcode, "DigitalIO (read)"); printf("DigitalIO read only:\n"); printf("D directions = 0x%.4lx, states = 0x%.4lx, output registers = 0x%.4lx\n", trisD, stateD, outputD); printf("IO states = 0x%lx\n", stateIO); return 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; }
bool initializeCore(void) { int dllStatus; BYTE verMajor,verMinor,verRevision,verRelease; InitializeOls (); dllStatus=GetDllStatus (); if (dllStatus!=0) { printf ("Unable to initialize WinRing0 library\n"); switch (dllStatus) { case OLS_DLL_UNSUPPORTED_PLATFORM: printf ("Error: unsupported platform\n"); break; case OLS_DLL_DRIVER_NOT_LOADED: printf ("Error: driver not loaded\n"); break; case OLS_DLL_DRIVER_NOT_FOUND: printf ("Error: driver not found\n"); break; case OLS_DLL_DRIVER_UNLOADED: printf ("Error: driver unloaded by other process\n"); break; case OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK: printf ("Error: driver not loaded from network\n"); break; case OLS_DLL_UNKNOWN_ERROR: printf ("Error: unknown error\n"); break; default: printf ("Error: unknown error\n"); } return false; } GetDriverVersion (&verMajor,&verMinor,&verRevision,&verRelease); if ((verMajor>=1) && (verMinor>=2)) return true; return false; }
int main (int argc, char *argv[]) { char fStr[50]; float version = 0.0; long error = 0; int i = 0; long idnum = -1; //Using first found U12 long demo = 0; //Normal operations long channel = 0; //Channel to be read/set. Used by multiple functions. long state = 0; //Digital states to set or states read. Used by digital functions. //EAnalogOut specific parameters float analogOut0 = 2.0, analogOut1 = 3.5; //Voltages of AO0 and AO1 to set //EAnalogIn specific parameters long gain = 0; //G=1, +-20 V (gain 0 = 1) long overVoltage = 0; //Returns >0 if overvoltage is detected float voltage = 0.0; //Returns the voltage reading //EDigitalOut specific paramters long writeD = 0; //Indicates if D line is to be written instead of IO line //EDigitalIn specific paramters long readD = 0; //Indicates if D line is read instead of IO line //ECount specific parameters long resetCounter = 0; //Indicates if counter is reset to zero after read double count = 0; //Current count before reset double ms = 0; //Returns the number of milliseconds since the Epoch. version = GetDriverVersion(); printf("Driver version: %.3f\n", version); version = GetFirmwareVersion(&idnum); printf("U12 Firmware version: %.3f\n\n", version); /* Setting analog outputs */ printf("Setting AO0 to %.3f V and AO1 to %.3f V.\n\n", analogOut0, analogOut1); error = EAnalogOut(&idnum, demo, 2.0, 3.5); handleError(error, "EAnalogOut"); /* Reading analog inputs */ printf("Reading some analog inputs:\n"); /* Reading from single-ended AI0 and AI1 */ for(i = 0; i < 2; i++) { channel = i; error = EAnalogIn(&idnum, demo, channel, gain, &overVoltage, &voltage); sprintf(fStr, "EAnalogIn (%ld)", channel); handleError(error, fStr); printf("Single-ended AI%ld = %.3f V, overVoltage = %ld\n", channel, voltage, overVoltage); } printf("\n"); /* Reading from differential AI0-AI1 (channel 8) and AI2-AI3 (channel 9), G=1 (+-20 V) */ for(i = 8; i < 10; i+=1) { channel = i; error = EAnalogIn(&idnum, demo, channel, gain, &overVoltage, &voltage); sprintf(fStr, "EAnalogIn (%ld) diff.", channel); handleError(error, fStr); printf("Differential AI%ld-AI%ld = %.3f V, overVoltage = %ld\n", (channel-8)*2, (channel-8)*2+1, voltage, overVoltage); } /* Setting digital outputs */ printf("\nSetting digital lines IO1 and D1 to output-low, and IO2 to output-high\n\n"); channel = 1; writeD = 0; state = 0; error = EDigitalOut(&idnum, demo, channel, writeD, state); handleError(error, "EDigitalOut (IO1)"); channel = 1; writeD = 1; state = 0; error = EDigitalOut(&idnum, demo, channel, writeD, state); handleError(error, "EDigitalOut (D1)"); channel = 2; writeD = 0; state = 1; error = EDigitalOut(&idnum, demo, channel, writeD, state); handleError(error, "EDigitalOut (IO2)"); /* Reading digital inputs */ printf("Reading some digital inputs:\n"); channel = 0; readD = 0; error = EDigitalIn(&idnum, demo, channel, readD, &state); handleError(error, "EDigitalIn (IO0)"); printf("IO%ld state = %ld\n", channel, state); channel = 0; readD = 1; error = EDigitalIn(&idnum, demo, channel, readD, &state); handleError(error, "EDigitalIn (D0)"); printf("D%ld state = %ld\n\n", channel, state); /* Read from the Counter */ //Reseting counter first printf("Reading Counter:\nResetting count and waiting 2 seconds for new data.\n"); resetCounter = 1; error = ECount(&idnum, demo, resetCounter, &count, &ms); handleError(error, "ECount (reset)"); //Wait for 2 seconds for data usleep(2000000); //Read Counter reading with 2 second timer resetCounter = 0; error = ECount(&idnum, demo, resetCounter, &count, &ms); handleError(error, "ECount (read)"); printf("Count = %.0f, OS timer = %0.3f ms\n", count, ms); return 0; }