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 deviceEnable(detection): lj.ePut (device.lngHandle, lj.LJ_ioPUT_ANALOG_ENABLE_BIT, 6, 0, 0) if detection is True: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 6, 1, 0, 0) elif detection is False: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 6, 0, 0, 0) lj.GoOne(device.lngHandle)
def deviceDirection(Direction): lj.ePut (device.lngHandle, lj.LJ_ioPUT_ANALOG_ENABLE_BIT, 5, 0, 0) if Direction is 1: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 5, 1, 0, 0) elif Direction is 0: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 5, 0, 0, 0) lj.GoOne(device.lngHandle)
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 set_value(self, channel_name, value): """ Sets the value of channel""" try: channel_name = self.channel_name(channel_name) except: raise if re.match('DAC', channel_name): try: if value is None: raise LabJackPython.AddRequest(self.handle, LabJackPython.LJ_ioPUT_DAC, self.channel_numbers[channel_name], value, 0, 0) LabJackPython.Go() exec('self.%s=float("%s")' % (channel_name, value)) except: # TODO catch the error for passing None Specifically pass elif re.match('FIO|EIO|CIO', channel_name): LabJackPython.AddRequest(self.handle, LabJackPython.LJ_ioPUT_DIGITAL_BIT, self.channel_numbers[channel_name], value, 0, 0) LabJackPython.Go() elif re.match('GND|SGND|VS|SPC', channel_name) or channel_name is None: pass else: raise LabJackInstrumentError('Invalid channel name for set_value.') self.current_state = self.get_state()
def devicePower(enable): lj.ePut (device.lngHandle, lj.LJ_ioPUT_ANALOG_ENABLE_BIT, 3, 0, 0) if enable is True: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 3, 1, 0, 0) if enable is False: deviceStartConifg() lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 3, 0, 0, 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 write(self, command, channel, value=0, optional_parameter=0, user_buffer=0): """ Writes a command to the LabJack device """ LabJackPython.AddRequest(self.handle, command, channel, value, optional_parameter, user_buffer) LabJackPython.Go()
def ask(self, command, channel, value=0, optional_parameter=0, user_buffer=0): """ Writes a command to the labjack and returns a value """ LabJackPython.AddRequest(self.handle, command, channel, value, optional_parameter, user_buffer) LabJackPython.Go() answer = LabJackPython.GetResult(self.handle, command, channel) return answer
def close(self): ''' Close connections to all cavities as well as connections to the LabJacks. This does not turn off any of the cavities. ''' # Close all quenches. try: self.close_quenches(self.quench_info.index) except: sys.stderr.write(tb.format_exc()) # Close both LabJacks try: self.quench_u3.close() print("U3 closed.") except: sys.stderr.write(tb.format_exc()) try: self.quench_u6.close() print("U6 closed.") except: sys.stderr.write(tb.format_exc()) # Free LabJacks from this kernel/thread try: LabJackPython.Close() print("All LabJacks freed for use in other threads.") except: sys.stderr.write(tb.format_exc())
def close(self): ''' Closes all connections to the USB and, if not inherited, to the LabJacks. In addition to closing the LabJacks, this will use the LabJackPython.Close() function to allow another Python kernel to open these LabJacks. ''' try: self.close_usb() except: sys.stderr.write(tb.format_exc()) if not self.u3_passed: try: self.u3_handle.close() print("U3 closed.") except: sys.stderr.write(tb.format_exc()) if not self.u6_passed: try: self.u6_handle.close() print("U6 closed.") except: sys.stderr.write(tb.format_exc()) if not (self.u3_passed or self.u6_passed): try: LabJackPython.Close() print("LabJacks freed for use in other kernels.") except: sys.stderr.write(tb.format_exc())
def deviceEmergency(emergency): lj.ePut (lj.lngHandle, lj.LJ_ioPUT_ANALOG_ENABLE_BIT, 4, 0, 0) if emergency is True: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 5, 0, 0, 0) lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 6, 0, 0, 0) elif emergency is False: lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 5, 1, 0, 0) lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_DIGITAL_BIT, 6, 1, 0, 0) lj.GoOne(device.lngHandle)
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 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 scanExistingDevices(self): """Check everything we know about. If something is gone, remove it.""" for serial, d in self.devices.items(): print "Checking %s for a vaild handle." % serial if not LabJackPython.isHandleValid(d.handle): # We lost this device self.deviceCountsByType[d.devType] -= 1 d.close() print "Deleting device", self.devices[serial] self.devices.pop(serial) if d.devType == 0x501: ex = self.exchangers[d.serialNumber][0] ex.shutdown(self.serviceCollection) self.exchangers.pop(d.serialNumber) else: self.serviceCollection.removeService(self.rawDeviceServices[serial]) self.rawDeviceServices.pop(serial) self.serviceCollection.removeService(self.modbusDeviceServices[serial]) self.modbusDeviceServices.pop(serial)
def off_and_close(self): ''' Turn off all SynthUSBs, change all DAC voltages to 0, and close all connections to everything. ''' # Turn off all power in all quenches. self.cavities_off(self.quench_info.index) # Close all quenches. self.close_quenches(self.quench_info.index) # Close both LabJacks. self.quench_u3.close() print("U3 closed.") self.quench_u6.close() print("U6 closed.") # Free LabJacks from this kernel/thread. LabJackPython.Close() print("All LabJacks freed for use in other threads.")
def scan(self): print "scanning" self.scanExistingDevices() devices = LabJackPython.openAllLabJacks() for device in devices: prodID = device.devType if prodID == 0x501: self._openSkymoteBridge(device) continue device._registerAtExitClose() self.deviceCountsByType[prodID] += 1 print "Opened d =", device self.devices[device.serialNumber] = device # Set up the Modbus port device.modbusPortNum = self.nextModbusPort modbusFactory = ModbusDeviceFactory(self, device.serialNumber) modbusService = internet.TCPServer(self.nextModbusPort, modbusFactory) modbusService.setServiceParent(self.serviceCollection) self.modbusDeviceServices[device.serialNumber] = modbusService # Set up C/R port port = self.nextCRPort device.crPortNum = port factory = RawDeviceFactory(self, device.serialNumber) service = internet.TCPServer(port, factory) service.setServiceParent(self.serviceCollection) self.rawDeviceServices[device.serialNumber] = service self.incrementPorts() return self.buildScanResponse()
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 read(self, command, channel): """ Reads the result of giving command to channel """ value = LabJackPython.GetResult(self.handle, command, channel) return value
def searchForDevices(self): self.u3Available = len(LabJackPython.listAll(LabJackU3LJTick.U3)) > 0
def deviceRamp(): lj.ePut (device.lngHandle, lj.LJ_ioPUT_ANALOG_ENABLE_BIT, 13, 1, 0) lj.AddRequest(device.lngHandle, lj.LJ_ioPUT_AIN_RANGE, 13, lj.LJ_rgBIP5V, 0, 0) lj.GoOne(device.lngHandle)
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, 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 __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 resetLabjackConfig(): lj.ePut(device.lngHandle, lj.LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0) def deviceDirection(Direction):
def close(self): if self.is_open: self.device.close() LabJackPython.Close() self.is_open = False
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)