Debian Codegraph @

tests/adapters/test_prologix.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 import pytest
26
27 from pymeasure.adapters import PrologixAdapter
28 from pymeasure.test import expected_protocol
29
30
31 init_comm = [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None)]
32
33
34 def test_init():
35 with expected_protocol(
36 PrologixAdapter,
37 init_comm,
38 ):
39 pass
40
41
42 def test_init_different_config():
43 with expected_protocol(
44 PrologixAdapter,
45 [("++auto 1", None), ("++eoi 0", None), ("++eos 0", None)],
46 auto=True, eoi=False, eos="\r\n",
47 ):
48 pass
49
50
51 @pytest.mark.parametrize("message, value", (("1", True), ("0", False)))
52 def test_auto(message, value):
53 with expected_protocol(
54 PrologixAdapter,
55 init_comm + [("++auto", message)],
56 ) as adapter:
57 assert adapter.auto is value
58
59
60 def test_gpib_read_timeout():
61 with expected_protocol(
62 PrologixAdapter,
63 init_comm + [
64 ("++read_tmo_ms 700", None),
65 ("++read_tmo_ms", 700)
66 ],
67 ) as adapter:
68 adapter.gpib_read_timeout = 700
69 assert adapter.gpib_read_timeout == 700
70
71
72 def test_write():
73 with expected_protocol(
74 PrologixAdapter,
75 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
76 ("something", None)],
77 ) as adapter:
78 adapter.write("something")
79
80
81 def test_write_address():
82 with expected_protocol(
83 PrologixAdapter,
84 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
85 ("++addr 5", None), ("something", None)],
86 address=5,
87 ) as adapter:
88 adapter.write("something")
89
90
91 def test_read():
92 with expected_protocol(
93 PrologixAdapter,
94 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
95 ("write", None), ("++read eoi", "response")],
96 ) as adapter:
97 adapter.write("write")
98 assert adapter.read() == "response"
99
100
101 def test_write_bytes():
102 with expected_protocol(
103 PrologixAdapter,
104 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
105 (b"something", None)],
106 ) as adapter:
107 adapter.write_bytes(b"something")
108
109
110 @pytest.mark.parametrize(
111 "test_input,expected", [
112 ([1, 2, 3], b'OUTP#13\x01\x02\x03\n'),
113 ([43, 27, 10, 13, 97, 98, 99], b'OUTP#17\x1b\x2b\x1b\x1b\x1b\x0a\x1b\x0dabc\n'),
114 ]
115 )
116 def test_write_binary_values(test_input, expected):
117 with expected_protocol(
118 PrologixAdapter,
119 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
120 (expected, None)]
121 ) as adapter:
122 adapter.write_binary_values("OUTP", test_input, datatype='B')
123
124
125 def test_wait_for_srq():
126 with expected_protocol(
127 PrologixAdapter,
128 [("++auto 0", None), ("++eoi 1", None), ("++eos 2", None),
129 ("++srq", None), ("++read eoi", "0"), ("++srq", None), ("++read eoi", "1")]
130 ) as adapter:
131 adapter.wait_for_srq()