/* * dac.cpp - generate a staircase voltage. * * compile: bcc32 dac.cpp rulbus.lib */ #include <stdio.h> // for printf() etc. #include <stdlib.h> // for strtol() #include <windows.h> // for Sleep() #include "rulbus.h" // rulbus interface static int usage(); // print program usage, return EXIT_FAILURE static int error(); // print error, return EXIT_FAILURE /* * main - handle commandline arguments and generate staircase voltage on DAC. */ int main( int argc, char *argv[] ) { /* * handle commandline arguments: */ if ( argc < 2 ) return usage(); /* * the name on the commandline must correspond to the name of a 12-bit * DAC in the Rulbus device configuration file, typically rulbus.conf. */ char *name = argv[1]; /* * open the DAC: */ int32 handle; if ( rb8510_dac12_open( &handle, name ) ) return error(); /* * 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++ ) { fprintf( stdout, "[%d]", i ); if ( rb8510_dac12_setVoltage( handle, i ) ) return error(); Sleep( 1000 ); // delay one second } /* * close the DAC: */ if ( rb8510_dac12_close( handle ) ) return error(); return EXIT_SUCCESS; } /* * usage - print program usage. */ static int usage() { fprintf( stdout, "Usage: dac device-name\n" ); return EXIT_FAILURE; } /* * error - retrieve and print Rulbus error. */ static int error() { const int len = 100; char msg[len]; rdl_getLastError( msg, len ); fprintf( stdout, "%s\n", msg ); return EXIT_FAILURE; }