/* * dac.cpp - generate a staircase voltage. * * Compile: bcc32 -tWM dac.cpp rulbusdcl-omf-static.lib winutils-omf-static.lib */ #include <iostream> // for std::cout etc. #include <cstdlib> // for std::strtol() #include <windows.h> // for Sleep() #include "rdcl/rb8510_dac12.h" // header static int usage(); // print program usage, return EXIT_FAILURE /* * main - handle commandline arguments and generate staircase voltage on DAC. */ int main( int argc, char *argv[] ) { try { /* * handle commandline arguments: */ if ( argc < 4 ) return usage(); /* * for rack and Rulbus address, let strtol() determine the radix of the input: * octal for 012, decimal for 12, hexadecimal for 0x12. */ char *name = argv[1]; int rack = std::strtol( argv[2], 0, 0 ); int addr = std::strtol( argv[3], 0, 0 ); const int bipolar = 1; // bipolar const float vpb = 5e-3; // volt-per-bit /* * create the DAC: */ Rulbus::RB8510_Dac12 dac( name, addr, rack, bipolar, vpb ); /* * generate 11 one volt steps, one per second: * * Note that the last step generates a RulbusRangeError, because the * voltage is outside [-10.235 .. +10.24 V]. */ for ( int i = 0; i <= 11; i++ ) { std::cout << '[' << i << ']'; dac.setVoltage( i ); Sleep( 1000 ); // delay one second } /* * dac goes out of scope and is destroyed: */ } catch ( const std::exception& e ) { std::cout << std::endl << e << std::endl; } return EXIT_SUCCESS; } /* * usage - print program usage. */ static int usage() { std::cout << "Usage: dac device-name rulbus-rack rulbus-address" << std::endl; return EXIT_FAILURE; }