import os import time import math import u3 import datetime SAMPLE_RATE_SECONDS = 30 # MAX_REQUESTS is the number of packets to be read. MAX_REQUESTS = 1 # SCAN_FREQUENCY is the scan frequency of stream mode in Hz SCAN_FREQUENCY = 2000 def main(): daq = u3.U3() daq.getCalibrationData() # Set FIO0-FIO3 and FIO6 to Analog daq.configIO(FIOAnalog=0x4F) #writeFile(logFileName, "Configuring U3-HV stream\r\n") daq.streamConfig(NumChannels=5, PChannels=[0, 1, 2, 3, 6], NChannels=[32, 32, 32, 31, 31], Resolution=3, ScanFrequency=SCAN_FREQUENCY) while(1): try: daq.streamStart() except: # A previous stream could have been running. Stop it and try again. daq.streamStop() daq.streamStart() dataCount = 0 for s in daq.streamData(): if s is not None: if dataCount >= MAX_REQUESTS: break print("\r\nHave data.") if s["errors"] != 0: print("Errors counted: %s" % (s["errors"])) cnt = 0 # Display errors for err in s['result'][11::64]: errNum = ord(err) if errNum != 0: # Error detected in this packet print(" Packet %s, error %s" % (cnt, errNum)) cnt+=1 if s["numPackets"] != daq.packetsPerRequest: print("----- UNDERFLOW : %s" % (s["numPackets"])) if s["missed"] != 0: print("+++ Missed %s" % s["missed"]) dataCount += 1 else: print("\r\nNo data") daq.streamStop() main()