pypdevsbbl.generic.io module¶
Set of PythonPDEVS I/O blocks for user interaction.
The classes in this file will allow for logging values and messages to files for analysis and tracing.
Execute this file to test the Sound block.
You should hear a melody being played on the piano.
If this is not the case, something is wrong with the
audio on your system. See the block itself for more
info.
Note
In order to obtain the syslog messages, a
syslog server needs to be setup. You can write
your own server
or you can install one on your system.
PySysLogQt
is a tiny, graphical server that was made by the author
for this specific purpose. It accepts both
RFC 5424-formatted messages as well as the default Python
format.
Warning
In order for the Logger block and all its
subclasses to work, the setLogger() function
needs to be called.
-
pypdevsbbl.generic.io.setLogger(loc, address=('localhost', 1024), loglevel=0, rfc5424=True)[source]¶ Sets the logger to a syslog logger that might follow RFC 5424.
Note
The
pypdevs.logger.setLogger()creates a logger that’s based on the standard implementation of theSysLogHandler. Alas, this handler does not follow the full syslog specification as described in RFC 5424 and therefore Python(P)DEVS doesn’t either. This function replacespypdevs.logger.setLogger()and provides the correct RFC.Parameters: - loc (any) – Location of the server, to prepend to every logged message.
- address (tuple) – The address of the syslog server in the form of
(ip-address, port). Defaults to
('localhost', 1024). - loglevel (numeric) – Minimal log level to support. All messages with a lower level will be discarded. Should be one from in the above list. Defaults to 0.
- rfc5424 (bool) – Whether or not to follow
RFC 5424as a logging format. Defaults toTrue. Note that this requires rfc5424-logging-handler to be installed.
-
class
pypdevsbbl.generic.io.Logger(name: str, level: str = 'info')[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSGeneric
syslog-logger.Before this class can be used,
setLogger()needs to be called.Parameters: - name (str) – The name of the block.
- level (str) – Logging level, in string format. This is a function that is called on the logger object.
Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Emergency(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs emergency messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Alert(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs alert messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Critical(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs critical messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Error(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs error messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Warn(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs warning messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Notice(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs notice messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Info(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs informational messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.Debug(name: str)[source]¶ Bases:
pypdevsbbl.generic.io.LoggerLogs debug messages.
Before this class can be used,
setLogger()needs to be called.Parameters: name (str) – The name of the block. Input Ports: input (str) – The message to be logged.
-
class
pypdevsbbl.generic.io.FileWriter(blockname: str, filename: str, binary: bool = False, append: bool = True)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSWrites data to a file.
Parameters: - blockname (str) – The name of the block.
- filename (str) – The name of the file to write to.
- binary (bool) – Whether or not to open the file in binary mode.
Defaults to
False. - append (bool) – Whether or not to append instead of overwriting.
Note that this requires the file to already exist.
Defaults to
True.
Input Ports: input (str/bytes) – When in binary mode, it expects a
bytes-object, otherwise astr. This is the data that needs to be written to the file.
-
class
pypdevsbbl.generic.io.FileReader(name: str, binary: bool = False)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSReads contents of a file.
Every time a filename arrives at the block, its contents will be outputted in the same time instance.
Parameters: - name (str) – The name of the block.
- binary (bool) – Whether or not to read the file in binary mode.
Defaults to
False.
State: contents (str) – The contents of the just-read file or
Noneif no file has been read.Input Ports: filename (str) – The name of the file to read.
Output Ports: contents (str/bytes) – The contents of the file.
-
class
pypdevsbbl.generic.io.Listener(name: str, dt=inf, fp=<function Listener.<lambda>>, *args)[source]¶ Bases:
pypdevs.DEVS.AtomicDEVSListens to an extrenal source.
The provided function is executed every
dttime and its return value is outputted on the polled port. Alternatively, every time a message arrives on the dt port, thedtvalue will change.Note
The block will poll at the beginning of the simulation.
Parameters: - dt (numeric) – The delay between messages. Cannot be negative
or zero. Defaults to
INFINITY. - fp (def) – The polling function to be executed. Takes at least the
current time as first input. When returning
None, theListenerwill not fire an output event. Defaults to a do nothing function:lambda x: None. - *args – Additional arguments used to call the function.
State: - dt (numeric) – The time between polls. Cannot be negative or zero.
- elapsed (numeric) – The currently elapsed time.
- value (any) – The return value.
Input Ports: dt (any) – A new
dtvalue.Output Ports: listen (any) – The polled result.
- dt (numeric) – The delay between messages. Cannot be negative
or zero. Defaults to