Hepsko

labjak 1.0

May 22nd, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from pynput import keyboard
  2. import u6
  3. from time import sleep
  4. import matplotlib.pyplot as plt
  5.  
  6.  
  7. d = u6.U6()  # initialize the interface; assumes a single U6 is plugged in to a USB port
  8. d.configU6()  # set default configuration
  9. d.configIO()  # ask for analog inputs
  10.  
  11. d.streamConfig(
  12.     NumChannels=3,
  13.     ChannelOptions=[7, 0, 0],
  14.     ChannelNumbers=[0, 1, 2],
  15.     ResolutionIndex=0,
  16.     ScanFrequency=1000)
  17.  
  18. d.packetsPerRequest = 1  # you can adjust this value to get more or less data
  19.  
  20. #set DAC0 to 4.0 voltage
  21. DAC0 = 5000
  22. d.writeRegister(DAC0, 4.0)
  23. break_program = False
  24. x = []
  25. y = []
  26. def show_result(i, ain0):
  27.     print("Iteration: " + str(i))
  28.     # print("AIN0: " + str(round(ain0, 3)))
  29.     # print("AIN1: " + str(round(ain1, 3)))
  30.     print("AIN0(Diff): " + str(round( ain0, 3)))
  31.     print("")
  32.  
  33.  
  34. def on_press(key):
  35.     global break_program
  36.     if key == keyboard.Key.esc:
  37.         break_program = True
  38.         return False
  39.  
  40.  
  41.  
  42.  
  43. # Write a set of data to a file "data.txt"
  44. def writeData( i):
  45.     print(d.getAIN(2))
  46.     show_result(i, d.getAIN(0, differential=True))
  47.     f2.write(str(d.getAIN(0, differential=True)) + '\t\n')
  48.     f2.close()
  49.  
  50.  
  51.  
  52. with keyboard.Listener(on_press=on_press) as listener:
  53.     iterator = 0
  54.     while not break_program:
  55.         writeData(iterator)
  56.         iterator = iterator + 1
  57.         # sleep(1)
  58.     listener.join()
  59.  
Add Comment
Please, Sign In to add comment