Hello,
I'm using a T7-pro with LJM and Python. I need to acquire 1 analog signal that is synchronized to an external clock (which can vary between 1 and 70Hz) and another analog signal at 10Hz (stability of the 10Hz is not important).
The synchronized signal acquisition is working, I'm using the following:
handle = ljm.openS("ANY", "ANY", "ANY")
# Setup analog inputs
ljm.eWriteName(handle, "AIN_ALL_NEGATIVE_CH", ljm.constants.GND)
ljm.eWriteName(handle, "AIN0_RANGE", 10.0)
ljm.eWriteName(handle, "AIN1_RANGE", 10.0)
ljm.eWriteName(handle, "STREAM_SETTLING_US", 0)
ljm.eWriteName(handle, "STREAM_RESOLUTION_INDEX", 7)# Ensure triggered stream is disabled (triggered != external clock)
ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 0)# Enable external clock on CIO3
ljm.eWriteName(handle, "STREAM_CLOCK_SOURCE", 2)
ljm.eWriteName(handle, "STREAM_EXTERNAL_CLOCK_DIVISOR", 1)# Configure the library so that eStreamRead returns immediately
ljm.writeLibraryConfigS(ljm.constants.STREAM_SCANS_RETURN, ljm.constants.STREAM_SCANS_RETURN_ALL_OR_NONE)
ljm.writeLibraryConfigS(ljm.constants.STREAM_RECEIVE_TIMEOUT_MS, 200) # Should be set according to the vector frequency + some margin. If too low or 0, th$# Configure and start stream
scan_names = ["AIN0"]
scan_list = ljm.namesToAddresses(numFrames=len(scan_names), aNames=scan_names)[0]
ljm.eStreamStart(handle, scansPerRead=1, numAddresses=len(scan_list), aScanList=scan_list, scanRate=100)# Read with this
ret = ljm.eStreamRead(handle)
When I call ljm.eReadName(handle, "AIN1"), I get the STREAM_IS_ACTIVE exception.
Is it possible to read two analog inputs this way ? Should I modify something ?
Thanks,
Ben
It is not possible to read the AIN using command response mode while stream mode is active. Stream mode needs to take full control of the ADC to avoid conflicts.
Since your clock rate is slow you could probably stop using stream mode and create a lua script that watches for your clock edge with a counter. When a clock edge is seen, sample the AIN. Also run an Interval timer to sample the other AIN at 10Hz:
https://labjack.com/support/datasheets/t-series/lua-scripting
Another alternative would be to stream as fast as possible. Add your synchronized AIN, a counter connected to your clock signal, and your 10Hz AIN to the scan list, then perform some post processing to pick out your synchronized samples (search for scans with counter increments) and do some decimation to keep 10 samples per second for the other AIN.
Thanks for your answer !
I'll have a go with the lua script, I find it quite an elegant solution in my case.
I'll upload the script to the T7 directly using my software (by writing to LUA_SOURCE_WRITE) and send the data using USER_RAM_FIFO0_DATA_F32 etc.