示例#1
0
    def get_continuous_measurement(self):

        reader = Reader(self._protocol)
        return reader.read([
            Mapping(PRESSURE_READING), Float,
            Mapping(PRESSURE_READING), Float
        ])
示例#2
0
    def start_continuous_measurement(self, mode=1):
        if mode not in [0, 1, 2]:
            raise ValueError('Wrong mode')

        cmd = Command(('COM,' + str(mode), [
            Mapping(PRESSURE_READING), Float,
            Mapping(PRESSURE_READING), Float
        ]))
        # we have to skip the next enquiry (so no <ENQ> will be send after the receiving <ACK>)
        # why?
        # after sending COM, the gauge will send continous data to us
        # as long as we do not interrupt him with another cmd, and since
        # <ENQ> is a cmd, we have to omit this.
        self._protocol.skipNextEnquiry()
        return self.query_command(cmd)
示例#3
0
 def __init__(self, transport, protocol):
     super(Trace, self).__init__(transport, protocol)
     self.points = Command(':TRAC:POIN?', ':TRAC:POIN',
                           Integer(min=2, max=1024))
     self.feed = Command(
         ':TRAC:FEED?', ':TRAC:FEED',
         Mapping({
             'sense': 'SENS',
             'calculate': 'CALC',
             None: 'NONE'
         }))
     self.feed_control = Command(':TRAC:FEED:CONT?', ':TRAC:FEED:CONT?',
                                 Mapping({
                                     'next': 'NEXT',
                                     'never': 'NEV'
                                 }))
示例#4
0
    def get_pressure_measurement(self, gauge=1):
        if (gauge == 1 or gauge == 2):
            cmd = Command(
                ('PR' + str(gauge), [Mapping(PRESSURE_READING), Float]))
            return self.query_command(cmd)

        raise ValueError('Wrong gauge')
示例#5
0
    def setUp(self):
        class TestObject(object):
            def __eq__(self, other):
                return type(self) == type(other)

        mapping = {'foobar': 'string', 1337: 'number', TestObject(): 'object'}
        self._values = tuple(mapping.iterkeys())
        self._serialized = tuple(mapping.itervalues())
        self._type = Mapping(mapping)
示例#6
0
    def __init__(self, transport, shims=None, channel=None):
        stb = {
            0: 'sweep mode active',
            1: 'standby mode active',
            2: 'quench condition present',
            3: 'power module failure',
            7: 'menu mode',
        }
        if not channel in (None, 1, 2):
            raise ValueError('Invalid channel. Must be either None, 1 or 2.')
        if channel:
            # if single channel mode is required, set the channel on every
            # command to avoid errors.
            protocol = slave.protocol.IEC60488(
                msg_prefix='CHAN {0};'.format(channel))
        else:
            protocol = slave.protocol.IEC60488()
        super(MPS4G, self).__init__(transport, protocol, stb=stb)
        if shims:
            if isinstance(shims, (str, bytes)):
                shims = [shims]
            for shim in list(shims):
                setattr(self, str(shim), Shim(transport, self._protocol, shim))

        if channel:
            # Channel is read only if channel is fixed
            self.channel = Command(('CHAN?', Set(1, 2)))
        else:
            self.channel = Command('CHAN?', 'CHAN', Set(1, 2))

        self.error = Command('ERROR?', 'ERROR', Boolean)
        self.current = Command('IMAG?', 'IMAG', UnitFloat)
        self.output_current = Command(('IOUT?', UnitFloat))
        # Custom format string to fix bug in firmware. The `;` must be appended
        self.lower_limit = Command('LLIM?', 'LLIM', UnitFloat(fmt='{0:.4f};'))
        self.mode = Command(('MODE?', String))
        self.name = Command('NAME?', 'NAME', String)
        self.switch_heater = Command('PSHTR?', 'PSHTR',
                                     Mapping({
                                         True: 'ON',
                                         False: 'OFF'
                                     }))
        for idx in range(0, 5):
            rng = Range(transport, self._protocol, idx)
            setattr(self, 'range{0}'.format(idx), rng)
        # Custom format string to fix bug in firmware. The `;` must be appended
        self.upper_limit = Command('ULIM?', 'ULIM', UnitFloat(fmt='{0:.4f};'))
        self.unit = Command('UNITS?', 'UNITS', Set('A', 'G'))
        self.voltage_limit = Command('VLIM?', 'VLIM', UnitFloat(min=0.,
                                                                max=10.))
        self.magnet_voltage = Command(('VMAG?', UnitFloat(min=-10., max=10.)))
        self.output_voltage = Command(('VMAG?', UnitFloat(min=-12.8,
                                                          max=12.8)))
        self.sweep_status = Command(('SWEEP?', String))
示例#7
0
 def __init__(self):
     super(MockInstrument, self).__init__(MockConnection())
     self.string = Command('STRING?', 'STRING', String)
     self.integer = Command('INTEGER?', 'INTEGER', Integer)
     self.float = Command('FLOAT?', 'FLOAT', Float)
     self.mapping = Command('MAPPING?', 'MAPPING',
                            Mapping({
                                'elite': 1337,
                                'notelite': 1338
                            }))
     self.read_only = Command(('STRING?', String))
     self.write_only = Command(write=('STRING', String))
     self.list = Command('LIST?', 'LIST', [Integer, Integer])
示例#8
0
 def __init__(self, connection, cfg, shim):
     super(Shim, self).__init__(connection, cfg)
     if not shim in SHIMS:
         raise ValueError('Invalid shim identifier, '
                          'must be one of {0}'.format(SHIMS))
     self._shim = shim = str(shim)
     self.limit = Command('SLIM?', 'SLIM', Float(min=-30., max=30.))
     state = {
         True: '{0} Enabled'.format(shim),
         False: '{0} Disabled'.format(shim)
     }
     self.status = Command(('SHIM?', Mapping(state)))
     self.current = Command('IMAG? {0}'.format(shim),
                            'IMAG {0}'.format(shim), UnitFloat)
示例#9
0
 def __init__(self, transport, protocol):
     super(Sense, self).__init__(transport, protocol)
     self.delta_mode = Command(':SENS:VOLT:DELT?', ':SENS:VOLT:DELT',
                               Boolean)
     self.function = Command(
         ':SENS:FUNC?', ':SENS:FUNC',
         Mapping({
             'voltage': '"VOLT:DC"',
             'temperature': '"TEMP"'
         }))
     self.nplc = Command(':SENS:VOLT:NPLC?', ':SENS:VOLT:NPLC',
                         Float(min=0.01, max=50))
     self.auto_range = Command(':SENS:VOLT:RANG:AUTO?', ':SENS:VOLT:RANG',
                               Boolean)
     self.range = Command(':SENS:VOLT:RANG?', ':SENS:VOLT:RANG',
                          Float(min=0, max=120))
示例#10
0
 def __init__(self, transport, protocol):
     super(Trigger, self).__init__(transport, protocol)
     self.auto_delay = Command(':TRIG:DEL:AUTO?', ':TRIG:DEL:AUTO', Boolean)
     # TODO count has a max value of 9999 but supports infinity as well.
     self.count = Command(':TRIG:COUN?', ':TRIG:COUN', Float(min=0.))
     self.delay = Command(':TRIG:DEL?', ':TRIG:DEL',
                          Float(min=0., max=999999.999))
     self.source = Command(
         ':TRIG:SOUR?', ':TRIG:SOUR',
         Mapping({
             'immediate': 'IMM',
             'timer': 'TIM',
             'manual': 'MAN',
             'bus': 'BUS',
             'external': 'EXT'
         }))
     self.timer = Command(':TRIG:TIM?', ':TRIG:TIM',
                          Float(min=0., max=999999.999))
示例#11
0
    def __init__(self, transport, protocol):
        assert isinstance(protocol, VAT590Protocol)

        self._transport = transport
        self._protocol = protocol

        self.PID_controller = Command('i:02', 's:02', String)

        self.interface_config = Command(
            'i:20',
            's:20',
            BitSequence([
                (1, Mapping(BAUD_RATE)),  # Baud rate
                (1, Mapping(PARITY_BIT)),  # Parity bit
                (1, Mapping(DATA_LENGTH)),  # Data length
                (1, Mapping(STOP_BITS)),  # Number of stop bits
                (1, Mapping({'Reserved': '0'})),
                (1, Mapping(DIGITAL_INPUT)),  # Digital input OPEN valve
                (1, Mapping(DIGITAL_INPUT)),  # Digital input CLOSED valve
                (1, Mapping({'Reserved': '0'}))
            ]))

        self._device_status = Command((
            'i:30',
            BitSequence([
                (1, Mapping(OPERATION_MODE)),  # Operation mode
                (1, Mapping(STATUS)),  # Status
                (1, Mapping(POWER_FAILURE_BATTERY)),  # Power failure option
                (1, Mapping(OPERATION))  # Operation
            ])))

        self._assembly = Command(
            'i:76',
            'i:76',
            BitSequence([
                (6, String()),  # Position
                (1, Mapping(PRESSURE_READING)),  # Pressure reading
                (7, String()),  # Pressure
                (1, Mapping(OPERATION_MODE)),  # Operation mode
                (1, Mapping(STATUS)),  # Status
                (1, Mapping(WARNING))  # Warning
            ]))

        self._warnings = Command((
            'i:51',
            BitSequence([
                (1, Mapping(SERVICE)),  # Service
                (1, Mapping(LEARN_DATA)),  # Learn data set
                (1, Mapping(POWER_FAILURE_BATTERY)),  # Power failure battery
                (1, Mapping(COMPRESSED_AIR_SUPPLY))  # Compressed air supply
            ])))

        self._valve_configuration = Command(
            'i:04',
            's:04',
            BitSequence([
                (1, Mapping(CLOSE_OPEN)),  # VALVE_POWER_UP
                (1, Mapping(CLOSE_OPEN)),  # VALVE_POWER_FAILURE
                (1, Mapping(NO_YES)),  # EXTERNAL_ISOLATION_VALVE_FUNCTION
                (1, Mapping(NO_YES)),  # CONTROL_STROKE_LIMITATION
                (1, Mapping(VALVE_FAILURE_POSITION)
                 ),  # NETWORK_FAILURE_END_POSITION
                (1, Mapping(VALVE_FAILURE_POSITION)),  # SLAVE_OFFLINE_POSITION
                (1, Mapping(SYNCHRONIZATION_START)),
                (1, Mapping(SYNCHRONIZATION_MODE)),
            ]))

        self._errors = Command(('i:50',
                                Mapping({
                                    'No errors': '00000000',
                                    'Sensor 1 signal converter failure.':
                                    '01000000',
                                    'Firmware memory failure.': '00010000'
                                })))

        self._range_config = Command(
            'i:21',
            's:21',
            BitSequence([
                (1, String()),  # Position range
                (7, String()),  # Pressure range
            ]))

        self._sensor_configuration = Command(
            'i:01', 's:01',
            BitSequence([(1, String()), (1, String()), (6, String())]))

        self._sensor_reading = Command('i:64', 'i:64', String)
        self._sensor_offset = Command('i:60', 'i:60', String)
        self._speed = Command('i:68', 'V:', String)
        self._pressure = Command('P:', 'S:', String)
        self._position = Command('A:', 'R:', String)
        self._identification = Command(('i:83', String))
        self._firmware_number = Command(('i:84', String))
        self._firmware_config = Command(('i:82', String))
        self._pressure_alignment = Command('c:6002', 'c:6002', String)
        self._zero = ('Z:', String)
        self._learn = ('L:0', String)

        # write only commands
        self._hold = ('H:', String)
        self._reset = ('c:82', String)
        self._close = ('C:', String)
        self._open = ('O:', String)
        self._access_mode = ('c:01', String)
示例#12
0
 def get_identification(self):
     cmd = Command(('TID', [
         Mapping(IDENTIFICATION_READING),
         Mapping(IDENTIFICATION_READING)
     ]))
     return self.query_command(cmd)
示例#13
0
    def set_pressure_unit(self, unit):
        if unit == 0 or unit == 1 or unit == 2:
            cmd = Command(('UNI,' + str(unit), Mapping(PRESSURE_UNIT_READING)))
            return self.query_command(cmd)

        raise ValueError('Wrong unit')
示例#14
0
 def reset(self):
     cmd = Command(('RES', Stream(Mapping(RESET_READING))))
     return self.query_command(cmd)
示例#15
0
 def get_error_status(self):
     cmd = Command(('ERR', Mapping(ERROR_READING)))
     return self.query_command(cmd)
示例#16
0
 def turn_off_first(self):
     cmd = Command(
         ('SEN,1,0',
          [Mapping(STATUS_GAUGE_READING),
           Mapping(STATUS_GAUGE_READING)]))
     return self.query_command(cmd)