device.base.base module¶
- exception device.base.base.CommandError[source]¶
Bases:
DeviceErrorCommand execution resulted in error.
Raise this in your command method to signalize an error.
Raised automatically when a device signalizes error (via
_readerror()).
- exception device.base.base.CommandUserStop[source]¶
Bases:
DeviceErrorCommand has terminated because of
stop()call.Raised automatically when
stop()is called.
- exception device.base.base.DeviceError[source]¶
Bases:
ExceptionUniversal exception: all other exceptions intherit from it.
Note: All
DeviceErrorexceptions are internal in the sense, that they are all handled in_outside_call()wrapper and user does not come into contact with them directly. User gets to see only the messages in log.
- class device.base.base.HardwareBase(debug_spam=False, log_callback=None, logger='main', ignore_log_conflict=False)[source]¶
Bases:
objectBase class for communication with devices. Thread-safe methods.
Any method that communicates with the device either directly or by calling other methods is refered to as command and MUST be decorated with one of the following:
@base_command,@compound_command,@idle_command. Note: this does not apply to private abstract methods (e.g._connect(), …).@base_command- Base commands usually communicate with the device directly and implement elementary tasks (e.g. set output voltage). They cannot be terminated by user.@compound_command- Compound commands implement more complex tasks using a set of base commands and other compound commands. They can be terminated by callingstop(). Tip: Any method decorated as a @compound_command can be instead decorated as a @base_command to forbid termination by user.@idle_command- Idle commands implement low-priority tasks that are called periodically in background (e.g. read and plot current data from oscilloscope). They do not trigger error when they are blocked by the exectuion of another command. They ignorestop()calls.If you reimplement __init__, make sure to call super().__init__ in it.
It is REQUIRED to implement following methods in a subclass, see their docstrings for more info. To implement these methods both commands and direct communication with the device can be used. However, do not decorate any of these with command decorators. Also none of these methods will be interupted by a
stop()call:def _connect(self): # Must return True/False def _disconnect(self): def _is_ready(self): # Must return True/False
It is OPTIONAL to implement these. Notes from above apply here as well:
def _safestate(self): def _readerror(self): # Must return str or None def _defaultstate(self): def _clear_defaultstate(self):
- connect()[source]¶
Connect to the device. Note: When already connected, connection validity is not checked - to do that call
is_ready()instead.
- is_connected()[source]¶
Check if connected to a hardware device. Note: Connection validity is not checked - to do that call
is_ready()instead.
- is_ready()[source]¶
Check if connection to device was opened and if it is responding. If not, try to open a new connection.
- exception device.base.base.TransmissionError[source]¶
Bases:
DeviceErrorCommunication related errors.
Raise this in a communication check (if you implement any).
It is useful to implement comm. check in a universal command-sender method (like
raw_scpi()in VisaHardwareBase). If you do not have this option then do not bother. It mainly just helps to make helpful log messages.
- device.base.base.base_command(func)[source]¶
Method decorator for BASE command. - User can terminate: no - Error if device busy: yes
Usage: @base_command