Chapter 4 163
Downloading and Using Files
Downloading ARB Waveform Data
//wave and the Q channel will a cosine wave.
for (int i=0; i<SAMPLES; ++i)
{
iqData[2*i] = AMPLITUDE * sin(two_pi*i/(float)SAMPLES);
iqData[2*i+1] = AMPLITUDE * cos(two_pi*i/(float)SAMPLES);
}
// make sure bytes are in the order MSB(most significant byte) first. (PC only).
char* cptr = (char*)iqData;// cast the integer values to characters
for (int i=0; i<(4*SAMPLES); i+=2)// 4*SAMPLES
{
char temp = cptr[i];// swap LSB and MSB bytes
cptr[i]=cptr[i+1];
cptr[i+1]=temp;
}
// now write the buffer to a file
out_stream.write((char*)iqData, 4*SAMPLES);
return 0;
}
Downloading Using C++
The following program uses the GPIB to download a file directly to the baseband generator (volatile
memory) for play back in the Dual ARB player. The program allocates a memory buffer on the PC or
workstation of 102400 bytes (100*1024 bytes). The actual size of the buffer is limited by the memory on
your PC or workstation, so the buffer size can be increased or decreased to meet your system limitations.
While this program is directed at using the GPIB to download a waveform file into volatile memory, it can
be modified to store files in non-volatile memory or for use over the LAN with the following minor changes:
LAN Replace the GPIB assignment for the instOpenString object with “lan[<hostname or IP
address>]” for the signal generator.
Non-volatile Memory Remove BBG1 from the file path assigned to the instDestFile object.
The program also includes some error checking to alert you when problems arise while trying to download
files. This includes checking to see if the file exists.