Hey, I'm not to this, and I'm just trying to figure out a simple system that monitors 3AIs and sends a few outputs. The outputs and data logging to excel I have down, but I am lost as to how to interpret the data from the stream function into an object that I can write to my excel file. There's seems to be a lot of antiquated commands in the example code too which is adding to my confusion. Here's the stream portion I have setup:
import u6
d = u6.U6()
import time
d.streamConfig(NumChannels = 1, ResolutionIndex = 0,
SettlingFactor = 0, ChannelNumbers = [0], ChannelOptions = [7],
ScanFrequency = 10, SampleFrequency = 100 )
# Sampling rate (Hz) = NumChannels * ScanFrequency
d.streamStart
mins = 0
x=0
data=[0]
for i in range (100):
print ">>>>>>>>>>>>>>>>>>>>>", data
x=d.streamData(convert=True)
data.append(x)
time.sleep(1)
# Increment the minute total
mins += (1 / 60)
it just spits out a list with [0, <generator object streamData at 0x000000000A5607E0>, <generator object streamData at 0x000000000A560870>,
....etc]
Refer to the current stream example on how to use stream mode. I'm not exactly sure what you mean by it using "antiquated commands".
https://github.com/labjack/LabJackPython/blob/master/Examples/streamTest.py
The LabJacPython page on our site mentions where to find the documentation:
https://labjack.com/support/software/examples/ud/labjackpython
Looking at you code:
1. For streamConfig use the ScanFrequency parameter to set the scan rate and not SampleFrequency. If both are set then SampleFrequency is ignored. This is what we document for SampleFrequency in the streamConfig method:
Deprecated:
SampleFrequency, the frequency in Hz to sample. Use ScanFrequency
since SampleFrequency has always set the scan
frequency and the name is confusing.
2. Use "d.streamStart()" to properly start stream mode.
3. d.streamData returns a generator, so get the generator object and iterate through that for the data streamData yeilds. For example:
stream_gen=d.streamData(convert=True)
for i in range (100):
x = stream_gen.next()
if x is not None:
#other code in loop
or similar to our example:
i = 0
for x in d.streamData():
if x is not None:
# Our stop condition
if i >= 100:
break
i = i + 1
#other code in loop
4. If "data" is just a list of all AIN0 readings (channel 0), add to data like so in the stream loop:
data.extend(x["AIN0"])
5. time.sleep may not be needed as your loop is not controlling the scan rate. Stream mode is hardware timed and continuously runnning on the U6. You are reading buffered data from the U6, and delays in the stream read loop are discouraged to make sure you are reading data from the U6 at a fast enough rate. If you are not reading fast enough for the scan rate, the U6's stream buffer will fill and overflow.
If your scan rate is less than 100 Hz, consider using command/response mode. In a loop send commands for a reading, get its response and use delays to control the scan rate. The u6allio.py demonstrates reading multiple analog inputs in a loop but has no delay:
https://github.com/labjack/LabJackPython/blob/master/Examples/u6allio.py
6. After streaming, perform a d.streamStop call to stop stream mode.