Debian Codegraph @

tests/instruments/velleman/test_velleman_k8090_with_device.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25
26 """
27 Test the instrument class for the Velleman F8090.
28
29 This tests the instrument class with the real device connected.
30 """
31
32 import pytest
33 from time import sleep
34
35 from pymeasure.adapters import SerialAdapter
36 from pymeasure.instruments.velleman import VellemanK8090, VellemanK8090Switches as Switches
37
38
39 @pytest.fixture()
40 def instrument(connected_device_address):
41 """Get instrument object.
42
43 Run like ``--device-address="ASRL1::INSTR"`` to use the visa adapter, and
44 like ``--device-address="COM1"`` to use the serial adapter.
45 """
46 if "ASRL" in connected_device_address:
47 return VellemanK8090(connected_device_address, timeout=500)
48 else:
49 adapter = SerialAdapter(
50 connected_device_address, baudrate=19200, timeout=0.5, read_termination=chr(0x0F)
51 )
52 return VellemanK8090(adapter)
53
54
55 def test_version(instrument):
56 ver = instrument.version
57
58 assert ver is not None and isinstance(ver, tuple)
59
60
61 def test_status(instrument):
62 last_on, curr_on, time_on = instrument.status
63
64 assert isinstance(curr_on, Switches)
65
66
67 def test_switch_on_off(instrument):
68 """Test switch on-off together.
69
70 This tests the physical switches and the status feedback.
71 You must also hear the real relays clicking, and verify the
72 LEDs 1 and 3 alone light up.
73 """
74 instrument.switch_off = Switches.ALL
75 sleep(0.5)
76
77 instrument.switch_on = Switches.CH1 | Switches.CH3
78 sleep(0.5)
79
80 _, curr_on_1, _ = instrument.status
81
82 instrument.switch_off = Switches.ALL
83 sleep(0.5)
84
85 _, curr_on_2, _ = instrument.status
86
87 assert curr_on_1 == Switches.CH1 | Switches.CH3
88 assert curr_on_2 == Switches.NONE
89
90 # Test another pointless off switch, to test a lack of confirmation
91 instrument.switch_off = Switches.ALL
92 sleep(0.5)