Why we need VariableStreamSleep if we are using the externally clocked stream for T7?
I see an example of stream_external_clock.c and it has slept at the beginning of the loop
while (streamRead++ < NUM_LOOP_ITERATIONS) {
VariableStreamSleep(SCANS_PER_READ, SCAN_RATE, LJMScanBacklog);
Question: Why to sleep function if stream values should be triggered by external call?
As configured, stream_external_clock.c uses the LJM_STREAM_SCANS_RETURN mode of LJM_STREAM_SCANS_RETURN_ALL_OR_NONE:
https://labjack.com/support/software/api/ljm/constants/ljmstreamscansreturn
Since LJM_STREAM_SCANS_RETURN_ALL_OR_NONE causes eStreamRead to not block, VariableStreamSleep prevents the loop from becoming a busy wait loop.
You could instead enable LJM_STREAM_SCANS_RETURN_ALL mode and get rid of the VariableStreamSleep call, and eStreamRead would block without the loop performing busy wait.
I did that, however, I am getting the error - LJME_NO_RESPONSE_BYTES_RECEIVED
I would assume if you read stream and trigger it by an external clock - it should just wait until the scan data will appear in the stream, not return an error. Right?
Are the pulses on CIO3 regular? What is the maximum amount of time between pulses?
LJME_NO_RESPONSE_BYTES_RECEIVED indicates LJM didn't receive bytes from the LabJack for the timeout period. You can increase the timeout with LJM_STREAM_RECEIVE_TIMEOUT_MS:
http://labjack.com/support/software/api/ljm/function-reference/ljmestreamstart#externally-clocked
Or you can set the timeout as infinite using 0.
Reading with LJM_STREAM_SCANS_RETURN_ALL_OR_NONE allows your thread to have more control than waiting in eStreamRead with LJM_STREAM_SCANS_RETURN_ALL. For example, if the device doesn't get pulses (due to a hardware disconnect, maybe) or if you need to perform other tasks while waiting, your thread can continue to do work incrementally while still checking if data is ready.
What ScansPerRead are you using?