roboglia.base.FileBus¶
-
class
FileBus
(name='FILEBUS', robot=None, port='', auto=True)[source]¶ Bases:
roboglia.base.bus.BaseBus
A bus that writes to a file with cache provided for testing purposes.
Writes by this class are send to a file stream and also buffered in a local memory. Reads use this buffer to return values or use the default values from the register defintion.
Same parameters as
BaseBus
.-
__init__
(name='FILEBUS', robot=None, port='', auto=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
is_open
¶ Returns
True
is the file is opened.
-
write
(reg, value)[source]¶ Updates the values in the FileBus.
The method will update the buffer with the value provided then will log the write on the file. A flush() is performed in case you want to inspect the content of the file while the robot is running.
File writing errors are intercepted and logged but no Exception is raised.
- Parameters
reg (BaseRegister or subclass) – The register object that needs to be written. Keep in mind that the register object also contains a reference to the device in the
device
attribute and it is up to the subclass to determine the way the information must be processed before providing it actual device.value (int) – The value needed to the written to the device.
-
read
(reg)[source]¶ Reads the value from the buffer of
FileBus
and logs it.The method intercepts the
raise
errors from writing to the physical file and converts them to errors in the log file so that the rest of the program can continue uninterrupted.The method will try to read from the buffer the value. If there is no value in the buffer it will be defaulted from the register’s default value. The method will log the read to the file and return the value.
- Parameters
reg (BaseRegister or subclass) – The register object that needs to be read. Keep in mind that the register object also contains a reference to the device in the
device
attribute and it is up to the subclass to determine the way the information must be processed before providing it to the caller.- Returns
Typically it would return an
int
that will have to be handled by the caller.- Return type
int
-
__repr__
()¶ Returns a representation of a BaseBus that includes the name of the class, the port and the status (open or closed).
-
property
auto_open
¶ Indicates if the bus should be opened by the robot when initializing.
-
property
name
¶ (read-only) the bus name.
-
property
port
¶ (read-only) the bus port.
-
property
robot
¶ The robot that owns the bus.
-