T7: stream_basic.py Calling Each AIN instead of ainStr | LabJack
 

T7: stream_basic.py Calling Each AIN instead of ainStr

2 posts / 0 new
Last post
notlim
milton.chui's picture
T7: stream_basic.py Calling Each AIN instead of ainStr

I came from the U6 and used the streamTest.py and the u6.py from the LabJackPython-2.0.0.

I upgraded to the T7 but it looks like the setup is slightly different. stream_basic.py from the Python_LJM_2019_04_03 seems like a good place to start.

I've gotten pretty satisfied with a modified version of it which allows me to stream 14 channels. However within the while loop there is ainStr which prints out the string of all the selected channels. But I want to call each AIN instead so I can do calculations within the while loop (I'm doing a differential).

I essentially want to be able to call something like this:

Channel1 = AIN0 - AIN1

print(Channel1)

etc....

How do I set this up so I can do this?

 

 

 

ainStr = ""

for j in range(0, numAdresses):

   ainstr += "%00.5f, " % (aData[j])

print(ainStr)

File Attachment: 
LabJack Support
labjack support's picture
The Python documentation (

The Python documentation ( help(ljm.eStreamRead)  ) documents the returned aData of samples like so:

aData: Stream data list with all channels interleaved. It will
            contain scansPerRead*numAddresses values configured from
            eStreamStart. The data returned is removed from the LJM
            stream buffer.

The example displays the first scan of the returned samples. Sample order for a 14 channel stream of AIN0-AIN13, starting with the first eStreamRead's return, looks like:

aData[0]  # Scan0, AIN0
aData[1]  # Scan0, AIN1
aData[2]  # Scan0, AIN2
#...
aData[13]  # Scan0, AIN13

aData[14]  # Scan1, AIN0
aData[15]  # Scan1, AIN1
aData[16]  # Scan1, AIN2
# ...
aData[27]  # Scan1, AIN13

aData[28]  # Scan2, AIN0
aData[29]  # Scan2, AIN1
aData[30]  # Scan2, AIN2
#...
aData[41]  # Scan2, AIN13

# And so on until aData[scansPerRead*numAddresses-1]

 

So:

Channel1 = AIN0 - AIN1
print(Channel1)

For all scans in aData would look like (just one way of doing it):

i = 0
while i < len(aData):
    channel1 = aData[i] - aData[i+1]  # AIN0 - AIN1
    print(channel1)
    i += numAddresses  # start of next scan

If you want differential, you can configure analog input readings with differential. Configure with even channels (positive) and adjacent odd channels are the negative channel. Set the AIN_ALL_NEGATIVE_CH register to 1 for all analog inputs to be differential, and set individual even channels with the AIN#(0:13)_NEGATIVE_CH registers.

https://labjack.com/support/datasheets/t-series/ain#differential

For example, for a AIN2-3 differential, you can set register AIN2_NEGATIVE_CH to 3, and you stream only AIN2 for the AIN2-AIN3 differential.