External clocked stream in python | LabJack
 

External clocked stream in python

6 posts / 0 new
Last post
Brad Waugh
Brad Waugh's picture
External clocked stream in python

I have created a nice python scrip to make an SPC chart with data from a T7 using command response based off of time and it works well.  Now I would like to add an encoder in to the mix and take a reading every so many encoder pulses.  I have the externaly clocked stream working with the clock devisor but it throws an exception if i lett it sit too long without spinning the encoder.  I am sure it has to do with LJM_STREAM_SCANS_RETURN and LJM_STREAM_RECEIVE_TIMEOUT_MS but am unsure how to set those in python.  


 https://labjack.com/support/software/api/ljm/function-reference/ljmestre...

LabJack Support
labjack support's picture
We somewhat recently made an

We somewhat recently made an externally clocked stream example in Python. It is available on our ljm-python GitHub (not on the main branch yet) and demonstrates how to set the LJM configurations:

https://github.com/labjack/labjack-ljm-python/blob/stream_external_clock...

Brad Waugh
Brad Waugh's picture
Thanks.  i added the falowing

Thanks.  i added the falowing to my code.  

        # Configure LJM for unpredictable stream timing
        ljm.writeLibraryConfigS(ljm.constants.STREAM_SCANS_RETURN,
                                ljm.constants.STREAM_SCANS_RETURN_ALL_OR_NONE)
        ljm.writeLibraryConfigS(ljm.constants.STREAM_RECEIVE_TIMEOUT_MODE,
                                ljm.constants.STREAM_RECEIVE_TIMEOUT_MODE_MANUAL)
        ljm.writeLibraryConfigS(ljm.constants.STREAM_RECEIVE_TIMEOUT_MS, 0)

 

i get a LJM library error code 1309 LJME_NO_SCANS_RETURNED but it goes away if i comment out 

ljm.writeLibraryConfigS(ljm.constants.STREAM_SCANS_RETURN,
                                ljm.constants.STREAM_SCANS_RETURN_ALL_OR_NONE)

 

it appears to be working as intended without it but i will need to do more testing

Brad Waugh
Brad Waugh's picture
Thanks that helped.  

Thanks that helped.

 

LabJack Support
labjack support's picture
You may notice that our

You may notice that our example just catches and ignores that specific exception; the LJME_NO_SCANS_RETURNED  error is expected with the STREAM_SCANS_RETURN_ALL_OR_NONE configuration if you call eStreamRead before scansPerRead scans have been acquired.

Brad Waugh
Brad Waugh's picture
I found that after I replied

I found that after I replied and have that working but thanks for your continued support.

 

I have another question now.  Is there a way to stop the stream without filling the buffer in the labjack.  On FI01 I have the line run signal which starts stream in a while loop.  When I remove the signal on FI01 i have to spin the encoder to fill the buffer to get out of the while loop