def DigitalInputOnePin(Pin=None): ''' Desc: Sets on pin (FIO4-7) to be digital input. Returns 1 for digital high and 0 for digital low. Ex: >>> LJU3HV.DigitalInputOnePin(Pin=5) 1 Pin 5 is a digital inout connected to high signal ''' LogicState = None if Pin is not None: d.configIO(FIOAnalog=(255 - 2**Pin)) d.getFeedback(u3.BitDirWrite(Pin, 0)) if d.getFeedback(u3.BitStateRead(Pin)) == [1]: LogicState = 1 elif d.getFeedback(u3.BitStateRead(Pin)) == [0]: LogicState = 0 else: print 'Something went wrong - it is neither low nor high' else: print 'No pin specified' return LogicState
def read(self): """ read the bit pattern at a latch The state of NLOAD is normallly high. When checking status (or reading bits), toggle NLOAD low for at least 10 mS then high to store the information for reading. CS-BUS is the global enable. The normal state is high. Set to this to low when programming latches or reading data. Then set high when done. @return: byte """ self.logger.debug(" read: Reading latch %d", self.address) # Select the latch to be read if self.setLatchAddr(read=True): port_states = self.LJ.getFeedback(u3.PortStateRead()) self.logger.debug(" read: port states to check latch address: %s", port_states) latchAddr = port_states[0]['EIO'] #self.logger.debug(" read: LatchGroup address is %d",latchAddr) if latchAddr != self.address and latchAddr != (self.address | 4): self.logger.debug(" read: Requested latch %d but got %d", self.address, latchAddr) return None else: #self.logger.debug(" read: latch address set to %d", self.address) portStates = self.set_signals( {"SCK":1, "SDI":1,"NLOAD":1, "CS-BUS":1}) # Store the information to be read from this address self.set_signals({"NLOAD":0}) self.set_signals({"NLOAD":1}) # Enable serial data transfer self.set_signals({"CS-BUS":0}) MBDATA = 0 # Process from MS to LS bit for bit in range(7,-1,-1): try: state = self.LJ.getFeedback( u3.BitStateRead(IONumber = WBDCsignal["SDO"]))[0] #self.logger.debug(" read: bit %d state is %d for MBDATA = %d", # bit, state, MBDATA) except Exception as details: self.logger.error(" read: Data In failed at bit %d\n%s", bit, details) return None if state: MBDATA = Math.Bin.setbit(MBDATA, bit) if bit > 0: self.set_signals({"SCK":0}) self.set_signals({"SCK":1}) self.set_signals({"CS-BUS":1}) return MBDATA else: self.logger.error(" read: Setting latch address failed") return -1
def pulse_bit(self, bit): """ This drops the designated bit to state 0 for half a second To ensure that it is seen as a negative pulse, the bit is set high for one second if it was not already high. """ if self.getFeedback(u3.BitStateRead(IONumber=bit)) == 0: self.getFeedback(u3.BitStateWrite(IONumber=bit, State=1)) time.sleep(1) self.getFeedback(u3.BitStateWrite(IONumber=bit, State=0)) time.sleep(0.5) self.getFeedback(u3.BitStateWrite(IONumber=bit, State=1))
def DigitalInputOneProperty(ConfigList=[], Property=None): ''' Desc: Sets on pin (FIO4-7) to be digital input. Returns 1 for digital high and 0 for digital low. !!! Remember not to use this function for AIN0-3!!! Ex: >>> LJU3HV.DigitalInputOutputOnePin(ConfigList=LJU3HV.ReadConfiguration(), Property='AirTemp') """the following element of LJU3HV.ReadConfiguration() is considered: ['FIO5', 'Mode:AI', 'NegChan:SE', 'LongSettle:F', 'QuickSample:F', 'Property:AirTemp', 'Unit:C', 'P_min:0', 'P_max:10', 'V_min[V]:0', 'V_max[V]:2.44', 'Dig:L', '|\n']""" 1 ''' a = None Checker = None for b in range(4, 8): PropertyList = ConfigList[b][5].split(':') if Property == PropertyList[1]: d.configIO(FIOAnalog=(255 - 2**b)) Checker = PropertyList[1] d.getFeedback(u3.BitDirWrite(b, 0)) if d.getFeedback(u3.BitStateRead(b)) == [1]: State = 1 elif d.getFeedback(u3.BitStateRead(b)) == [0]: State = 0 else: print 'Something went wrong - it is neither low nor high' if Checker is None: print 'No property chosen at all' return State
def __init__(self): self.d = u3.U3() # Configure all ports as digital self.d.configIO(0) # Configure the output port as output, input as input self.d.getFeedback([ u3.BitDirWrite(self.INPUT_PORT, 0), u3.BitDirWrite(self.OUTPUT_PORT, 1) ]) # Store commands, for easy reference self.out_cmd = [ u3.BitStateWrite(self.OUTPUT_PORT, 1), u3.BitStateWrite(self.OUTPUT_PORT, 0) ] self.in_cmd = u3.BitStateRead(self.INPUT_PORT)
def getDigIOState(self, io_channel): '''Get the state of a Digital IO Channel ''' self.safeLJOpen() state_bool = self.lj.getFeedback( u3.BitStateRead(io_channel))[0] #GSet direction of digital output if state_bool == 0: state = 'low' elif state_bool == 1: state = 'high' else: print 'Returned unknown state' state = None self.lj.close() return state
def check_trigger(self): """" Simply returns the state of the pin as a boolean """ return bool(self.device.getFeedback(u3.BitStateRead(self.chan))[0])
EnableCounter0=True, EnableCounter1=True) print(config) NHVs = 4 NLVs = 1 NDINs = 1 NCounters = 2 IsLV = [False] * NHVs + [True] * NLVs # Sensors/Actuators AINs = [ u3.AIN(i, NegativeChannel=31, LongSettling=False, QuickSample=True) for i in range(NHVs + NLVs) ] DINs = [u3.BitStateRead(i) for i in range(NHVs + NLVs, NHVs + NLVs + NDINs)] Counters = [u3.Counter(i, Reset=True) for i in range(NCounters)] def RGB(rgb): # RGB LED connected to EIO7, EIO5, EIO3 if rgb < 8: rgb += 8 threeBits = bin(rgb)[-3:] ch = (15, 13, 11) return [u3.BitStateWrite(ch[i], int(threeBits[i])) for i in range(3)] #````````````````````````````Helper functions````````````````````````````````` def printi(msg): print('LLJ:INFO: ' + msg)
#myCentre.draw() myStim.draw() #leftEnd.draw() #rightEnd.draw() myWin.update() # for labjack # ----------------------- START SYNCHRONIZATION RECEIVE TTL w/ LAB JACK --------------------------------- d = u3.U3() # Open LJU3 d.getCalibrationData() #d.debug = True d.configIO(EnableCounter1=True, TimerCounterPinOffset=6) # set the counter to pin 4 #d.setDOState(ioNum=5, state=0) print 'READING..' print d.getFeedback(u3.BitStateRead(IONumber=6)) #print d.getFeedback(u3.BitStateRead(IONumber =4)) print d.getFeedback(u3.Counter(counter=1)) t0 = time.time() while True: trigger = int(np.array(d.getFeedback(u3.Counter(counter=1)))) # print(trigger) if trigger > 0: t1 = time.time() break print d.getFeedback(u3.Counter(counter=1)) print 'Total time' print t1 - t0 # ----------------------- ----------------------------------------------------------------------------------
def DigitalInputOutputAll(ConfigList=[]): ''' Desc: The function that sets FIO pins (4-7) to be either digital input or output. In the latter case both high (3.4 V)or low (0 V) can be specified in the configuration file. The function returns a list of states of all the aforementioned pins: 0 - digital input LOW, 1 - digital input HIGH and 2 - the particular pin is not digital input !!! Remember not to use this function for the pins AIN0-3!!! Ex: >>> LJU3HV.DigitalInputOutputAll(LJU3HV.ReadConfiguration ('C:\Users\Dom\Desktop)) """ FIO4 Mode:DI NegChan:SE LongSettle:F QuickSample:F Property:Temp4 Unit:C P_min:0 P_max:10 V_min[V]:0 V_max[V]:2.44 Dig:L | FIO5 Mode:AI NegChan:SE LongSettle:F QuickSample:F Property:out1 Unit:C P_min:0 P_max:10 V_min[V]:0 V_max[V]:2.44 Dig:L | FIO6 Mode:DO NegChan:SE LongSettle:F QuickSample:F Property:Temp6 Unit:C P_min:0 P_max:10 V_min[V]:0 V_max[V]:2.44 Dig:H | FIO7 Mode:DO NegChan:SE LongSettle:F QuickSample:F Property:Temp7 Unit:C P_min:0 P_max:10 V_min[V]:0 V_max[V]:2.44 Dig:H | """ [0,2,2,2] ''' fioAn = 255 DIResults = [2, 2, 2, 2] for b in range(4, 8): if ConfigList[b][1] != 'Mode:AI': fioAn -= 2**b d.configIO(FIOAnalog=fioAn) for b in range(4, 8): if ConfigList[b][1] == 'Mode:DI': d.getFeedback(u3.BitDirWrite(b, 0)) if d.getFeedback(u3.BitStateRead(b)) == [1]: DIResults[b - 4] = 1 elif d.getFeedback(u3.BitStateRead(b)) == [0]: DIResults[b - 4] = 0 else: pass # 2 given by the defaults means it is not digtal input elif ConfigList[b][1] == 'Mode:DO': print ConfigList[b][11] d.getFeedback(u3.BitDirWrite(b, 1)) if ConfigList[b][11] == 'Dig:L': d.getFeedback(u3.BitStateWrite(b, 0)) if ConfigList[b][11] == 'Dig:H': d.getFeedback(u3.BitStateWrite(b, 1)) return DIResults