Requires LJM 1.2100 or later.
Initializes all device registers and stream out objects necessary to start an aperiodic stream-out.
Requires LJM 1.2100 or later.
Initializes all device registers and stream out objects necessary to start an aperiodic stream-out.
LJM_ERROR_RETURN LJM_InitializeAperiodicStreamOut(
int Handle,
int StreamOutIndex,
int TargetAddr,
double ScanRate)
LJM errorcodes or 0 for no error.
For each waveform being streamed out:
The aperiodic stream-out functions use the same targets as listed on the stream-out page.
Call LJM_InitializeAperiodicStreamOut with the selected target.
LJM_WriteAperiodicStreamOut can be called before starting stream to preemptively queue up data for the device stream out buffer.
Next, start stream with STREAM_OUT#(0:3) in the scan list. The stream-out index must match the index value passed to InitializeAperiodicStreamOut.
Name | Start Address | Type | Access | |
|
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.
|
The order of STREAM_OUT#(0:3) in the scan list determines when the target updated. For example, if STREAM_OUT3 is before STREAM_OUT0 in the scan list, STREAM_OUT3_TARGET will be updated before STREAM_OUT0_TARGET.
Read from stream using LJM_eStreamRead, if there are stream-in channels.
Call LJM_WriteAperiodicStreamOut to add data points to stream out.
To stop stream, use LJM_eStreamStop.
LJM_InitializeAperiodicStreamOut allocates a 20 second buffer in LJM (according to the stream rate).
LJM_InitializeAperiodicStreamOut sets the device stream out buffer (STREAM_OUT#(0:3)_BUFFER_ALLOCATE_NUM_BYTES) to 16384.
This function writes to the following registers, which should not be set manually when using LJM_InitializeAperiodicStreamOut for a given stream index:
int handle; int err = 0; double scanRate = 1000; const int NUM_WRITES = 9; 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_InitializeAperiodicStreamOut( handle, streamOutIndex, targetAddr, scanRate ); ErrorCheck(err, "LJM_InitializeAperiodicStreamOut"); printf("\n"); int queueVals; // Write some values to the device buffer before starting the stream err = LJM_WriteAperiodicStreamOut( handle, streamOutIndex, samplesToWrite, values, &queueVals ); ErrorCheck(err, "LJM_WriteAperiodicStreamOut"); 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"); int startTime = GetCurrentTimeMS(); err = LJM_eStreamStart( handle, scansPerRead, NUM_SCAN_ADDRESSES, aScanList, &scanRate ); ErrorCheck(err, "LJM_eStreamStart"); for (int i = 0; i < NUM_WRITES; i++) { err = LJM_WriteAperiodicStreamOut( handle, streamOutIndex, samplesToWrite, values, &queueVals ); ErrorCheck(err, "LJM_WriteAperiodicStreamOut in loop"); } int runTime = GetCurrentTimeMS() - startTime; // 512 samples * 10 writes = 5120 samples. scan rate = 1000 // samples/sec, so it should take 5.12 seconds to write all data out int streamOutMS = 1000 * samplesToWrite * (NUM_WRITES + 2) / scanRate; if (runTime < streamOutMS) { MillisecondSleep(streamOutMS - runTime); } err = LJM_eStreamStop(handle); ErrorCheck(err, "Problem closing stream"); err = LJM_Close(handle); ErrorCheck(err, "Problem closing device"); delete[] values;
Every LabJack is backed by our free Legendary Support, for life. Additionally, we provide all the software you need to get the most out of your LabJack. Read More