def __init__(self, transport, protocol, timer=None): super(BaurDriver, self).__init__(transport, protocol) assert isinstance(protocol, BaurProtocol) if timer is None: timer = time self.timer = timer self.protocol = protocol # Commands: self.position = Command( # Command: def __init__(self, query=None, write=None, type_=None, protocol=None): 'mabs?', # query 'mabs', String ) self.status = Command(( # Command: def __init__(self, query=None, write=None, type_=None, protocol=None): 'STAT', # query BitSequence([ (1, String), # Service (8, String) # Learn data set #,(1, String) # Power failure battery ]) ))
def test_write_with_query_only_cmd(self): protocol = MockProtocol() transport = MockTransport() cmd = Command(('HEADER', Integer)) with pytest.raises(AttributeError) as excinfo: cmd.write(transport, protocol) assert str(excinfo.value) == 'Command is not writeable'
def test_simulation_with_query_and_writeable_cmd(self): protocol = MockProtocol() transport = SimulatedTransport() cmd = Command('HEADER?', 'HEADER', Integer) response = cmd.query(transport, protocol) assert isinstance(response, int) assert cmd._simulation_buffer == [Integer().dump(response)]
def test_query_with_write_only_cmd(self): protocol = MockProtocol() transport = MockTransport() cmd = Command(write='HEADER') with pytest.raises(AttributeError) as excinfo: cmd.query(transport, protocol) assert str(excinfo.value) == 'Command is not queryable'
def test_write(self): protocol = MockProtocol() transport = MockTransport() cmd = Command(write=('HEADER', [Integer, Integer])) cmd.write(transport, protocol, 1, 2) assert protocol.transport == transport assert protocol.header == 'HEADER' assert protocol.data == ('1', '2')
def __init__(self, transport, protocol): super(Output, self).__init__(transport, protocol) self.gain = Command('OUTP:GAIN?', 'OUTP:GAIN', Float(min=-100e6, max=100e6)) self.offset = Command('OUTP:OFFS?', 'OUTP:OFFS', Float(min=-1.2, max=1.2)) self.relative = Command('OUTP:REL?', 'OUTP:REL', Boolean) self.state = Command('OUTP:STAT?', 'OUTP:STAT', Boolean)
def __init__(self, transport, protocol, query, write, register): super(Status, self).__init__(transport, protocol) for k, v in register.items(): q = query + ' {0}'.format(int(k)) w = write + ' {0},'.format(int(k)) if write else None name = v.replace(' ', '_') setattr(self, name, Command(q, w, Boolean)) self.value = Command(query, write, Register(register))
def __init__(self, ppr=None, *args, **kw): super(ParallelPoll, self).__init__(*args, **kw) ppr = _construct_register(ppr, PARALLEL_POLL_REGISTER) # The first 8 bits represent the status byte. ppr.update(self._stb) self._ppr = ppr self.parallel_poll_enable = Command('*PRE?', 'PRE', Register(ppr)) self.individual_status = Command(('*IST?', Boolean))
def test_write_with_generator_type(self): protocol = MockProtocol() transport = MockTransport() cmd = Command(write=('HEADER', it.repeat(Integer()))) cmd.write(transport, protocol, 1, 2, 3) assert protocol.transport == transport assert protocol.header == 'HEADER' assert protocol.data == ('1', '2', '3')
def __init__(self, transport, protocol, id): super(Aux, self).__init__(transport, protocol) self.id = id = int(id) #: Queries the aux input voltages. self.input = Command(('OAUX? {0}'.format(id), Float)) #: Sets and queries the output voltage. self.output = Command('AUXV? {0}'.format(id), 'AUXV {0},'.format(id), Float(min=-10.5, max=10.5))
def test_query_with_generator_type(self): protocol = MockProtocol(response=['1', '2', '3']) transport = MockTransport() cmd = Command(query=('HEADER', it.repeat(Integer()))) response = cmd.query(transport, protocol) assert protocol.transport == transport assert protocol.header == 'HEADER' assert protocol.data == () assert response == [1, 2, 3]
def test_query_without_message_data_and_multi_data_response(self): protocol = MockProtocol(response=['1', '2']) transport = MockTransport() cmd = Command(query=('HEADER', [Integer, Integer])) response = cmd.query(transport, protocol) assert protocol.transport == transport assert protocol.header == 'HEADER' assert protocol.data == () assert response == [1, 2]
def __init__(self, transport, protocol, idx): super(Range, self).__init__(transport, protocol) self.idx = idx = int(idx) if not idx in range(0, 5): raise ValueError('Invalid range index.' ' Must be one of {0}'.format(range(0, 5))) self.limit = Command('RANGE? {0}'.format(idx), 'RANGE {0} '.format(idx), Float(fmt='{0:.4f}')) self.rate = Command('RATE? {0}'.format(idx), 'RATE {0}'.format(idx), Float(min=1e-4, max=100., fmt='{0:.4f}'))
def test_simulation_with_query_only_cmd(self): protocol = MockProtocol() transport = SimulatedTransport() cmd = Command(query=('HEADER', [Integer, Integer])) response = cmd.query(transport, protocol) assert len(response) == 2 for item in response: assert isinstance(item, int) # query only should not buffer simulated response with pytest.raises(AttributeError): cmd._simulation_buffer
def __init__(self, transport, protocol, idx): super(Trace, self).__init__(transport, protocol) self.idx = idx = int(idx) self.value = Command(('OUTR? {0}'.format(idx), Float)) quantities = Enum('1', 'x', 'y', 'r', 'theta', 'xn', 'yn', 'rn', 'Al1', 'Al2', 'Al3', 'Al4', 'F', 'x**2', 'y**2', 'r**2', 'theta**2', 'xn**2', 'yn**2', 'rn**2', 'Al1**2', 'Al2**2', 'Al3**2', 'Al4**2', 'F**2') self.definition = Command( 'TRCD? {0}'.format(idx), 'TRCD {0},'.format(idx), (quantities, quantities, quantities, Boolean))
def __init__(self, transport, protocol): super(GPIB, self).__init__(transport, protocol) self.address = Command( 'SYST:COMM:GPIB:ADDR?', 'SYST:COMM:GPIB:ADDR', Integer(min=0, max=30) ) self.external = Command( 'SYST:COMM:GPIB:ADDR:EXT?', 'SYST:COMM:GPIB:ADDR:EXT', Boolean )
def __init__(self, transport, protocol, idx): super(Output, self).__init__(transport, protocol) idx = int(idx) self.mode = Command('AUXM? {0}'.format(idx), 'AUXM {0},'.format(idx), Enum('fixed', 'log', 'linear')) self.voltage = Command('AUXV? {0}'.format(idx), 'AUXV {0},'.format(idx), Float(min=-10.5, max=10.5)) self.limits = Command( 'SAUX? {0}'.format(idx), 'SAUX {0},'.format(idx), (Float(min=1e-3, max=21), Float( min=1e-3, max=21), Float(min=-10.5, max=10.5)))
def __init__(self, transport, protocol): super(Heater, self).__init__(transport, protocol) self.manual_output = Command('MOUT?', 'MOUT', Float) self.output = Command(('HTR?', Float)) self.range = Command( 'HTRRNG?', 'HTRRNG', Enum('off', '31.6 uA', '100 uA', '316 uA', '1 mA', '3.16 mA', '10 mA', '31.6 mA', '100 mA') ) self.status = Command( ('HTRST?', Enum('no error', 'heater open error')) )
def __init__(self, transport, protocol, idx): super(Relay, self).__init__(transport, protocol) idx = int(idx) self.config = Command( 'RELAY? {0}'.format(idx), 'RELAY {0},'.format(idx), [ Enum('off', 'on', 'alarm', 'zone'), Enum('scan', *range(1, 17)), Enum('low', 'high', 'both') ] ) self.status = Command(('RELAYST? {0}'.format(idx), Boolean))
def __init__(self, transport): super(K2182, self).__init__(transport) self.initiate = Initiate(self._transport, self._protocol) self.output = Output(self._transport, self._protocol) self.sample_count = Command(':SAMP:COUN?', ':SAMP:COUN', Integer(min=1, max=1024)) self.sense = Sense(self._transport, self._protocol) self.system = System(self._transport, self._protocol) self.temperature = Command((':MEAS:TEMP?', Float)) self.trace = Trace(self._transport, self._protocol) self.triggering = Trigger(self._transport, self._protocol) self.unit = Unit(self._transport, self._protocol) self.voltage = Command((':MEAS:VOLT?', Float))
def __init__(self, transport, protocol, id): super(BridgeChannel, self).__init__(transport, protocol) self.idx = id self.config = Command('BRIDGE? {}'.format(id), 'BRIDGE {} '.format(id), [ Float(min=0.01, max=5000.), Float(min=0.001, max=1000.), Enum('AC', 'DC'), Enum('standart', 'fast', 'high res') ]) bit = 2 * (id + 1) self.current = Command(('GETDAT? {}'.format(2**bit), Float)) self.resistance = Command(('GETDAT? {}'.format(2**(bit + 1)), Float))
def __init__(self, transport, protocol, shim): super(Shim, self).__init__(transport, protocol) 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)
def __init__(self, transport, protocol, channel): super(Output, self).__init__(transport, protocol) if not channel in (1, 2): raise ValueError('Invalid Channel number. Valid are either 1 or 2') self.channel = channel mode = 'off', 'channel', 'manual', 'zone' mode = mode + ('still',) if channel == 2 else mode self.analog = Command('ANALOG? {0}'.format(channel), 'ANALOG {0},'.format(channel), [Enum('unipolar', 'bipolar'), Enum(*mode), Enum('kelvin', 'ohm', 'linear', start=1), Float, Float, Float]) self.value = Command(('AOUT? {0}'.format(channel), Float))
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')
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))
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' }))
def __init__(self, transport, protocol=None, esb=None, stb=None, *args, **kw): super(IEC60488, self).__init__(transport, protocol, *args, **kw) self._esb = esb = _construct_register(esb, EVENT_STATUS_BYTE) self._stb = stb = _construct_register(stb, STATUS_BYTE) self.event_status = Command(('*ESR?', Register(esb))) self.event_status_enable = Command('*ESE?', '*ESE', Register(esb)) self.status = Command(('*STB?', Register(stb))) self.operation_complete = Command(('*OPC?', Boolean)) self.identification = Command( ('*IDN?', [String, String, String, String]))
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))
def make_zone(i): """Helper function to create a zone command.""" type_ = [ Float, Float(min=0.001, max=1000.), Integer(min=0, max=10000), Integer(min=0, max=10000), Integer(min=0, max=100), Enum(*Heater.RANGE), Boolean, Boolean, Integer(min=-100, max=100),Integer(min=-100, max=100) ] return Command('ZONE? {0}'.format(i), 'ZONE {0},'.format(i), type_)
def __init__(self, transport, protocol, channel): super(Output, self).__init__(transport, protocol) if not channel in (1, 2): raise ValueError('Invalid Channel number. Valid are either 1 or 2') self.channel = channel self.analog = Command( 'ANALOG? {0}'.format(channel), 'ANALOG {0},'.format(channel), [ Boolean, Enum('off', 'input', 'manual', 'loop'), #INPUT, Enum('kelvin', 'celsius', 'sensor', 'linear', start=1), Float, Float, Float ]) self.value = Command(('AOUT? {0}'.format(channel), Float))
def __init__(self, transport, protocol, channels): super(Input, self).__init__(transport, protocol) # The ls370 channels start at 1 self._channels = tuple( InputChannel(transport, protocol, idx) for idx in range(1, channels + 1) ) self.scan = Command( 'SCAN?', 'SCAN', (Integer(min=0, max=len(self)), Boolean) )
def __init__(self, transport, protocol, location): super(Display, self).__init__(transport, protocol) location = int(location) self.config = Command( 'DISPLOC? {0}'.format(location), 'DISPLOC {0},'.format(location), [ Integer(min=0, max=16), Enum('kelvin', 'ohm', 'linear', 'min', 'max', start=1), Integer(min=4, max=6) ] )
def __init__(self, transport, protocol, idx): super(Input, self).__init__(transport, protocol) self.idx = idx = int(idx) self.average = Command( 'MEAS:AVER? {0}'.format(idx), 'MEAS:AVER {0},'.format(idx), Integer(min=1, max=250) ) self.polarity = Command( 'MEAS:POL? {0}'.format(idx), 'MEAS:POL {0},'.format(idx), Enum('unipolar', 'bipolar', start=1) ) # Due to a bug in the isc4807 firmware, a query returns 10.0001 instead # of 10. This leads to problems when a Set type is used as query and # write type. self.range = Command( ('MEAS:RANG? {0}'.format(idx), Integer), ('MEAS:RANG {0},'.format(idx), Set(5, 10)) ) self.voltage = Command(('MEAS:VOLT? {0}'.format(idx), Float))
def __init__(self, transport, protocol=None): if protocol is None: protocol = VAT641Protocol() self._transport = transport self._protocol = protocol #super(VAT590Driver, self)._init_(transport, protocol) self._mode = ('U:', String) self._close = ('C:', String) self._open = ('O:', String) self._hold = ('H:', String) self._zero_adjust = ('Z:', String) self._interlock = ('U:', String) self._speed = ('V:', String) self._software_version = Command('i:01', 'i:01', String) self._valve_position = Command('A:', 'R:', String) self._valve_is_open = Command('i:05', 'i:05', String)
def __init__(self, transport): super(ICS4807, self).__init__(transport) self.gpib = GPIB(self._transport, self._protocol) self.input = tuple( Input(self._transport, self._protocol, i) for i in range(1, 7) ) self.relay = tuple( Relay(self._transport, self._protocol, i) for i in range(1, 7) ) self.temperature = CommandSequence( self._transport, self._protocol, [Command((':MEAS:TEMP? {}'.format(i), Float)) for i in range(1, 5)] )
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)
def __init__(self, transport, protocol): super(Cursor, self).__init__(transport, protocol) self.seek_mode = Command('CSEK?', 'CSEK', Enum('max', 'min', 'mean')) self.width = Command('CWID?', 'CWID', Enum('off', 'narrow', 'wide', 'spot')) self.vertical_division = Command('CDIV?', 'CDIV', Enum(8, 10, None)) self.control_mode = Command('CLNK?', 'CLNK', Enum('linked', 'separate')) self.readout_mode = Command('CDSP?', 'CDSP', Enum('delay', 'bin', 'fsweep', 'time')) self.bin = Command('CBIN?', 'CBIN', Integer)
def __init__(self, transport, protocol, idx, length): super(Curve, self).__init__(transport, protocol) self.idx = idx = int(idx) self.header = Command( 'CRVHDR? {0}'.format(idx), 'CRVHDR {0},'.format(idx), [ String(max=15), String(max=10), Enum('Ohm/K', 'logOhm/K', start=3), Float(min=0.),Enum('negative', 'positive', start=1) ] ) if length > 0: self.__length = int(length) else: raise ValueError('length must be a positive integer > 0')
def test_write_without_data(self): protocol = MockProtocol() transport = MockTransport() cmd = Command(write='HEADER') cmd.write(transport, protocol)
def test_write_with_simulation(self): protocol = MockProtocol() transport = SimulatedTransport() cmd = Command(write=('HEADER', [Integer, Integer])) cmd.write(transport, protocol, 1, 2) assert cmd._simulation_buffer == ['1', '2']