from labjack import ljm from multiprocessing import Process, Pipe import numpy as np from time import sleep parallel = True handle = ljm.openS("t7", "usb", "any") # Process 1 def write(pipe): out = np.linspace(-10, 10, 1000) while True: try: for volt in out: pipe.recv() sleep(0.1) pipe.send(1) to_write = volt.round(decimals=2) # ljm.eWriteName(handle, 'TDAC0', to_write) print 'Written:', to_write except KeyboardInterrupt: break # Process 2 def read(pipe): while True: try: pipe.send(1) sleep(0.1) pipe.recv() data_read = ljm.eReadName(handle, "AIN0") # data_read = 'youpi' print 'Read:', data_read except KeyboardInterrupt: ljm.close(handle) break # Serial def serial(): out = np.linspace(-10, 10, 1000) while True: try: for volt in out: to_write = volt.round(decimals=2) ljm.eWriteName(handle, 'TDAC0', to_write) print 'Written:', to_write data_read = ljm.eReadName(handle, "AIN0") print 'Read:', data_read except KeyboardInterrupt: ljm.close(handle) break # If parallel: if parallel: pip1, pip2 = Pipe() p1 = Process(target=write, args=(pip1,)) p2 = Process(target=read, args=(pip2,)) p1.start() p2.start() else: serial()