Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pynput import keyboard
- import u6
- from time import sleep
- import matplotlib.pyplot as plt
- d = u6.U6() # initialize the interface; assumes a single U6 is plugged in to a USB port
- d.configU6() # set default configuration
- d.configIO() # ask for analog inputs
- d.streamConfig(
- NumChannels=3,
- ChannelOptions=[7, 0, 0],
- ChannelNumbers=[0, 1, 2],
- ResolutionIndex=0,
- ScanFrequency=1000)
- d.packetsPerRequest = 1 # you can adjust this value to get more or less data
- #set DAC0 to 4.0 voltage
- DAC0 = 5000
- d.writeRegister(DAC0, 4.0)
- break_program = False
- x = []
- y = []
- def show_result(i, ain0):
- print("Iteration: " + str(i))
- print("AIN0(Diff): " + str(round( ain0, 3)))
- print("")
- def on_press(key):
- global break_program
- if key == keyboard.Key.esc:
- break_program = True
- return False
- # Try to measure a data set.
- def measure():
- try:
- d.streamStart()
- for r in d.streamData():
- if r is not None:
- if r['errors'] or r['numPackets'] != d.packetsPerRequest or r['missed']:
- print("error")
- break
- finally:
- d.streamStop()
- return r
- # Write a set of data to a file "data.txt"
- def writeData(r, i):
- print(d.getAIN(2))
- result = d.getAIN(positiveChannel=0, resolutionIndex=12, gainIndex=2, settlingFactor=0, differential=True)
- show_result(i, result)
- f2.write(str(result) + '\t\n')
- f2.close()
- f2.close()
- with keyboard.Listener(on_press=on_press) as listener:
- iterator = 0
- while not break_program:
- writeData(measure(), iterator)
- iterator = iterator + 1
- listener.join()
Add Comment
Please, Sign In to add comment