def start(self): """ Name:MainWindow.start() Desc:Starts reading values from EI1050 probe """ try: # Get device selection if len(LabJackPython.listAll(3)) > 0: self.device = u3.U3() elif len(LabJackPython.listAll(6)) > 0: self.device = u6.U6() else: self.device = ue9.UE9() self.serialDisplay.config(text=self.device.serialNumber) # Create and start the thread self.thread = ei1050.EI1050Reader(self.device, self.targetQueue) # Start scheduleing self.window.after(1000, self.updateLabels) self.thread.start() # Change button self.startButton.config(text="Stop", command=self.stop) except: showErrorWindow(sys.exc_info()[0], sys.exc_info()[1])
def start(self): """ Name:MainWindow.start() Desc:Starts reading values from EI1050 probe """ try: # Get device selection #if self.deviceSelection.get() == "U3": self.device = U3() #elif self.deviceSelection.get() == "U6": self.device = U6() #else: self.device = UE9() if len(LabJackPython.listAll(3)) > 0: self.device = U3() elif len(LabJackPython.listAll(6)) > 0: self.device = U6() else: self.device = UE9() self.serialDisplay.config(text=self.device.serialNumber) #if self.deviceSelection.get() == "U6" or self.deviceSelection.get() == "U3": self.device.setToFactoryDefaults() #if len(LabJackPython.listAll(3)) > 0: # print MainWindow.FIO_PIN_STATE # self.device.configU3(FIOAnalog = MainWindow.FIO_PIN_STATE) # Create and start the thread self.thread = EI1050Reader(self.device, self.targetQueue) # Start scheduleing self.window.after(1000,self.updateLabels) self.thread.start() # Change button self.startButton.config(text="Stop", command=self.stop) except: showErrorWindow(sys.exc_info()[0], sys.exc_info()[1])
def searchForDevices(self): """ Name: searchForDevices() Desc: Determines which devices are available """ self.u3Available = len(LabJackPython.listAll(LJTickDAC.U3)) > 0 self.u6Available = len(LabJackPython.listAll(LJTickDAC.U6)) > 0 self.ue9Available = len(LabJackPython.listAll(LJTickDAC.UE9)) > 0
def searchForDevices(self): """ Name: searchForDevices() Desc: Determines which devices are available """ self.u3Available = len(LabJackPython.listAll(LJTickDAC.U3)) > 0 self.u6Available = len(LabJackPython.listAll(LJTickDAC.U6)) > 0 self.ue9Available = len(LabJackPython.listAll(LJTickDAC.UE9)) > 0
def updateDeviceDict(self): if self.usbOverride: ljsocketAddress = None devs = list() devCount = LabJackPython.deviceCount(None) for serial, dev in self.deviceBySerial.items(): dev.close() self.deviceBySerial.pop(serial) self.deviceByName = dict() devsObj = LabJackPython.listAll(3) for dev in devsObj.values(): devs.append({"serial" : dev["serialNumber"], "prodId" : dev["devType"]}) devsObj = LabJackPython.listAll(6) for dev in devsObj.values(): devs.append({"serial" : dev["serialNumber"], "prodId" : dev["devType"]}) devsObj = LabJackPython.listAll(9) for dev in devsObj.values(): devs.append({"serial" : dev["serialNumber"], "prodId" : dev["devType"]}) devsObj = LabJackPython.listAll(0x501) for dev in devsObj.values(): devs.append({"serial" : dev["serialNumber"], "prodId" : dev["devType"]}) if DEBUG: print "usbOverride:",devs else: ljsocketAddress = "%s:%s" % (self.address, self.port) devs = LabJackPython.listAll(ljsocketAddress, LabJackPython.LJ_ctLJSOCKET) serials = list() for dev in devs: serials.append(str(dev['serial'])) if str(dev['serial']) in self.deviceBySerial: continue if dev['prodId'] == 3: if DEBUG: print "Adding new device with serial = %s" % (dev['serial']) try: d = u3.U3(LJSocket = ljsocketAddress, serial = dev['serial']) except Exception, e: raise Exception( "Error opening U3: %s" % e ) try: d.configU3() d.getCalibrationData() except Exception, e: raise Exception( "Error with configU3: %s" % e )
def findBridges(self): devs = [] ljsocketAddress = "localhost:6000" try: devs = LabJackPython.listAll(ljsocketAddress, 200) except: return {} for dev in devs: #print "Got dev: serial = %s, prodId = 0x%X" % (dev['serial'], dev['prodId']) if dev['prodId'] != 0x501: continue elif str(dev['serial']) in self.bridges: d = self.bridges[str(dev['serial'])] if d.numMotes() != len(d.motes): log("Number of motes changed. Placing all motes into rapid mode.") d.motes = d.listMotes() for mote in d.motes: t = PlaceMoteInRapidModeThread(mote) t.start() continue d = skymote.Bridge(LJSocket = ljsocketAddress, serial = dev['serial']) try: d.ethernetFirmwareVersion() except: d.ethernetFWVersion = "(No Ethernet)" d.nameCache = d.getName() d.readSerialNumber() d.usbFirmwareVersion() d.mainFirmwareVersion() d.productName = "SkyMote Bridge" d.meetsFirmwareRequirements = True d.spontaneousDataCache = dict() d.motes = d.listMotes() for mote in d.motes: t = PlaceMoteInRapidModeThread(mote) t.start() self.bridges["%s" % d.serialNumber] = d t = SpontaneousDataLoggingThread(d) t.start() self.loggingThreads["%s" % d.serialNumber] = t return self.bridges
def start(self): """ Name:main.start() Desc:Starts reading values from EI1050 probe """ try: # Get device selection if len(LabJackPython.listAll(3)) > 0: self.device = u3.U3() # print('Device serial number : '+str(self.device.serialNumber)) # Create and start the thread self.thread = ei1050.EI1050Reader(self.device, self.targetQueue) # Start scheduleing self.thread.start() except: showError(sys.exc_info()[0], sys.exc_info()[1])
def __init__(self, devType=None, encoderAttached=False): """ Name: DAC10.__init__(devType = None, encoderAttached = False) Args: devType, set to 3 to force use of U3, 6 for U6, 9 for UE9. encoderAttached, set to True if your motor has a quadrature encoder output and you want to use it. Note: This requires the use of the EIOs so a CB15 is required. Also, the U3 only has two timers and is therefore incapable of doing both the PWM to the DCA and Quadrature. Desc: Makes a new instance of the DCA10 class. Examples: To open the first found device, without an encoder: >>> import dca10 >>> d = dca10.DCA10() To open the first found U6, without an encoder: >>> import dca10 >>> d = dca10.DCA10(devType = 6) To open the first found UE9, with an encoder: >>> import dca10 >>> d = dca10.DCA10(devType = 6, encoderAttached = True) """ self.device = None self.encoderAttached = encoderAttached self.directionLine = None self.enableLine = None self.currentLine = None self.enableState = 1 self.directionState = 1 if devType is None: if len(LabJackPython.listAll(3)) != 0: self.device = u3.U3() elif len(LabJackPython.listAll(6)) != 0: self.device = u6.U6() elif len(LabJackPython.listAll(9)) != 0: self.device = ue9.UE9() else: raise NoDevicesConnectedException( "Couldn't find any connected devices. Please connect a LabJack and try again." ) elif devType == 3: self.device = u3.U3() elif devType == 6: self.device = u6.U6() elif devType == 9: self.device = ue9.UE9() else: raise InvalidConfigurationException("Invalid device type submitted. Got %s expected 3, 6, or 9." % devType) if self.device.devType == 3 and self.encoderAttached: raise InvalidConfigurationException("The U3 does not have enough timers to support an encoder.") if self.device.devType == 3: self.directionLine = 5 self.enableLine = 6 self.currentLine = 0 else: if self.encoderAttached: self.directionLine = 9 self.enableLine = 8 else: self.directionLine = 1 self.enableLine = 2 self.currentLine = 0 # Make sure all the pins are digital, and enable a timer. if self.device.devType == 3: self.device.writeRegister(50590, 1) if self.device.devType == 9: self.device.writeRegister(7000, 1) else: self.device.writeRegister(7000, 2) self.device.writeRegister(7002, 1) # Set the Timer for PWM and Duty Cycle of 0% if self.encoderAttached: self.device.writeRegister(50501, 3) self.device.writeRegister(7100, [8, 0, 8, 0, 0, 65535]) else: self.device.writeRegister(50500, 0) self.device.writeRegister(50501, 1) self.device.writeRegister(7100, [0, 65535]) # Set the direction and enable lines to output. # Don't have to do this because modbus will take care of direction. # self.device.writeRegister(6100 + self.enableLine, 1) # self.device.writeRegister(6100 + self.directionLine, 1) # Set the direction and enable lines high. self.device.writeRegister(6000 + self.enableLine, 1) self.device.writeRegister(6000 + self.directionLine, 1)
def searchForDevices(self): self.u3Available = len(LabJackPython.listAll(LabJackU3LJTick.U3)) > 0
def __init__(self,resource_name=None,**key_word_arguments): """ Intializes the LabJackInstrument Class, supports U3 all others are untested, but may work.""" # if the name is not given assume it is a U3 if resource_name is None: # if there are multiple ones connected choose the first connected_devices=LabJackPython.listAll(LabJackPython.LJ_dtU3) self.LabJack_info=connected_devices.values()[0] # now we can parse the possibilities: elif resource_name in [3,'U3','LJ_dtU3']: # if there are multiple ones connected choose the first connected_devices=LabJackPython.listAll(LabJackPython.LJ_dtU3) self.LabJack_info=connected_devices.values()[0] elif resource_name in [9,'UE9','LJ_dtUE9']: # if there are multiple ones connected choose the first connected_devices=LabJackPython.listAll(LabJackPython.LJ_dtUE9) self.LabJack_info=connected_devices.values()[0] elif resource_name in [6,'U6','LJ_dtU6']: # if there are multiple ones connected choose the first connected_devices=LabJackPython.listAll(LabJackPython.LJ_dtU6) self.LabJack_info=connected_devices.values()[0] else: try: for device_type in [LabJackPython.LJ_dtU3,LabJackPython.LJ_dtUE9, LabJackPython.LJ_dtU6]: if resource_name in LabJackPython.listAll(device_type).keys(): connected_devices=LabJackPython.listAll(LabJackPython.LJ_dtU6) self.LabJack_info=connected_devices[resource_name] break except: print 'Resource Name is Not valid Must be a Labjack type, or ' print ' a vaild serial number' raise LabJackInstrumentError('No Device Found') #self.wrapper=LabJackPython -- since labjack has a module not a single # class this does not make since, I will just call things directly from # the module self.LabJack_type=self.LabJack_info['devType'] self.serial=self.LabJack_info['serialNumber'] self.address=self.LabJack_info['localID'] self.instrument_type='LABJACK' self.LabJack_connection_type=LabJackPython.LJ_ctUSB self.handle=LabJackPython.openLabJack(self.LabJack_type, self.LabJack_connection_type,handleOnly =True) self.commands=[] # if the attribute does not have __ in the name and it has GET or PUT # then it is a command for attribute in dir(LabJackPython): if not re.match('__',attribute) and (re.search('GET',attribute) or re.search('PUT',attribute)) : self.commands.append(attribute) self.channel_configuration={} self.mode_list=['analog','digital','timer','counter'] self.DEFAULT_STATE_QUERY_DICTIONARY={} self.state_buffer=[] self.STATE_BUFFER_MAX_LENGTH=10 if self.LabJack_type == 3: self.channel_locations={1:'SGND',2:'SPC',3:'SGND',4:'VS',5:'FIO7', 6:'FIO6',7:'GND',8:'VS',9:'FIO5',10:'FIO4',11:'GND',12:'VS',13:'VS', 14:'GND',15:'DAC0',16:'DAC1',17:'VS',18:'GND',19:'AIN2',20:'AIN3', 21:'VS',22:'GND',23:'AIN0',24:'AIN1','DB15':{1:'VS',2:'CIO1',3:'CIO3',4:'EIO0', 5:'EIO2',6:'EIO4',7:'EIO6',8:'GND',9:'CIO0',10:'CIO2',11:'GND', 12:'EIO1',13:'EIO3',14:'EIO5',15:'EIO7'}} self.write(LabJackPython.LJ_ioPUT_DAC_ENABLE,1) self.configuration={} self.channel_numbers={} self.channel_names=self.channel_locations.values() self.channel_names.remove(self.channel_locations['DB15']) self.channel_names.extend(self.channel_locations['DB15'].values()) for channel_name in self.channel_names: if channel_name in ['GND','SGND','VS']: self.configuration[channel_name]=channel_name elif re.match('FIO|AIN|EIO|CIO|DAC',channel_name): match=re.match('\w\w\w(?P<number>\d)',channel_name) number=int(match.group('number')) if re.match('EIO',channel_name): number=number+8 elif re.match('CIO',channel_name): number=number+16 self.channel_numbers[channel_name]=number #self.configuration[channel_name]=self.get_configuration(channel_name) self.current_state=self.get_state() if METHOD_ALIASES: for command in alias(self): exec(command)
def __init__(self, devType=None, encoderAttached=False): """ Name: DAC10.__init__(devType = None, encoderAttached = False) Args: devType, set to 3 to force use of U3, 6 for U6, 9 for UE9. encoderAttached, set to True if your motor has a quadrature encoder output and you want to use it. Note: This requires the use of the EIOs so a CB15 is required. Also, the U3 only has two timers and is therefore incapable of doing both the PWM to the DCA and Quadrature. Desc: Makes a new instance of the DCA10 class. Examples: To open the first found device, without an encoder: >>> import dca10 >>> d = dca10.DCA10() To open the first found U6, without an encoder: >>> import dca10 >>> d = dca10.DCA10(devType = 6) To open the first found UE9, with an encoder: >>> import dca10 >>> d = dca10.DCA10(devType = 6, encoderAttached = True) """ self.device = None self.encoderAttached = encoderAttached self.directionLine = None self.enableLine = None self.currentLine = None self.enableState = 1 self.directionState = 1 if devType is None: if len(LabJackPython.listAll(3)) != 0: self.device = u3.U3() elif len(LabJackPython.listAll(6)) != 0: self.device = u6.U6() elif len(LabJackPython.listAll(9)) != 0: self.device = ue9.UE9() else: raise NoDevicesConnectedException( "Couldn't find any connected devices. Please connect a LabJack and try again." ) elif devType == 3: self.device = u3.U3() elif devType == 6: self.device = u6.U6() elif devType == 9: self.device = ue9.UE9() else: raise InvalidConfigurationException( "Invalid device type submitted. Got %s expected 3, 6, or 9." % devType) if self.device.devType == 3 and self.encoderAttached: raise InvalidConfigurationException( "The U3 does not have enough timers to support an encoder.") if self.device.devType == 3: self.directionLine = 5 self.enableLine = 6 self.currentLine = 0 else: if self.encoderAttached: self.directionLine = 9 self.enableLine = 8 else: self.directionLine = 1 self.enableLine = 2 self.currentLine = 0 # Make sure all the pins are digital, and enable a timer. if self.device.devType == 3: self.device.writeRegister(50590, 1) if self.device.devType == 9: self.device.writeRegister(7000, 1) else: self.device.writeRegister(7000, 2) self.device.writeRegister(7002, 1) # Set the Timer for PWM and Duty Cycle of 0% if self.encoderAttached: self.device.writeRegister(50501, 3) self.device.writeRegister(7100, [8, 0, 8, 0, 0, 65535]) else: self.device.writeRegister(50500, 0) self.device.writeRegister(50501, 1) self.device.writeRegister(7100, [0, 65535]) # Set the direction and enable lines to output. # Don't have to do this because modbus will take care of direction. #self.device.writeRegister(6100 + self.enableLine, 1) #self.device.writeRegister(6100 + self.directionLine, 1) # Set the direction and enable lines high. self.device.writeRegister(6000 + self.enableLine, 1) self.device.writeRegister(6000 + self.directionLine, 1)
def updateDeviceDict(self): try: if self.usbOverride: self.scanEvent.wait() self.scanEvent.clear() ljsocketAddress = None devs = list() devCount = LabJackPython.deviceCount(None) for serial, dev in self.devices.items(): dev.close() self.devices.pop(str(serial)) devsObj = LabJackPython.listAll(3) for dev in devsObj.values(): devs.append({"serial": dev["serialNumber"], "prodId": dev["devType"]}) devsObj = LabJackPython.listAll(6) for dev in devsObj.values(): devs.append({"serial": dev["serialNumber"], "prodId": dev["devType"]}) devsObj = LabJackPython.listAll(9) for dev in devsObj.values(): devs.append({"serial": dev["serialNumber"], "prodId": dev["devType"]}) print "usbOverride:", devs else: ljsocketAddress = "%s:%s" % (self.address, self.port) devs = LabJackPython.listAll(ljsocketAddress, LabJackPython.LJ_ctLJSOCKET) serials = list() for dev in devs: serials.append(str(dev["serial"])) if str(dev["serial"]) in self.devices: continue if dev["prodId"] == 3: print "Adding new device with serial = %s" % (dev["serial"]) try: d = u3.U3(LJSocket=ljsocketAddress, serial=dev["serial"]) except Exception, e: raise Exception("Error opening U3: %s" % e) try: d.configU3() d.getCalibrationData() d.meetsFirmwareRequirements = True if float(d.firmwareVersion) < U3_MIN_FIRMWARE_VERSION: d.meetsFirmwareRequirements = False except Exception, e: raise Exception("Error with configU3: %s" % e) try: # d.debug = True fioList, fioFeedbackCommands = self.makeU3FioList(d) d.fioList = fioList d.fioFeedbackCommands = fioFeedbackCommands self._addTimerModesToDevice(d, 2) except Exception, e: print "making u3 fio list: %s" % e raise Exception("making u3 fio list: %s" % e)
def __init__(self, resource_name=None, **key_word_arguments): """ Intializes the LabJackInstrument Class, supports U3 all others are untested, but may work.""" # if the name is not given assume it is a U3 if resource_name is None: # if there are multiple ones connected choose the first connected_devices = LabJackPython.listAll(LabJackPython.LJ_dtU3) self.LabJack_info = connected_devices.values()[0] # now we can parse the possibilities: elif resource_name in [3, 'U3', 'LJ_dtU3']: # if there are multiple ones connected choose the first connected_devices = LabJackPython.listAll(LabJackPython.LJ_dtU3) self.LabJack_info = connected_devices.values()[0] elif resource_name in [9, 'UE9', 'LJ_dtUE9']: # if there are multiple ones connected choose the first connected_devices = LabJackPython.listAll(LabJackPython.LJ_dtUE9) self.LabJack_info = connected_devices.values()[0] elif resource_name in [6, 'U6', 'LJ_dtU6']: # if there are multiple ones connected choose the first connected_devices = LabJackPython.listAll(LabJackPython.LJ_dtU6) self.LabJack_info = connected_devices.values()[0] else: try: for device_type in [ LabJackPython.LJ_dtU3, LabJackPython.LJ_dtUE9, LabJackPython.LJ_dtU6 ]: if resource_name in LabJackPython.listAll( device_type).keys(): connected_devices = LabJackPython.listAll( LabJackPython.LJ_dtU6) self.LabJack_info = connected_devices[resource_name] break except: print 'Resource Name is Not valid Must be a Labjack type, or ' print ' a vaild serial number' raise LabJackInstrumentError('No Device Found') #self.wrapper=LabJackPython -- since labjack has a module not a single # class this does not make since, I will just call things directly from # the module self.LabJack_type = self.LabJack_info['devType'] self.serial = self.LabJack_info['serialNumber'] self.address = self.LabJack_info['localID'] self.instrument_type = 'LABJACK' self.LabJack_connection_type = LabJackPython.LJ_ctUSB self.handle = LabJackPython.openLabJack(self.LabJack_type, self.LabJack_connection_type, handleOnly=True) self.commands = [] # if the attribute does not have __ in the name and it has GET or PUT # then it is a command for attribute in dir(LabJackPython): if not re.match('__', attribute) and (re.search( 'GET', attribute) or re.search('PUT', attribute)): self.commands.append(attribute) self.channel_configuration = {} self.mode_list = ['analog', 'digital', 'timer', 'counter'] self.DEFAULT_STATE_QUERY_DICTIONARY = {} self.state_buffer = [] self.STATE_BUFFER_MAX_LENGTH = 10 if self.LabJack_type == 3: self.channel_locations = { 1: 'SGND', 2: 'SPC', 3: 'SGND', 4: 'VS', 5: 'FIO7', 6: 'FIO6', 7: 'GND', 8: 'VS', 9: 'FIO5', 10: 'FIO4', 11: 'GND', 12: 'VS', 13: 'VS', 14: 'GND', 15: 'DAC0', 16: 'DAC1', 17: 'VS', 18: 'GND', 19: 'AIN2', 20: 'AIN3', 21: 'VS', 22: 'GND', 23: 'AIN0', 24: 'AIN1', 'DB15': { 1: 'VS', 2: 'CIO1', 3: 'CIO3', 4: 'EIO0', 5: 'EIO2', 6: 'EIO4', 7: 'EIO6', 8: 'GND', 9: 'CIO0', 10: 'CIO2', 11: 'GND', 12: 'EIO1', 13: 'EIO3', 14: 'EIO5', 15: 'EIO7' } } self.write(LabJackPython.LJ_ioPUT_DAC_ENABLE, 1) self.configuration = {} self.channel_numbers = {} self.channel_names = self.channel_locations.values() self.channel_names.remove(self.channel_locations['DB15']) self.channel_names.extend(self.channel_locations['DB15'].values()) for channel_name in self.channel_names: if channel_name in ['GND', 'SGND', 'VS']: self.configuration[channel_name] = channel_name elif re.match('FIO|AIN|EIO|CIO|DAC', channel_name): match = re.match('\w\w\w(?P<number>\d)', channel_name) number = int(match.group('number')) if re.match('EIO', channel_name): number = number + 8 elif re.match('CIO', channel_name): number = number + 16 self.channel_numbers[channel_name] = number #self.configuration[channel_name]=self.get_configuration(channel_name) self.current_state = self.get_state() if METHOD_ALIASES: for command in alias(self): exec(command)