Writing Waveforms to Your Device
Before you can generate any data, you must write your waveform(s) to the device onboard memory. Use the Write Named Waveform VIs/functions to write waveform data from your PC memory to your onboard device memory.
The Write Named Waveform VIs/functions are shown in the following table.
LabVIEW VIs | C Functions |
---|---|
Use one of the following instances of the
niHSDIO Write Named Waveform polymorphic VI:
|
niHSDIO_WriteNamedWaveformU32 |
niHSDIO_WriteNamedWaveformU16 | |
niHSDIO_WriteNamedWaveformU8 | |
niHSDIO_WriteNamedWaveformWDT | |
niHSDIOWriteNamedWaveformFromFileHWS |
You can associate names with each waveform you write to the device. Naming waveforms is optional if you are writing a single waveform to the device and are not using scripts. You must name each waveform if you write multiple waveforms to your device. Use niHSDIO_ConfigureWaveformToGenerate to select which named waveform is generated at Initiate. However, you must also name each waveform when using scripts, as the script generate statement uses the waveform name to know which waveform to generate.
Note Select Programming»Reference»Script Instructions from the table of contents of this help file for more information on the generate statement and other scripting instructions. |
When using very large waveforms, it may be problematic to allocate enough PC memory to perform a single Write Named Waveform call. You can write large waveforms to your device by writing smaller blocks at a time. Use the niHSDIO Allocate Named Waveform VI and niHSDIO_AllocateNamedWaveform function and Write Named Waveform VI/functions (listed in the previous table) to accomplish this task.
Note An easier way to handle the task in the example below is by using niHSDIO Write Named Waveform From File (HWS), as this VI/function handles memory allocation for you. |
Refer to the following code snippets for an example of writing a 1 MS waveform to onboard memory in LabVIEW and in C.
#define BLOCK_SIZE 8192
ViUInt32 data[BLOCK_SIZE];
.
.
.
niHWS_OpenFile("mydata.hws", niHWS_Val_ReadOnly, &fileHandle;.
niHWS_GetWfmReference (fileHandle, VI_NULL, VI_NULL, &wfmRef);
/* reserve onboard memory, name the waveform "myWfm" */
niHWS_GetWfmI32Attribute (wfmRef, niHWS_Attr_WaveformSize, &wfmSize);
niHSDIO_AllocateNamedWaveform (instrHdl, "myWfm", wfmSize);
/* write waveform 1 block at a time */
numSamplesWritten = 0;
while (numSamplesWritten <= wfmSize)
{
/* Read BLOCK_SIZE samples from .hws file, put in data */
niHWS_ReadDigitalU32(wfmRef, BLOCK_SIZE, data, &actualSamplesRead);
niHSDIO_WriteNamedWaveformU32 (instrHdl, "myWfm", actualSamplesRead, data);
numSamplesRead = numSamplesRead + actualSamplesRead;
}
.
.
.
Each call to a Write Named Waveform VI/function writes to the end of the most previously written data.
Note Closing the session using the niHSDIO close VI or the niHSDIO_close function also deletes all waveforms from your device. You can manually delete a single named waveform from onboard memory by calling the niHSDIO Delete Named Waveform VI or the niHSDIO_DeleteNamedWaveform function. |
Note If you try to write past the end of a waveform, NI-HSDIO returns an error. |
Note NI digital waveform generator/analyzers require blocks be multiples of 32 samples for NI 654x/655x devices or 64 samples for NI 656x devices when writing to preallocated waveforms. The overall waveform size does not have this restriction, but it must be even for the NI 654x/655x devices or a multiple of four for the NI 656x (a multiple of eight if the NI 656x is in DDR mode). The last call to Write Named Waveform should write enough data to fill the waveform. |