Streaming Waveform Data

NI-FGEN provides the following programmatic examples:
  • LabVIEW: Fgen Arb Waveform Streaming.vi
  • LabWindows/CVI: ArbitraryWaveformStreaming.prj

The following example shows a case when you want to generate a 1.6 GB waveform using an NI arbitrary waveform generator with 256 MB of onboard memory. This 1.6 GB waveform may be in the host memory, on disk, or data that your application generates dynamically during generation.


1378

Complete the following steps to configure your application for streaming:

  1. Call the niFgen Allocate Waveform VI or the niFgen_AllocateWaveform function to specify the amount of onboard memory to reserve for streaming.
    The allocated memory, known as the streaming waveform, serves as a buffer for the streaming process. The size of the waveform you want to stream must be evenly divisible by the amount of onboard memory allocated for streaming to prevent the streaming waveform from being overwritten before it has generated.

    1378

  2. Set the Streaming Waveform Handle property or the NIFGEN_ATTR_STREAMING_WAVEFORM_HANDLE attribute to the waveform handle returned in step 1.
    Setting this property or attribute ensures that none of your streaming data is overwritten before it is generated. NI-FGEN monitors your progress to ensure that you write fresh data fast enough to keep up with the generation. If your application fails to keep up or attempts to write fresh data over data that has not been generated, NI-FGEN returns an error.

    1378

  3. Call the niFgen Write Waveform VI or the niFgen_WriteWaveform function to write the first part of the waveform data to the streaming waveform in onboard memory.
    Tip When transferring large blocks of waveform data, break the data into smaller blocks and call the niFgen Write Waveform VI or the niFgen_WriteWaveform function multiple times. The data is appended sequentially. A computer can allocate smaller blocks of a large waveform faster than allocating a single large contiguous block in memory. Depending on the amount of RAM on the computer, transferring ten 16 MB blocks may be faster than transferring one 160 MB block.

    1378

  4. Call the niFgen Initiate Generation VI or the niFgen_InitiateGeneration function to begin the waveform generation.
    As the waveform generates, space in the streaming waveform becomes free.

    1378

  5. Use the Space Available in Streaming Waveform property or the NIFGEN_ATTR_STREAMING_SPACE_AVAILABLE_IN_WAVEFORM attribute to determine how much of the streaming waveform is free for writing new data.
    As the waveform generates, space becomes available to write more waveform data.

    1378

  6. Call niFgen Write Waveform VI or the niFgen_WriteWaveform function to write a new block of waveform data to the streaming waveform in onboard memory.

    1378

    If the size of the new block of waveform data is larger than the space available, NI-FGEN waits until sufficient space becomes available or the streaming write time expires. Use the Streaming Write Timeout property or the NIFGEN_ATTR_STREAMING_WRITE_TIMEOUT attribute to change the streaming write time.


    1378

  7. Repeat steps 5 and 6 until all waveform data is written.

    1378

Streaming Waveform Data to Multiple Channels

To stream data to multiple channels, you must provide interleaved data. You cannot stream to two or more channels with individual, non-interleaved writes for each channel.

Improving Streaming Performance

To improve your maximum sustainable transfer rate for streaming, consider the following recommendations:

  • Adjust the Data Transfer Block Size property or the NIFGEN_ATTR_DATA_TRANSFER_BLOCK_SIZE attribute. The default data transfer block size for NI-FGEN is 2 MSa (or 4 MB). If you were to write a 16 MB waveform to the signal generator, the complete transfer would occur using four separate DMA transfers. If you modify the data transfer block size to 8 MSa (16 MB), for example, the data transfer is more efficient and is instead accomplished in a single transfer.
  • Configure advanced streaming properties by calling the Maximum In-Flight Read Requests or Preferred Packet Size property or the NIFGEN_ATTR_DATA_TRANSFER_MAXIMUM_IN_FLIGHT_READS, NIFGEN_ATTR_DATA_TRANSFER_PCI_DMA_OPTIMIZATIONS, or NIFGEN_ATTR_DATA_TRANSFER_PREFERRED_PACKET_SIZE attributes.
  • Optimize the bus bandwidth usage for multi-device streaming applications by calling the Maximum Bandwidth property or the NIFGEN_ATTR_DATA_TRANSFER_MAXIMUM_BANDWIDTH attribute.
  • When streaming from drives, consider the drive speed for maximum sustainable rates.

    Transfer rates from drives can vary for a number of reasons, including where the data is physically stored on the drive and how much data is stored. Storing your waveform files on a fairly empty, defragmented drive may help increase performance.

  • Use a redundant array of independent disks (RAID) configuration to utilize striping to increase data transfer rates from disk.
  • When using 18-slot PXI chassis, install the signal generator used for streaming in the first segment (slots 2 to 6) of the PXI chassis.
  • Utilize Direct DMA.

Using Direct DMA to Improve Streaming Performance

You can achieve high rates of data transfer to the onboard memory by configuring your device for Direct DMA.

  1. Enable the signal generator for direct DMA writes by setting the Direct DMA Enabled property or the NIFGEN_ATTR_DIRECT_DMA_ENABLED attribute.
    After enabled, NI-FGEN monitors and reports any issues with the direct DMA transfer.
  2. Identify the waveform data source and set the Direct DMA Window Address property or the NIFGEN_ATTR_DIRECT_DMA_WINDOW_ADDRESS attribute to the address provided by your direct DMA-compatible data source.
  3. Set the Direct DMA Window Size property or the NIFGEN_ATTR_DIRECT_DMA_WINDOW_SIZE attribute to the size of the memory window provided by your direct DMA-compatible data source.
  4. Use the niFgen Write Waveform (Direct DMA I16) VI or the niFgen_WriteBinary16Waveform function to write blocks of data to the signal generator. For each block of data written to the signal generator, you provide the address of the direct DMA window instead of an array of samples residing in host memory. NI-FGEN detects when the address is within the direct DMA window and handles the transfer appropriately.