error = AFG_Init(); // finds an AFG31000 and sets up a VI session // This is Example 2 (pg 195) from the current AFG31000 manual as of 1/14/23 // Translated from BASIC and it should do the same thing error = AFG_Command("*RST\r"); unsigned char wave[4000]; unsigned int Data; unsigned char High, Low; for (i=0; i<500; i++) { Data = i * (int)(16382 / 500); High = Data / 256; Low = Data & 0xff; wave[(2*i)] = High; wave[(2*i)+1] = Low; } for (i=500; i<800; i++) { Data = 16382; High = Data / 256; Low = Data & 0xff; wave[2*i] = High; wave[2*i+1] = Low; } for (i=800; i<1000; i++) { Data = (1000 - i) * (int)(16382 / 200); High = Data / 256; Low = Data & 0xff; wave[2*i] = High; wave[2*i+1] = Low; } for (i=1000; i<2000; i++) { Data = 0; High = Data / 256; Low = Data & 0xff; wave[2*i] = High; wave[2*i+1] = Low; } error = AFG_Command("TRACE:DATA EMEMORY1, #44000"); error = AFG_Array(wave, 4000); error = AFG_Command("\r"); error = AFG_Command("Source1:Function:Shape EMEM1\r"); error = AFG_Command("SOURCE1:VOLTAGE:LEVEL:IMMEDIATE:OFFSET 0.00\r"); error = AFG_Command("SOURCE1:VOLTAGE:LEVEL:IMMEDIATE:AMPLITUDE 1.00\r"); error = AFG_Command("Output1:State ON\r"); return 0; } //============================================================================== // Private functions /****************************************************************************** FUNCTION: AFG_Search ABSTRACT: Queries VISA to locate a Tek 3000 series AFG ARGUMENT: char *smatch - char buffer to return match results or empty string of none char *sserial - optional serial number to find a specific AFG, or empty string if none RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Search ( char *smatch, char *sserial) { (stuff removed) return retval; } /****************************************************************************** FUNCTION: AFG_Init ABSTRACT: Locates a specific AFG in VISA world, openes and initializes it, and returns a connection handle for futther calls. In version 0.0.1, only one AFG may be open at one time. ARGUMENT: char *sserial - The Tektronix serial number of the desired AFG RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Init ( char *sserial) { (stuff removed) return retval; } /****************************************************************************** FUNCTION: AFG_Close ABSTRACT: Closes a connection to an open AFG ARGUMENT: none RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Close (void) { (stuff removed) return retval; } /****************************************************************************** FUNCTION: AFG_Command ABSTRACT: Sends a command to the AFG ARGUMENT: char *scmd - the command string RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Command ( char *scmd) { int retval = AFG_INVALID; int handle = 1; if (0) // if (sim_mode) { retval = AFG_SUCCESS; } else // not sim mode { if ((0 < handle) && (ourdevice.open)) { status = viWrite(ourdevice.vi, (ViBuf)scmd, strlen(scmd), &retCnt); if (0 == status) { retval = AFG_SUCCESS; } } } // sim mode return retval; } /****************************************************************************** FUNCTION: AFG_Word ABSTRACT: Sends a word to the AFG in big endian format ARGUMENT: int n RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Word ( int n) { int retval = AFG_INVALID; int handle = 1; unsigned char lowbyte, highbyte; char scmd[8]; if (0) // if (sim_mode) { retval = AFG_SUCCESS; } else // not sim mode { if ((0 < handle) && (ourdevice.open)) { highbyte = n / 256; lowbyte = n - 256 * highbyte; scmd[0] = highbyte; scmd[1] = lowbyte; status = viWrite(ourdevice.vi, (ViBuf)scmd, 2, &retCnt); if (0 == status) { retval = AFG_SUCCESS; } } } // sim mode return retval; } /****************************************************************************** FUNCTION: AFG_Array ABSTRACT: Sends an array of chars to the AFG ARGUMENT: char *Arr int n RETURN: AFG_SUCCESS (0), or error code ******************************************************************************/ int AFG_Array (unsigned char *arr, int n) { int retval = AFG_INVALID; int handle = 1; if (0) // if (sim_mode) { retval = AFG_SUCCESS; } else // not sim mode { if ((0 < handle) && (ourdevice.open)) { status = viWrite(ourdevice.vi, (ViBuf)arr, n, &retCnt); if (0 == status) { retval = AFG_SUCCESS; } } } // sim mode return retval; }