#include #include #include #include #include #include typedef signed short INT16; #define POINTS 65536 void programExit(char *s) { printf("%s\n",s); exit(-1); } int main(int argc, char *argv[]) { ViSession defaultRM; ViStatus status; ViSession sess; ViUInt32 retCount; ViString arbGen = "arbGen"; ViString idnQuery = "*IDN?\n"; char idnResponse[100]; int idx; INT16 waveform[POINTS]; double pi = 3.14159265358979323; status = viOpenDefaultRM(&defaultRM); if ( status != VI_SUCCESS ) { programExit("viOpenDefaultRM() failed");} // // Open a session to the device using the alias // status = viOpen(defaultRM,arbGen,VI_EXCLUSIVE_LOCK,VI_NULL,&sess); if ( status != VI_SUCCESS ) { programExit("viOpen() failed");} // // Perform a clear to put the device I/O in a known state. // status = viClear(sess); if ( status != VI_SUCCESS ) { programExit("viClear() failed");} status = viWrite(sess,idnQuery,(ViUInt32)strlen(idnQuery),&retCount); if ( status != VI_SUCCESS ) { programExit("viWrite() failed");} if ( retCount != strlen(idnQuery)) { programExit("viWrite() failed\n"); } status = viRead(sess,idnResponse,sizeof(idnResponse),&retCount); if ( status != VI_SUCCESS ) { programExit("viRead() failed\n");} // null-terminate the response so it can be printed idnResponse[retCount] = 0; printf("%s = %s\n",arbGen,idnResponse); // // Create a damped sine arb waveform // for (idx=0; idx < POINTS; idx++) { waveform[idx] = (short)( 8191.0 * exp(-( 4.0/(double)POINTS) * (double)idx ) * sin(2.0 * pi * (10.0/(double)POINTS) * (double)idx) ); } // // Change the default formatted I/O buffer size so the download goes faster // status = viSetBuf(sess,VI_WRITE_BUF,32760); if ( status != VI_SUCCESS ) { programExit("viSetAttr(VI_WRITE_BUF) failed\n");} // // Write waveform[] to the arbGen // status = viPrintf(sess, "data:dac volatile,%*hb\n", idx, waveform); if (status != VI_SUCCESS) { programExit("data:dac failed"); } // // Make arbGen output = waveform just downloaded // status = viPrintf(sess,"FUNC:USER VOLATILE\n; FUNC USER\n; VOLT 5.0\n"); if (status != VI_SUCCESS) { programExit("FUNC:USER VOLATILE failed"); } }