def check_for_spark(daq, old_ctr_val): out = daq.getFeedback(u3.Counter(counter=0, Reset=False)) ctr_val = out[0] if (old_ctr_val < ctr_val): # spark occurred handle_spark(ctr_val) elif (old_ctr_val > ctr_val): # counter wrap occurred print "WARNING: looks like the counter wrapped" print "ctr_val, old_ctr_val = ", \ ctr_val, ", ", old_ctr_val print "but this is highly unlikely..." # no matter what happens, update the old_ctr_val # most of the time, ctr_val == old_ctr_val already... return ctr_val
def ResetCounter(Counter=None): ''' Desc: Performs a reset of the chosen counter !!! Before using it make sure than the counter is really enabled!!! Ex: >>> LJU3HV.ResetCounter(0) Conter 0 was reset ''' if Counter is not None: d.getFeedback(u3.Counter(counter=Counter, Reset=True)) else: print 'No counter specified'
def ReadCounter(Counter=None): ''' Desc: Reads the chosen counter !!! Before using it make sure than the counter is really enabled!!! Ex: >>> LJU3HV.ResetCounter(0) [] ''' CounterResult = None if Counter is not None: CounterResult = d.getFeedback(u3.Counter(counter=Counter, Reset=True)) else: print 'No counter specified' return CounterResult
dt = 100 dev.configIO(EnableCounter1=True, TimerCounterPinOffset=6) fps = 15.3 top = 10 bottom = 0 steps = 2 n_planes = int( (top - bottom) / steps) + 1 # total number of planes for each volume volumes_per_s = fps / n_planes # total number of volume acquisition per volume pulse_count = 0 with Opto(port='COM6') as etl: while True: etl.current(bottom) pulse_count = int(np.array(dev.getFeedback(u3.Counter(counter=1)))) #print('Reset',pulse_count) if pulse_count > 0: # for initial trigger (first TTL pulse/first plane of the volume) print('ETL', etl.current()) print('ini', pulse_count) #pulse_count -= 1 # reset it to zero so you can image the first plane, if it is one it will immediately increment the focal_plane old_pulse_count = 0 # to store the previous focal plane while pulse_count <= n_planes: if pulse_count > old_pulse_count: # for initial trigger (first TTL pulse/first plane of the volume) focal_plane = float(bottom + ((pulse_count - 1) * steps)) #time.sleep(0.064) print('Focal plane', focal_plane) etl.current(focal_plane) print('ETL', etl.current()) print('pulse', pulse_count) old_pulse_count += 1
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) def printw(msg):
#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 # ----------------------- ---------------------------------------------------------------------------------- ''' d = u3.U3() # Open LJU3
volumes_per_s = fps / n_planes # total number of volume acquisition per volume pulse_count = 0 i = 0 with Opto(port='COM6') as etl: etl.current(bottom) old_pulse_count = 0 # to store the previous focal plane while pulse_count <= n_planes: # for initial trigger (first TTL pulse/first plane of the volume) if pulse_count > old_pulse_count and old_pulse_count <= n_planes: # for initial trigger (first TTL pulse/first plane of the volume) i += 1 print(i) focal_plane = float(bottom + ((pulse_count - 1) * steps)) #time.sleep(0.064) print('Focal plane', focal_plane) etl.current(focal_plane) print('ETL', etl.current()) print('pulse', pulse_count) old_pulse_count += 1 pulse_count = int(np.array(dev.getFeedback(u3.Counter(counter=1)))) if pulse_count > old_pulse_count and old_pulse_count >= n_planes: print('2ndloop') time.sleep(0.64) etl.current(bottom) #print(pulse_count, old_pulse_count, n_planes) #print('DONE') #dev.configIO(EnableCounter1=False, TimerCounterPinOffset=6) #dev.configIO(EnableCounter1=True, TimerCounterPinOffset=6) #pulse_count = int(np.array(dev.getFeedback(u3.Counter(counter=1, Reset = True)))) #print(pulse_count)
def set_counter(self, reset=False): return self.u.getFeedback(u3.Counter(counter=1, Reset=reset))