Debian Codegraph @

pymeasure/instruments/generic_types.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 logging
26 from warnings import warn
27
28 from .instrument import Instrument
29
30 log = logging.getLogger(__name__)
31 log.addHandler(logging.NullHandler())
32
33
34 class SCPIMixin:
35 """Mixin class for SCPI instruments with the default implementation of base SCPI commands."""
36
37 def __init__(self, *args, **kwargs):
38 kwargs.setdefault("includeSCPI", False) # in order not to trigger the deprecation warning
39 super().__init__(*args, **kwargs)
40
41 # SCPI default properties
42 complete = Instrument.measurement(
43 "*OPC?",
44 """Get the synchronization bit.
45
46 This property allows synchronization between a controller and a device. The Operation
47 Complete query places an ASCII character 1 into the device's Output Queue when all pending
48 selected device operations have been finished.
49 """,
50 cast=str,
51 )
52
53 status = Instrument.measurement(
54 "*STB?",
55 """Get the status byte and Master Summary Status bit.""",
56 cast=str,
57 )
58
59 options = Instrument.measurement(
60 "*OPT?",
61 """Get the device options installed.""",
62 cast=str,
63 )
64
65 id = Instrument.measurement(
66 "*IDN?",
67 """Get the identification of the instrument.""",
68 cast=str,
69 maxsplit=0,
70 )
71
72 next_error = Instrument.measurement(
73 "SYST:ERR?",
74 """Get the next error in the queue.
75 If you want to read and log all errors, use :meth:`check_errors` instead.
76 """,
77 )
78
79 # SCPI default methods
80 def clear(self):
81 """Clear the instrument status byte."""
82 self.write("*CLS")
83
84 def reset(self):
85 """Reset the instrument."""
86 self.write("*RST")
87
88 def check_errors(self):
89 """ Read all errors from the instrument.
90
91 :return: List of error entries.
92 """
93 errors = []
94 while True:
95 err = self.next_error
96 if int(err[0]) != 0:
97 log.error(f"{self.name}: {err[0]}, {err[1]}")
98 errors.append(err)
99 else:
100 break
101 return errors
102
103
104 class SCPIUnknownMixin(SCPIMixin):
105 """Mixin which adds SCPI commands to an instrument from which it is not known whether it
106 supports SCPI commands or not.
107 """
108
109 def __init__(self, *args, **kwargs):
110 warn("It is not known whether this device support SCPI commands or not. Please inform "
111 "the pymeasure maintainers if you know the answer.", FutureWarning)
112 super().__init__(*args, **kwargs)