PeriodicStreamOut [LJM User's Guide]
Requires LJM 1.2100 or later.
Initializes device registers and sends waveform data to a device stream buffer to output a periodic waveform. Calling this function will enable an out-stream that will loop over data values written to it when LJM_eStreamStart
is called, then stop streaming values when LJM_eStreamStop
is called.
Syntax
LJM_ERROR_RETURN LJM_PeriodicStreamOut(
int Handle,
int StreamOutIndex,
int TargetAddr,
double ScanRate,
int NumValues,
const double * aWriteData)
Parameters
Handle [in]
A device handle. The handle is a connection ID for an active device. Generate a handle with LJM_Open or LJM_OpenS.
StreamOutIndex [in]
The number assigned to this stream-out. See the Stream Out section of the T-series datasheet for more information.
TargetAddr [in]
The target register to send stream-out data to. See the Stream Out section of the T-series datasheet for a list of potential targets.
ScanRate [in]
The desired number of scans per second. Should be the same value as set in LJM_eStreamStart
. Keep in mind that data rate limits are specified in Samples/Second which is equal to NumAddresses * Scans/Second
or NumAddresses * ScanRate
.
NumValues[in]
The number of values to write to the stream-out buffer. This is also the number of values that will be looped over.
aWriteData[in]
The data array to be written to the stream-out buffer.
Returns
LJM errorcodes or 0
for no error.
Setting Up Periodic Stream-Out
For each waveform being streamed out:
Choose which target channel will output the waveform
Call
LJM_PeriodicStreamOut
Start stream with
STREAM_OUT#(0:3)
in the scan listStop stream
Target Selection
The periodic stream-out functions use the same targets as listed on the stream-out page.
DAC0
DAC1
FIO_STATE
FIO_DIRECTION
EIO_STATE
EIO_DIRECTION
CIO_STATE
CIO_DIRECTION
MIO_STATE
MIO_DIRECTION
Call LJM_PeriodicStreamOut
Call LJM_PeriodicStreamOut
with the selected target.
Start Stream
Next, start stream with STREAM_OUT#(0:3)
in the scan list. The stream-out index must match the index value passed to LJM_PeriodicStreamOut
.
The order of STREAM_OUT#(0:3)
in the scan list determines when the target is updated. For example, if STREAM_OUT3
is before STREAM_OUT0
in the scan list, STREAM_OUT3_TARGET
will be updated before STREAM_OUT0_TARGET
.
Stop Stream
To stop stream, use LJM_eStreamStop.
Remarks
LJM_PeriodicStreamOut
sets the device stream out buffer (STREAM_OUT#(0:3)_BUFFER_ALLOCATE_NUM_BYTES
) to 16384
.
Configuration
This function writes to the following registers. When using LJM_PeriodicStreamOut
for a given stream index, they should not be set manually:
STREAM_OUT#(0:3)_TARGET
STREAM_OUT#(0:3)_BUFFER_ALLOCATE_NUM_BYTES
STREAM_OUT#(0:3)_LOOP_NUM_VALUES
STREAM_OUT#(0:3)_ENABLE
STREAM_OUT#(0:3)_BUFFER_U16
STREAM_OUT#(0:3)_SET_LOOP
Example
PeriodicStreamOut Example
int handle;
int err = 0;
double scanRate = 1000;
int runTimeMS = 5000;
enum { NUM_SCAN_ADDRESSES = 1 };
const char * scanList[NUM_SCAN_ADDRESSES] = {"STREAM_OUT0"};
int targetAddr = 1000; // DAC0
int streamOutIndex = 0;
int samplesToWrite = 512;
// Make an arbitrary waveform that increases voltage linearly from 0-2.5V
double * values = new double[samplesToWrite];
double increment = double(1) / samplesToWrite;
for (int i = 0; i < samplesToWrite; i++) {
double sample = 2.5*increment*i;
values[i] = sample;
}
// Open first available LabJack device
err = LJM_Open(LJM_dtANY, LJM_ctANY, "LJM_idANY", &handle);
ErrorCheck(err, "LJM_Open");
PrintDeviceInfoFromHandle(handle);
ErrorCheck(err, "PrintDeviceInfoFromHandle");
err = LJM_PeriodicStreamOut(
handle,
streamOutIndex,
targetAddr,
scanRate,
samplesToWrite,
values
);
ErrorCheck(err, "LJM_PeriodicStreamOut");
int scansPerRead = scanRate/ 2;
int aScanList[NUM_SCAN_ADDRESSES];
int aTypes[NUM_SCAN_ADDRESSES];
int deviceScanBacklog;
int ljmScanBacklog;
err = LJM_NamesToAddresses(
NUM_SCAN_ADDRESSES,
scanList,
aScanList,
aTypes
);
ErrorCheck(err, "LJM_NamesToAddresses scan list");
err = LJM_eStreamStart(
handle,
scansPerRead,
NUM_SCAN_ADDRESSES,
aScanList,
&scanRate
);
ErrorCheck(err, "LJM_eStreamStart");
// Run for some time then stop the stream
MillisecondSleep(runTimeMS);
printf("Stopping stream...\n");
err = LJM_eStreamStop(handle);
ErrorCheck(err, "Problem closing stream");
err = LJM_Close(handle);
ErrorCheck(err, "Problem closing device");
delete[] values;