import sys import traceback from datetime import datetime import u3 # 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 = 1000 # At high frequencies ( >5 kHz), the number of samples will be MAX_REQUESTS # times 48 (packets per request) times 25 (samples per packet). d = u3.U3() # To learn the if the U3 is an HV d.configU3() # For applying the proper calibration to readings. d.getCalibrationData() ##Assigns FIO4 as analog input timer, PinOffset 4 = FIO4 is timer, 1 timer enabled d.configIO(TimerCounterPinOffset=4, NumberOfTimersEnabled=2) ##Mode 12= 16 bit rising edge period measurement, initial value = 0 u3.Timer0Config(TimerMode=1, Value=32578) u3.Timer1Config(TimerMode=12, Value=0) ##3=1MHz clock base, 100= clock divisor. 1MHz/100=10kHz. 16-bit timer/10kHz sampling= 65536/10,000=6.5 seconds=Maximum time allowed between pulses. d.configTimerClock(3,256) print("Configuring U3 stream") d.streamConfig(NumChannels=1, PChannels=[200], NChannels=[31], Resolution=3, ScanFrequency=SCAN_FREQUENCY) try: print ("start stream",) d.streamStart() start = datetime.now() print (start) missed = 0 dataCount = 0 packetCount = 0 for r in d.streamData(): if r is not None: # Our stop condition if dataCount >= MAX_REQUESTS: break if r['errors'] != 0: print ("Error: %s ; " % r['errors'], datetime.now()) if r['numPackets'] != d.packetsPerRequest: print ("----- UNDERFLOW : %s : " % r['numPackets'], datetime.now()) if r['missed'] != 0: missed += r['missed'] print ("+++ Missed ", r['missed']) print (r['AIN200']) else: # Got no data back from our read. # This only happens if your stream isn't faster than the # the USB read timeout, ~1 sec. print ("No data", datetime.now()) finally: stop = datetime.now() d.streamStop() print ("stream stopped.") d.close()