aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-02 21:53:34 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-02 21:53:34 -0400
commit21c687a7e5b3114d6cf5bd30302b8b84f0c4622e (patch)
tree2ea75101a233082e9976a6c6ef517a6394f3d646
parentd8c9aa3d2ec67e32407f05cfe2600bf58581a9ae (diff)
downloadpyExpControl-21c687a7e5b3114d6cf5bd30302b8b84f0c4622e.tar.gz
pyExpControl-21c687a7e5b3114d6cf5bd30302b8b84f0c4622e.zip
read and write with stream
-rw-r--r--labjackStreamTest.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/labjackStreamTest.py b/labjackStreamTest.py
index d4c6a9e..c5368ea 100644
--- a/labjackStreamTest.py
+++ b/labjackStreamTest.py
@@ -1,16 +1,18 @@
import sys
import traceback
+import time # For sleep, clock, time and perf_counter
from datetime import datetime
import u3
import u6
import ue9
+dacAddress = 5000 # DAC Modbus address
# MAX_REQUESTS is the number of packets to be read.
MAX_REQUESTS = 75
# SCAN_FREQUENCY is the scan frequency of stream mode in Hz
-SCAN_FREQUENCY = 5000
+SCAN_FREQUENCY = 1000
d = None
@@ -73,7 +75,7 @@ c['AINSlopes']['0']= 0.0000775030
print("Configuring UE9 stream")
-d.streamConfig(NumChannels=2, ChannelNumbers=[0, 1], ChannelOptions=[0, 0], SettlingTime=0, Resolution=12, ScanFrequency=SCAN_FREQUENCY)
+d.streamConfig(NumChannels=4, ChannelNumbers=[0, 1, 2, 3], ChannelOptions=[0, 0, 0, 0], SettlingTime=0, Resolution=12, ScanFrequency=SCAN_FREQUENCY)
'''
'''
@@ -86,6 +88,13 @@ Exiting...""")
try:
print("Start stream")
+ d.writeRegister(dacAddress, 2.05)
+ # d.singleIO(IOType=5, Channel=0, DAC=0)
+ dacNumber=0
+ bits = d.voltageToDACBits(1.4, dacNumber = dacNumber)
+ out=d.singleIO(IOType=5, Channel=dacNumber, DAC=bits)
+ print(out)
+
d.streamStart()
start = datetime.now()
print("Start time is %s" % start)
@@ -93,8 +102,14 @@ try:
missed = 0
dataCount = 0
packetCount = 0
+ v=0.1
for r in d.streamData():
+ # d.writeRegister(dacAddress, 0.05*dataCount)
+ v=v+0.1
+ print(v)
+ bits = d.voltageToDACBits(v, dacNumber = dacNumber)
+ out=d.singleIO(IOType=5, Channel=dacNumber, DAC=bits)
if r is not None:
# Our stop condition
if dataCount >= MAX_REQUESTS:
@@ -111,6 +126,10 @@ try:
missed += r['missed']
print("+++ Missed %s" % r["missed"])
+ if r["firstPacket"] != packetCount % 256:
+ print("----- Overflow skipping packets : expected %s got %s ; %s" %
+ (packetCount, r["firstPacket"], datetime.now()))
+
# Comment out these prints and do something with r
print("Average of %s AIN0, %s AIN1 readings: %s, %s" %
(len(r["AIN0"]), len(r["AIN1"]), sum(r["AIN0"])/len(r["AIN0"]), sum(r["AIN1"])/len(r["AIN1"])))