def trialEndSignal(d): # end trialOnsetSignal try: d.getFeedback(u3.DAC8(Dac=0, Value=49)) except: print "LabJack not connected" pass
def stopBlockSignal(d): # step voltage down, signaling end of time block try: d.getFeedback(u3.DAC8(Dac=0, Value=0)) except: print "LabJack not connected" pass
def startBlockSignal(d): # step voltage up to 1 volt, signaling beginning of time block # Stays at 1 volt for duration of block try: d.getFeedback(u3.DAC8(Dac=0, Value=49)) except: print "LabJack not connected" pass
def trialOnsetSignal(d): # signal onset of individual trials # Brief step up to 2 volts try: d.getFeedback(u3.DAC8(Dac=0, Value=149)) #d.getFeedback(u3.DAC8(Dac = 0, Value = 49)) except: print "LabJack not connected" pass
def AnalogOutputOneGiveVoltagePin(Pin=None, Voltage=None, Bits=None): ''' Desc: Sets voltage on a particular pin with particular property to the configured level. All pin, volatge and resolution are set from the keyboard. Ex: >>> LJU3HV.AnalogOutput(Pin=1, Voltage=1.57, Bits=8) The voltage on DAC1 is set to 1.57 V ''' if Pin is None: print 'No pin is given' else: pass if Voltage is not None: #voltage scale validation if Voltage > 5: print 'The proposed voltage on pin DAC %d is greater than 5 V\nThe voltage was set to 5' % ( Pin) Voltage = 5 else: pass if Voltage < 0: print 'The proposed voltage on pin DAC %d is less than 0 V\nThe voltage was set to 0' % ( Pin) Voltage = 0 else: pass VoltageLevel = Voltage if Bits == 16: d.getFeedback( u3.DAC16(Dac=Pin, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=Pin, is16Bits=True))) elif Bits == 8: d.getFeedback( u3.DAC8(Dac=Pin, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=Pin, is16Bits=False))) else: print 'The number of bits should be either 8 or 16' else: print('Please set some value')
def set_voltage(self, voltage, DAC=0, is16bits=True): setbits = self.u.voltageToDACBits(voltage, is16Bits=is16bits) if is16bits: self.u.getFeedback(u3.DAC16(Dac=DAC, Value=setbits)) binary = bin(setbits)[2:].zfill(16) actualV = int(binary[:10], 2) / (2**10) * (4.95 - 0.04) + 0.04 # print(actualV) return actualV else: self.u.getFeedback(u3.DAC8(Dac=DAC, Value=setbits)) binary = bin(setbits)[2:].zfill(8) actualV = int(binary[:8], 2) / (2**8) * (4.95 - 0.04) + 0.04 # print(actualV) return actualV
def AnalogOutputOneGiveVoltagePin8bits(Pin=None, Voltage=None): ''' Desc: Sets voltage on a particular pin with particular property to the configured level. All pin and voltage are set from the keyboard. The resolution is 8 bits. Ex: >>> LJU3HV.AnalogOutput(Pin=0, Voltage=2.06) The voltage on DAC0 is set to 2.06 V ''' if Pin is None: print 'No pin is given' else: pass if Voltage is not None: #voltage scale validation if Voltage > 5: print 'The proposed voltage on pin DAC %d is greater than 5 V\nThe voltage was set to 5' % ( Pin) Voltage = 5 else: pass if Voltage < 0: print 'The proposed voltage on pin DAC %d is less than 0 V\nThe voltage was set to 0' % ( Pin) Voltage = 0 else: pass VoltageLevel = Voltage d.getFeedback( u3.DAC8(Dac=Pin, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=Pin, is16Bits=False))) else: print('Please set some value')
def AnalogOutputOneGiveVoltageProperty(ConfigList=[], PropertyChanged=None, Voltage=None): ''' Desc: Sets voltage on a particular pin with particular property to the configured level. The pin is identified with the property given in the configuration file, while the voltage is set from the keyboard. Ex: >>> LJU3HV.AnalogOutput(ConfigList=LJU3HV.ReadConfiguration(), PropertyChanged=FirstValve, Voltage=2.50) """ the following element of LJU3HV.ReadConfiguration() is considered: ['AO0', 'Property:FirstValve', 'Unit:', 'P_min:50', 'P_max:100', 'P_current:50', 'V_min[V]:1', 'V_max[V]:3', 'Bits:8', '|\n'])""" The voltage on DAC0 is set to 2.5 V ''' if PropertyChanged is not None: for b in range(0, 2): PropertyList = ConfigList[b + 8][1].split(':') if PropertyList[1] == PropertyChanged: #PropertyValue =float(PropertyValue) if Voltage is not None: VoltageLevel = Voltage #voltage scale validation if Voltage > 5: print 'The proposed voltage on pin DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break #The loop must be broken else: pass if Voltage < 0: print 'The proposed voltage on pin DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass if ConfigList[b + 8][8] == 'Bits:16': d.getFeedback( u3.DAC16(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=True))) elif ConfigList[b + 8][8] == 'Bits:8': d.getFeedback( u3.DAC8(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=False))) else: pass else: print('Please set some value') else: print('Not configured properly')
def AnalogOutputOnePercentage(ConfigList=[], PropertyChanged=None, PercentsVoltageAvailable=None): ''' Desc: Sets voltage on a particular pin with particular property to the configured level. The voltage is evaluated basing on P_max, P_min, V_max, V_min and PercentsVoltageAvailable- linear calculation. Ex: >>> LJU3HV.AnalogOutput(ConfigList=LJU3HV.ReadConfiguration(), PropertyChanged=FirstValve, PercentsVoltageAvailable=30) """ the following element of LJU3HV.ReadConfiguration() is considered: ['AO0', 'Property:FirstValve', 'Unit:', 'P_min:50', 'P_max:100', 'P_current:50', 'V_min[V]:1', 'V_max[V]:3', 'Bits:8', '|\n'])""" VoltageLevel= V_min+ PercentsVoltageAvailable/100*(VoltageMax-VoltageMin)=1+80/100*(3-1)*=2.6 The voltage on DAC0 is set to 2.6 V !!!Please note that DAC0 was chosen because of the folowing list elements : 'AO0', 'Property:FirstValve'!!! ''' if PropertyChanged is not None: for b in range(0, 2): PropertyList = ConfigList[b + 8][1].split(':') if PropertyList[1] == PropertyChanged: #PropertyValue =float(PropertyValue) if PercentsVoltageAvailable is not None: VoltageMinList = ConfigList[b + 8][6].split(':') VoltageMin = float(VoltageMinList[1]) VoltageMaxList = ConfigList[b + 8][7].split(':') VoltageMax = float(VoltageMaxList[1]) #voltage scale validation if VoltageMax > 5: print 'The proposed maximal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break #The loop must be broken else: pass if VoltageMax < 0: print 'The proposed maximal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin > 5: print 'The proposed minimal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin < 0: print 'The proposed minimal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass VoltageLevel = VoltageMin + float( PercentsVoltageAvailable) / 100 * (VoltageMax - VoltageMin) if ConfigList[b + 8][8] == 'Bits:16': d.getFeedback( u3.DAC16(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=True))) elif ConfigList[b + 8][8] == 'Bits:8': d.getFeedback( u3.DAC8(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=False))) else: pass else: print('Please set some value') else: print('Not configured properly')
def AnalogOutputOneValue(ConfigList=[], PropertyChanged=None, PropertyValue=None): ''' Desc: Sets voltage on a particular pin with particular property to the configured level. The voltage is evaluated basing on PropertyValue, P_max, P_min, V_max, V_min - linear calculation. Ex: >>> LJU3HV.AnalogOutputOneValue(LJU3HV.ReadConfiguration(), PropertyChanged=FirstValve, PropertyValue=80) """ the following element of LJU3HV.ReadConfiguration() is considered: ['AO0', 'Property:FirstValve', 'Unit:', 'P_min:50', 'P_max:100', 'P_current:50', 'V_min[V]:0', 'V_max[V]:5', 'Bits:8', '|\n'])""" VoltageLevel= V_min+ (PropertyValue-P_min)/(P_max-P_min)*(V_max-V_min)=0+(80-50)/(100-50)*(5-0)=3.0 The voltage on DAC0 is set to 3.0 V !!!Please note that DAC0 was chosen because of the folowing list elements : 'AO0', 'Property:FirstValve' and that the value of property is given by the user, not read from the file!!!. ''' if PropertyChanged is not None: for b in range(0, 2): PropertyList = ConfigList[b + 8][1].split(':') if PropertyList[1] == PropertyChanged: #PropertyValue =float(PropertyValue) if PropertyValue is not None: P_minList = ConfigList[b + 8][3].split( ':') #trick with splitting P_min = float(P_minList[1]) P_maxList = ConfigList[b + 8][4].split( ':') #trick with splitting P_max = float(P_maxList[1]) VoltageMinList = ConfigList[b + 8][6].split(':') VoltageMin = float(VoltageMinList[1]) VoltageMaxList = ConfigList[b + 8][7].split(':') VoltageMax = float(VoltageMaxList[1]) #voltage scale validation if VoltageMax > 5: print 'The proposed maximal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break #The loop must be broken else: pass if VoltageMax < 0: print 'The proposed maximal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin > 5: print 'The proposed minimal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin < 0: print 'The proposed minimal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass VoltageLevel = VoltageMin + (PropertyValue - P_min) / ( P_max - P_min) * (VoltageMax - VoltageMin) print VoltageLevel #checking if P is within the range, if not the value must be reassigned if PropertyValue > P_max: print 'The given value corresponding to DAC %d is greater than the maximal one\nThe voltage was set to Vmax' % ( b) VoltageLevel = VoltageMax else: pass if PropertyValue < P_min: print 'The set value corresponding to DAC %d is smaller than the minimal one\nThe voltage was set to Vmin' % ( b) VoltageLevel = VoltageMin else: pass if ConfigList[b + 8][8] == 'Bits:16': d.getFeedback( u3.DAC16(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=True))) elif ConfigList[b + 8][8] == 'Bits:8': d.getFeedback( u3.DAC8(Dac=b, Value=d.voltageToDACBits( volts=VoltageLevel, dacNumber=b, is16Bits=False))) else: pass else: print('Please set some value') else: print('Not configured properly')
def AnalogOutput(ConfigList=[]): ''' Desc: Sets voltage on DAC0 and DAC1 as configured - the voltage is evaluated basing on P_current, P_max, P_min, V_max, V_min -> linear calculation. Ex: >>> LJU3HV.AnalogOutput(ConfigList=LJU3HV.ReadConfiguration()) """ where LJU3HV.ReadConfiguration()[8]==['AO0', 'Property:Valve', 'Unit:', 'P_min:0', 'P_max:100', 'P_current:50', 'V_min[V]:0', 'V_max[V]:5', 'Bits:8', '|\n'])""" VoltageLevel= V_min+ (P_current-P_min)/(P_max-P_min)*(V_max-V_min)=0+(50-0)/(100-0)*(5-0)2.5 The voltage on DAC0 is set to 2.5 V. ''' VoltageMinList = [] VoltageMaxList = [] P_minList = [] P_maxList = [] P_realList = [] for b in range(0, 2): P_minList.append(ConfigList[b + 8][3].split( ':')) #trick with splitting and the convertion to number P_min = float(P_minList[b][1]) P_maxList.append(ConfigList[b + 8][4].split(':')) P_max = float(P_maxList[b][1]) P_realList.append(ConfigList[b + 8][5].split(':')) P_real = float(P_realList[b][1]) VoltageMinList.append(ConfigList[b + 8][6].split(':')) VoltageMin = float(VoltageMinList[b][1]) VoltageMaxList.append(ConfigList[b + 8][7].split(':')) VoltageMax = float(VoltageMaxList[b][1]) #voltage scale validation if VoltageMax > 5: print 'The proposed maximal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break #The loop must be broken else: pass if VoltageMax < 0: print 'The proposed maximal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin > 5: print 'The proposed minimal voltage on DAC %d is greater than 5 V\nThe voltage cannot be set' % ( b) break else: pass if VoltageMin < 0: print 'The proposed minimal voltage on DAC %d is less than 0 V\nThe voltage cannot be set' % ( b) break else: pass VoltageLevel = VoltageMin + (P_real - P_min) / (P_max - P_min) * ( VoltageMax - VoltageMin) #checking whether P is within the range, if not the value must be reassigned if P_real > P_max: print 'The set value corresponding to DAC %d is greater than the maximal one\nThe voltage was set to Vmax' % ( b) VoltageLevel = VoltageMax else: pass if P_real < P_min: print 'The set value corresponding to DAC %d is smaller than the minimal one\nThe voltage was set to Vmin' % ( b) VoltageLevel = VoltageMin else: pass if ConfigList[b + 8][8] == 'Bits:16': #Because of the error if VoltageLevel == 0: d.getFeedback( u3.DAC8(Dac=b, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=b, is16Bits=False))) else: d.getFeedback( u3.DAC16(Dac=b, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=b, is16Bits=True))) elif ConfigList[b + 8][8] == 'Bits:8': d.getFeedback( u3.DAC8(Dac=b, Value=d.voltageToDACBits(volts=VoltageLevel, dacNumber=b, is16Bits=False))) else: pass