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. Must be a number between 0 and 3 (cannot stream-out more than 4 channels at once).
- TargetAddr [in]
- The target register to send stream-out data to. See the Stream-Out page 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 list
- Stop stream
1. 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
2. Call LJM_PeriodicStreamOut
Call LJM_PeriodicStreamOut with the selected target.
3. 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.
Name |
Start Address |
Type |
Access |
STREAM_OUT#(0:3)
Include one or more of these registers in STREAM_SCANLIST_ADDRESS#(0:127) to trigger stream-out updates. When added to the scan list these do count against the max scan rate just like normal input addresses, but they do not return any data in the stream read.
|
4800 |
UINT16 |
R
|
STREAM_OUT#(0:3)
- Starting Address: 4800
Include one or more of these registers in STREAM_SCANLIST_ADDRESS#(0:127) to trigger stream-out updates. When added to the scan list these do count against the max scan rate just like normal input addresses, but they do not return any data in the stream read.
- Data type: UINT16 (type index = 0)
-
Read-only
- Default value: 0
-
T7:
Expanded Names |
Addresses |
STREAM_OUT0,
STREAM_OUT1,
STREAM_OUT2,
STREAM_OUT3
Show All
|
4800,
4801,
4802,
4803
Show All
|
|
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.
4. 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
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;