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)
Beispiel #2
0
"""
Classfile for LabJack U6: Common Functions
"""

import LabJackPython
import time, threading, signal
from datetime import timedelta
import multiprocessing
import csv

u6_device = LabJackPython.openLabJack(LabJackPython.LJ_dtU6,
                                      LabJackPython.LJ_ctUSB,
                                      handleOnly=True)


class ei1050:
    def getHandle(self):
        return self.handle

    def configure(self, power_port, data_port, clock_port):
        try:
            LabJackPython.ePut(self.handle, LabJackPython.LJ_ioPUT_DIGITAL_BIT,
                               power_port, 1, 0)
            LabJackPython.ePut(self.handle, LabJackPython.LJ_ioPUT_CONFIG,
                               LabJackPython.LJ_chSHT_DATA_CHANNEL, data_port,
                               0)
            LabJackPython.ePut(self.handle, LabJackPython.LJ_ioPUT_CONFIG,
                               LabJackPython.LJ_chSHT_CLOCK_CHANNEL,
                               clock_port, 0)
            LabJackPython.GoOne(self.handle)
            return True
    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)