void main () { /* Variable Declarations */ int ch; int Row, Col; int BdNum = 0; int DevNum = 0; int ConfigVal = 0; int ULStat = 0; int Gain = BIP10VOLTS; int chan, ExitFlag; WORD DataValue; float volts; /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed DONTSTOP :program will continue even if error occurs. Note that STOPALL and STOPFATAL are only effective in Windows applications, not Console applications. */ cbErrHandling (PRINTALL, DONTSTOP); // Initialize output to ground. // Note that the default behavior is to update D/A's immediately // upon cbAOut or cbAOutScan. volts = 0.0; chan = 0; ULStat = cbFromEngUnits(BdNum, Gain, volts, &DataValue); ULStat = cbAOut (BdNum, chan, Gain, DataValue); // Set DAC Update mode to hold off updating D/A's until issued Update Command // Parameters // BOARDINFO : General information about the board // BdNum : Number used by CB.CFG to describe this board // DevNum : Selects device; in this case, selects D/A channel to configure // Note that -1 selects all D/A channels // BIDACUPDATEMODE : Selects update mode for D/A, whether immediately (via cbAOut // or cbAOutScan) or upon issuing BIDACUPDATECMD // UPDATEONCOMMAND : Delay D/A output updates from cbAOut or cbAOutScan until // BIDACUPDATECMD is issued. DevNum = ALLDEVICES; ULStat = cbSetConfig(BOARDINFO, BdNum, DevNum, BIDACUPDATEMODE, UPDATEONCOMMAND); ExitFlag = FALSE; while (!ExitFlag) { // Set up the display screen ClearScreen(); printf ("Demonstration of DAC Update Modes with cbAOut()\n\n"); GetTextCursor (&Col, &Row); MoveCursor (0, 3); printf ("Enter a voltage between -10.0 and +10.0: "); MoveCursor (41, 3); if (0==scanf ("%f", &volts)) { printf("Error : Invalid entry."); break; } ULStat = cbFromEngUnits(BdNum, Gain, volts, &DataValue); ULStat = cbAOut (BdNum, chan, Gain, DataValue); printf ("\n %.2f volts has been sent to D/A 0.\n\n", volts); printf ("Press U to update D/A output, Q to quit, \n or any other key to continue:\n "); while (!kbhit()){} ch=getch(); if (ch=='q' || ch=='Q') ExitFlag=TRUE; else if (ch=='u' || ch=='U') { // Issue command to update all the D/A's with the last value written // to them via cbAOut or cbAOutScan // // Parameters // BOARDINFO : General information about the board // BdNum : Number used by CB.CFG to describe this board // DevNum : Not used for BIDACUPDATECMD // BIDACUPDATECMD : Update D/A outputs with last value written // ConfigVal : Note used for BIDACUPDATECMD DevNum = NOT_USED; ConfigVal = NOT_USED; ULStat = cbSetConfig(BOARDINFO, BdNum, DevNum, BIDACUPDATECMD, ConfigVal); printf("\nD/A output 0 has been updated. "); } else printf("\nD/A output 0 has not been updated!"); } printf ("\n"); }
MccUSBDAQDevice::MccUSBDAQDevice(ORBManager* orb_manager, std::string DeviceName, std::string Address, unsigned short ModuleNumber, int boardNum_, int numADChans_) : STI_Device(orb_manager, DeviceName, Address, ModuleNumber), boardNum(boardNum_), numADChans(numADChans_) { //constants for the usb daq physical device UDStat = 0; // DataValue = 0; Options = DEFAULTOPTION; // cbw software revision number RevLevel = (float)CURRENTREVNUM; if (driverMutex != 0) { driverMutex->lock(); // Declare UL Revision Level UDStat = cbDeclareRevision(&RevLevel); /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed DONTSTOP :program will continue even if error occurs. Note that STOPALL and STOPFATAL are only effective in Windows applications, not Console applications. */ cbErrHandling (DONTPRINT, DONTSTOP); //must come before evaluating ranges //Set whether single-ended or differential. int errorCode = cbSetConfig(BOARDINFO, boardNum, 0, BINUMADCHANS, numADChans); //Check setting errorCode = cbGetConfig (BOARDINFO, boardNum, 0, BINUMADCHANS, &numADChans); //numADChans == 0 occurs when the usb daq is not connected. if (numADChans == 0) { initialized = false; return; } //Get the number of DA outs cbGetConfig (BOARDINFO, boardNum, 0, BINUMDACHANS, &numDAChans); driverMutex->unlock(); } if (numDAChans == 0) { initialized = false; return; } getChannelInfo(); if (!availableADInRanges.empty()) ADInRange = availableADInRanges.begin()->first; else ADInRange = BIP10VOLTS; //set it to something to avoid complaints. Will be ignored if (!availableDAOutRanges.empty()) DAOutRange = availableDAOutRanges.begin()->first; else DAOutRange = UNI5VOLTS; //set it to something to avoid complaints. Will be ignored }