def OpenDevice(self): self._device = u12.U12() self.generic_read = { 'analog' : self.AnalogRead, 'digital' : self.DigitalRead, 'counter' : self.CounterRead, } return True
def daqfind(): """ Searches for NI Daqs Dev(0-127), cDAQN(0-127), Mod(0-7) Returns a list of valid handles for devices currently found on system. """ handles = [] try: import u12 daq = u12.U12() except: return handles daqs = daq.listAll() for i in daqs['localIDList']: if i < 9999: handles.append(i) #print handles return handles
def init_setup(): ###########PINS USED############# global SevenFivePin, TwentyFourPin, LJ1, num_readings SevenFivePin = 0 #AI0 TwentyFourPin = 1 #AI1 print("Pins Set") #####LOG TO FILE##### log_file_name = "" #logging.basicConfigicConfig(filename=log_file_name, level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') ####send to terminal#### logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') #########RESISTORS############### R_TF_1 = float(1100) R_TF_2 = float(360) R_S_1 = float(1100) R_S_2 = float(1100) R_LJ = float(46000) REff = lambda R_1, R_2: 1 / (1 / R_1 + 1 / R_2) R_TF_E = REff(R_LJ, R_TF_2) R_S_E = REff(R_LJ, R_S_2) global R_TF_Ratio, R_S_Ratio R_TF_Ratio = R_TF_E / (R_TF_1 + R_TF_E) R_S_Ratio = R_S_E / (R_S_1 + R_S_E) #########GENERAL CONSTANTS######### num_readings = 10 ########Initializing Lab Jack####### try: LJ1 = u12.U12() #labjack object # print(LJ1) print("Success!") except Exception, e: print("THIS IS NOT WORKING!") print(e) sys.exit()
import u12 d1 = u12.U12(serialNumber=100054654) d2 = u12.U12(serialNumber=100035035) #d1.eDigitalOut(1,0) #d1.eDigitalOut(1,1) #d1.eDigitalOut(0,1) #d1.eDigitalOut(0,0)
import u12 from time import sleep from time import time import sys sys.path.insert(0, '/home/albert/Documents/Albert Work/Scripts') from pressure import pressure_read d=u12.U12() d.eDigitalOut(0,1) d.eDigitalOut(1,1) p=pressure_read(d,5,True) d.eDigitalOut(0,0) d.eDigitalOut(1,0) print("Pressure: " + str(p)) d.close()
import u12 from time import sleep import numpy as np d = u12.U12(serialNumber=100054654) resistance = 5.7e2 #ohms PSgain = 6.5 for i in np.arange(1.0, 3.0, 0.25): d.eAnalogOut(i, 0) PSV = i * PSgain meas_current = d.eAnalogIn(7)['voltage'] actual_current = PSV / resistance print(meas_current - actual_current) sleep(5) d.eAnalogOut(0, 0) d.close() #output #1.0432839912280703 #0.9818393640350878 #0.9301603618421053 #0.9175438596491228 #0.9098101699561404 #0.7214124177631579 #0.5769599780701754 #0.583874725877193
import u12 from time import sleep from time import time from scipy.integrate import simps import datetime import csv import numpy as np import sys sys.path.insert(0, '/home/albert/Documents/Albert Work/Scripts') from funcs import PID d1 = u12.U12() d1 = d1 time_iter = 0.3 time_tot = 100 time_cont = 2 status_time = 20 num_iters = int(round(time_tot / time_iter)) num_status_iters = int(round(status_time / time_iter)) num_hist = int(round(time_cont / time_iter)) now = datetime.datetime.now() time_stamp = str(now.year) + '-' + str(now.month) + '-' + str( now.day) + '-' + str(now.hour) time_lst = [] err_lst = [0] * 3 o = 0 init_time = time()
def initialize_labjack(): device = u12.U12() return device
import u12 import sys from time import sleep from time import time d1=u12.U12(serialNumber=100039255) d1.eAnalogOut(analogOut0=0,analogOut1=5) burst_data=d1.rawAIBurst(NumberOfScans=128,SampleInterval=int(6000000.0/(128*4)))['Channel2'] pulse_hist=[None]*len(burst_data) for index,voltage in enumerate(burst_data): if voltage > 4: pulse_hist[index]=1 else: pulse_hist[index]=0 pulse_num=0 if pulse_hist[0] == 1: pulse_num+=1 for index,x in enumerate(pulse_hist): if index < len(pulse_hist)-1: if x == 0: if pulse_hist[index+1] == 1: pulse_num+=1 print(len(burst_data)) frequency=pulse_num Q=(frequency+5)/8.1 print('Flow rate is '+str(Q)+' L/min') d1.eAnalogOut(analogOut0=0,analogOut1=0)
import u12 from time import sleep from time import time from scipy.integrate import simps import datetime import csv import numpy as np import sys sys.path.insert(0, '/home/egs/UHV-chamber-controls/funcs') from funcs import PID d2 = u12.U12(serialNumber=100035035) #d1=u12.U12(serialNumber=100054654) d1 = d2 time_iter = 0.3 time_tot = 10000 time_cont = 2 status_time = 20 num_iters = int(round(time_tot / time_iter)) num_status_iters = int(round(status_time / time_iter)) num_hist = int(round(time_cont / time_iter)) now = datetime.datetime.now() time_stamp = str(now.year) + '-' + str(now.month) + '-' + str( now.day) + '-' + str(now.hour) time_lst = [] err_lst = [0] * 3
import time import u12 # A couple of random variables used throughout output = None wrong = "Something went wrong! " chn = False out = False inp = False dig = False ana = False # Initialize the u12 function library model try: device = u12.U12() except Exception as eRR: print eRR sys.exit() # This whole function is legacy code. # It will keep the application running in the terminal. def loop(): # Usage documentation def usage(): print "LabJuice - Control Application for LabJack U12 Acquisition Board" print print "Usage:" print "digital [channel] [in/out=V] -- Reads, or sets, the digital input and output." print " Channel: 0-3 for IO"
def __init__(self): self.conveyor = u12.U12()
to the buffer until it has been emptied. Analog input resolution 12 bit, +/- 10V Analog output resolution 10 bit +/- the supply voltage (which can have an error as large as 5%, so monitor the supply voltage with an analog input channel) Analog outputs have maximum update rate of 50 Hz https://labjack.com/support/datasheets/u12/hardware-description/ao0-ao1 @author: Emma Cating-Subramanian """ import time import ctypes as c import u12 from matplotlib import pyplot as plt labjack = u12.U12() # automatically opens the U6 numChannels = 2 resolutionIndex = 1 gain = 1 # Range = +/- 10 V. This corresponds to the output of the lockin. sampleRate = 10 # units of samples/second. https://labjack.com/support/datasheets/u6/operation/stream-mode """ I'm starting this by doing all the timing in Windows rather than on the DAQ since the LabJack doesn't have very good timing anyway. """ scanRate = sampleRate / numChannels assert (sampleRate <= 50E3), "LabJack U12 problem: sample rate too high for device!"