def test_lakeshore475_control_slope_limit():
    """
    Get / set slope limit, unitful and not.
    """
    with expected_protocol(
            ik.lakeshore.Lakeshore475,
        [
            "CPARAM?",
            "UNIT?",
            "CPARAM?",
            "UNIT?",
            "UNIT?",
            "CPARAM 1.0,10.0,42.0,42.0",
            "CPARAM?",
            "UNIT?",
            "UNIT?",
            "CPARAM 1.0,10.0,42.0,42.0",
        ],
        [
            "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
            "2",  # teslas
            "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
            "2",  # teslas
            "2",
            "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
            "2",
            "2"
        ],
    ) as lsh:
        assert lsh.control_slope_limit == u.Quantity(100.0, u.V / u.min)
        lsh.control_slope_limit = u.Quantity(42000.0, u.mV / u.min)
        lsh.control_slope_limit = 42.0
Beispiel #2
0
def test_apt_mc_motion_timeout(init_kdc101):
    """Set and get motion timeout."""
    with expected_protocol(ik.thorlabs.APTMotorController, [init_kdc101[0]],
                           [init_kdc101[1]],
                           sep="") as apt:
        apt.channel[0].motion_timeout = u.Quantity(100, u.s)
        assert apt.channel[0].motion_timeout == u.Quantity(100, u.s)
Beispiel #3
0
def test_power():
    with expected_protocol(ik.phasematrix.PhaseMatrixFSW0020, [
            "0D.", "03{:04X}.".format(
                int(u.Quantity(10, u.dBm).to(u.cBm).magnitude))
    ], ["-064"]) as inst:
        assert inst.power == u.Quantity(-10, u.dBm)
        inst.power = u.Quantity(10, u.dBm)
def test_tc200_temperature_set():
    with expected_protocol(
            ik.thorlabs.TC200, ["tset?", "tmax?", "tset=40"],
        ["tset?", "30 C", "> tmax?", "250", "> tset=40", "> "],
            sep="\r") as tc:
        assert tc.temperature_set == u.Quantity(30.0, u.degC)
        tc.temperature_set = u.Quantity(40, u.degC)
def test_visacomm_timeout(visa_inst):
    """Set / Get timeout of VISA communicator."""
    comm = VisaCommunicator(visa_inst)
    comm.timeout = 3
    assert comm.timeout == u.Quantity(3, u.s)
    comm.timeout = u.Quantity(40000, u.ms)
    assert comm.timeout == u.Quantity(40, u.s)
def test_srsdg645_holdoff():
    """
    SRSDG645: Set / get hold off.
    """
    with expected_protocol(ik.srs.SRSDG645, ["HOLD?", "HOLD 0", "HOLD 0.01"],
                           ["+0.001001000000"]) as ddg:
        assert u.Quantity(1001, u.us) == ddg.holdoff
        ddg.holdoff = 0
        ddg.holdoff = u.Quantity(10, u.ms)  # unitful hold off
def test_srsdg645_burst_period():
    """
        SRSDG645: Checks getting/setting of enabling T0 output on first
        in burst mode.
        """
    with expected_protocol(ik.srs.SRSDG645, ["BURP?", "BURP 13", "BURP 0.1"],
                           ["100E-9"]) as ddg:
        unit_eq(ddg.burst_period, u.Quantity(100, "ns").to(u.sec))
        ddg.burst_period = u.Quantity(13, "s")
        ddg.burst_period = 0.1
def test_channel_power_getter():
    with expected_protocol(
            ik.holzworth.HS9000,
        [":ATTACH?", ":CH1:PWR?", ":CH1:PWR:MIN?", ":CH1:PWR:MAX?"],
        [":CH1:CH2:FOO", "0", "-100", "20"],
            sep="\n") as hs:
        channel = hs.channel[0]
        assert channel.power == u.Quantity(0, u.dBm)
        assert channel.power_min == u.Quantity(-100, u.dBm)
        assert channel.power_max == u.Quantity(20, u.dBm)
def test_srsdg645_burst_delay():
    """
        SRSDG645: Checks getting/setting of enabling T0 output on first
        in burst mode.
        """
    with expected_protocol(ik.srs.SRSDG645, ["BURD?", "BURD 42", "BURD 0.1"],
                           ["0"]) as ddg:
        unit_eq(ddg.burst_delay, u.Quantity(0, "s"))
        ddg.burst_delay = u.Quantity(42, "s")
        ddg.burst_delay = 0.1
def test_unitful_property_sendcmd_query(mock_inst):
    """Assert that unitful_property calls sendcmd, query of parent class."""
    # getter
    assert mock_inst.unitful_property == u.Quantity(42, u.K)
    mock_inst.spy_query.assert_called()
    # setter
    value = 13
    mock_inst.unitful_property = u.Quantity(value, u.K)
    assert mock_inst._sendcmd == f"42 {value:e}"
    mock_inst.spy_sendcmd.assert_called()
def test_srsdg645_trigger_rate():
    """
    SRSDG645: Set / get trigger rate.
    """
    with expected_protocol(ik.srs.SRSDG645,
                           ["TRAT?", "TRAT 10000", "TRAT 1000"],
                           ["+1000.000000"]) as ddg:
        assert ddg.trigger_rate == u.Quantity(1000, u.Hz)
        ddg.trigger_rate = 10000
        ddg.trigger_rate = u.Quantity(1000, u.Hz)  # unitful send
def test_yaml_quantity_tag():
    yaml_data = StringIO(u"""
a:
    b: !Q 37 tesla
    c: !Q 41.2 inches
    d: !Q 98
""")
    data = yaml.load(yaml_data, Loader=yaml.Loader)
    assert data['a']['b'] == u.Quantity(37, 'tesla')
    assert data['a']['c'] == u.Quantity(41.2, 'inches')
    assert data['a']['d'] == 98
def test_channel_offset(channel, val_read, val_unitless, val_millivolt):
    """Get / set offset."""
    val_read = u.Quantity(val_read, u.V)
    val_unitful = u.Quantity(val_millivolt, u.mV)
    with expected_protocol(ik.tektronix.TekAWG2000, [
            f"FG:CH{channel+1}:OFFS?", f"FG:CH{channel+1}:OFFS {val_unitless}",
            f"FG:CH{channel+1}:OFFS {val_unitful.to(u.V).magnitude}"
    ], [f"{val_read.magnitude}"]) as inst:
        assert inst.channel[channel].offset == val_read
        inst.channel[channel].offset = val_unitless
        inst.channel[channel].offset = val_unitful
def test_channel_frequency(channel, val_read, val_unitless, val_kilohertz):
    """Get / set offset."""
    val_read = u.Quantity(val_read, u.Hz)
    val_unitful = u.Quantity(val_kilohertz, u.kHz)
    with expected_protocol(ik.tektronix.TekAWG2000, [
            f"FG:FREQ?", f"FG:FREQ {val_unitless}HZ",
            f"FG:FREQ {val_unitful.to(u.Hz).magnitude}HZ"
    ], [f"{val_read.magnitude}"]) as inst:
        assert inst.channel[channel].frequency == val_read
        inst.channel[channel].frequency = val_unitless
        inst.channel[channel].frequency = val_unitful
def test_srsdg645_channel_delay():
    """
    SRSDG645: Get / set delay.
    """
    with expected_protocol(
            ik.srs.SRSDG645,
        ["DLAY?2", "DLAY 3,2,60", "DLAY 5,4,10"],
        ["0,42"],
    ) as ddg:
        ref, t = ddg.channel["A"].delay
        assert ref == ddg.Channels.T0
        assert abs((t - u.Quantity(42, "s")).magnitude) < 1e5
        ddg.channel["B"].delay = (ddg.channel["A"], u.Quantity(1, "minute"))
        ddg.channel["D"].delay = (ddg.channel["C"], 10)
def test_get_log_point_with_unit():
    """Get a log point and include a unit query."""
    channel = ch_names[0]
    unit = ik.srs.SRSCTC100._UNIT_NAMES[ch_units[0]]
    values = (13, 42)
    which = "first"
    values_out = (u.Quantity(float(values[0]),
                             u.ms), u.Quantity(float(values[1]), unit))
    with expected_protocol(ik.srs.SRSCTC100,
                           [ch_names_query, f"getLog.xy {channel}, {which}"],
                           [ch_names_str, f"{values[0]},{values[1]}"]) as inst:
        with inst._error_checking_disabled():
            assert (inst.channel[channel].get_log_point(
                which=which, units=unit) == values_out)
def test_lakeshore475_field_get_control_params():
    """
    Get field control parameters.
    """
    with expected_protocol(
            ik.lakeshore.Lakeshore475,
        ["CPARAM?", "UNIT?"],
        [
            "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
            "2"  # teslas
        ],
    ) as lsh:
        current_params = lsh.field_control_params
        assert current_params == (1.0, 10.0, u.Quantity(42.0, u.tesla / u.min),
                                  u.Quantity(100.0, u.volt / u.min))
Beispiel #18
0
def test_current():
    """Get / Set current of instrument."""

    # values to set for test
    value_unitless = 0.8
    value_unitful = u.Quantity(50, u.mA)

    with expected_protocol(
            ik.yokogawa.Yokogawa7651,
            [
                "F5;\nE;",  # set current mode
                f"SA{value_unitless};",
                "E;",  # trigger
                "F5;\nE;",  # set current mode
                f"SA{value_unitful.to(u.A).magnitude};",
                "E;"  # trigger
            ],
            [
            ]
    ) as yok:
        # query
        with pytest.raises(NotImplementedError) as exc_info:
            print(f"current is: {yok.current}")
        exc_msg = exc_info.value.args[0]
        assert exc_msg == "This instrument does not support querying the " \
                          "output current setting."

        # set first current, then current mode
        yok.current = value_unitless
        yok.current = value_unitful
Beispiel #19
0
    def available_scales(self):
        """Get available scales from connected device.

        :return: Scales currently available on device.
        :rtype: :class:`Blu.Scale`

        Example:
            >>> import instruments as ik
            >>> inst = ik.gentec_eo.Blu.open_serial('/dev/ttyACM0')
            >>> inst.available_scales
            [<Scale.max100milli: '22'>, <Scale.max300milli: '23'>,
            <Scale.max1: '24'>, <Scale.max3: '25'>, <Scale.max10: '26'>,
            <Scale.max30: '27'>, <Scale.max100: '28'>]
        """
        # set no terminator and a 1 second timeout
        _terminator = self.terminator
        self.terminator = ""
        _timeout = self.timeout
        self.timeout = u.Quantity(1, u.s)

        try:
            # get the response
            resp = self._no_ack_query("*DVS").split('\r\n')
        finally:
            # set back terminator and 3 second timeout
            self.terminator = _terminator
            self.timeout = _timeout

        # prepare return
        retlist = []  # init return list of enums
        for line in resp:
            if len(line) > 0:  # account for empty lines
                index = line[line.find("[") + 1:line.find("]")]
                retlist.append(self.Scale(index))
        return retlist
Beispiel #20
0
def test_channel_voltage():
    """Get / Set voltage of channel."""

    # values to set for test
    value_unitless = 5.
    value_unitful = u.Quantity(500, u.mV)

    with expected_protocol(
            ik.yokogawa.Yokogawa7651,
            [
                "F1;\nE;",  # set voltage mode
                f"SA{value_unitless};",
                "E;",  # trigger
                "F1;\nE;",  # set voltage mode
                f"SA{value_unitful.to(u.volt).magnitude};",
                "E;"  # trigger
            ],
            [
            ]
    ) as yok:
        # query
        with pytest.raises(NotImplementedError) as exc_info:
            print(f"Voltage is: {yok.channel[0].voltage}")
        exc_msg = exc_info.value.args[0]
        assert exc_msg == "This instrument does not support querying the " \
                          "output voltage setting."

        # set first current, then voltage mode
        yok.channel[0].voltage = value_unitless
        yok.channel[0].voltage = value_unitful
 def temperature_set(self, newval):
     # the set temperature is always in celsius
     newval = convert_temperature(newval, u.degC)
     if newval < u.Quantity(20.0, u.degC) or newval > self.max_temperature:
         raise ValueError("Temperature set is out of range.")
     out_query = "tset={}".format(newval.magnitude)
     self.sendcmd(out_query)
Beispiel #22
0
def test_keithley195_input_range(init, statusword, range):
    """Get / set input range.

    Set unitful and w/o units.
    """
    mode = ik.keithley.Keithley195.Mode(int(statusword.decode()[5]))
    index = ik.keithley.Keithley195.ValidRange[mode.name].value.index(range)
    # new statusword
    new_statusword = list(statusword.decode())
    new_statusword[6] = str(index + 1)
    new_statusword = "".join(new_statusword)
    # units
    units = ik.keithley.keithley195.UNITS2[mode]
    with expected_protocol(
            ik.keithley.Keithley195,
        [
            init,
            "U0DX",
            f"R{index + 1}DX",
            "U0DX",
            f"R{index + 1}DX",
            "U0DX",  # query
            "U0DX"
        ],
        [statusword, statusword, new_statusword, new_statusword],
            sep="\n") as mul:
        mul.input_range = range
        mul.input_range = u.Quantity(range, units)
        assert mul.input_range == range * units
Beispiel #23
0
def test_apt_mc_position_encoder(init_kdc101):
    """Get unitful position of encoder, in counts."""
    with expected_protocol(
            ik.thorlabs.APTMotorController,
        [
            init_kdc101[0],
            ThorLabsPacket(  # read position
                message_id=ThorLabsCommands.MOT_REQ_ENCCOUNTER,
                param1=0x01,
                param2=0x00,
                dest=0x50,
                source=0x01,
                data=None).pack()
        ],
        [
            init_kdc101[1],
            ThorLabsPacket(message_id=ThorLabsCommands.MOT_GET_ENCCOUNTER,
                           param1=None,
                           param2=None,
                           dest=0x50,
                           source=0x01,
                           data=struct.pack('<Hl', 0x01, -20000)).pack()
        ],
            sep="") as apt:
        assert apt.channel[0].position_encoder == u.Quantity(-20000, 'counts')
Beispiel #24
0
def test_apt_sgr_max_travel(init_ksg101):
    value = 10000
    with expected_protocol(
            ik.thorlabs.APTPiezoStage,
        [
            init_ksg101[0],
            ThorLabsPacket(  # read state
                message_id=ThorLabsCommands.PZ_REQ_MAXTRAVEL,
                param1=0x01,
                param2=0x00,
                dest=0x50,
                source=0x01,
                data=None).pack()
        ],
        [
            init_ksg101[1],
            ThorLabsPacket(message_id=ThorLabsCommands.PZ_GET_MAXTRAVEL,
                           param1=None,
                           param2=None,
                           dest=0x50,
                           source=0x01,
                           data=struct.pack('<HH', 0x01, value)).pack()
        ],
            sep="") as apt:
        assert apt.channel[0].max_travel == value * u.Quantity(100, 'nm')
def test_maui_time_div(init):
    """Get / Set time per division."""
    with expected_protocol(
            ik.teledyne.MAUI,
            [
                init,
                'TDIV?',
                'TDIV 0.001'
            ],
            [
                '1'
            ],
            sep="\n"
    ) as osc:
        assert osc.time_div == u.Quantity(1, u.s)
        osc.time_div = u.Quantity(1, u.ms)
Beispiel #26
0
def quantity_constructor(loader, node):
    """
    Constructs a `u.Quantity` instance from a PyYAML
    node tagged as ``!Q``.
    """
    # Follows the example of http://stackoverflow.com/a/43081967/267841.
    value = loader.construct_scalar(node)
    return u.Quantity(*split_unit_str(value))
Beispiel #27
0
        def std_dev(self):
            """
            Gets the standard deviation for the specified channel as determined
            by the statistics gathering.

            :type: `~pint.Quantity`
            """
            return u.Quantity(float(self._get('SD')), self.units)
Beispiel #28
0
        def average(self):
            """
            Gets the average measurement for the specified channel as
            determined by the statistics gathering.

            :type: `~pint.Quantity`
            """
            return u.Quantity(float(self._get('average')), self.units)
Beispiel #29
0
def test_lcc25_voltage2():
    with expected_protocol(ik.thorlabs.LCC25, [
            "volt2?",
            "volt2=10.0",
    ], ["volt2?", "20", ">volt2=10.0", ">"],
                           sep="\r") as lcc:
        unit_eq(lcc.voltage2, u.Quantity(20, "V"))
        lcc.voltage2 = 10.0
def test_channel_power_setter():
    with expected_protocol(ik.holzworth.HS9000, [
            ":ATTACH?", ":CH1:PWR:MIN?", ":CH1:PWR:MAX?",
            ":CH1:PWR {:e}".format(0)
    ], [":CH1:CH2:FOO", "-100", "20"],
                           sep="\n") as hs:
        channel = hs.channel[0]
        channel.power = u.Quantity(0, u.dBm)