navigate.model.devices.MonitoredSerial
- class navigate.model.devices.MonitoredSerial(*args, **kwargs)
Bases:
Serial
MonitoredSerial - Serial class that logs read/write events.
- __init__(*args, **kwargs)
Initialize comm port object. If a “port” is given, then the port will be opened immediately. Otherwise a Serial port object in closed state is returned.
Methods
__init__
(*args, **kwargs)Initialize comm port object.
applySettingsDict
(d)Apply stored settings from a dictionary returned from get_settings().
cancel_read
()cancel_write
()close
()Close port
fileno
()For easier use of the serial port instance with select.
flush
()Flush of file like objects.
flushInput
()flushOutput
()getCD
()getCTS
()getDSR
()getRI
()getSettingsDict
()Get current port settings as a dictionary.
inWaiting
()iread_until
(*args, **kwargs)Read lines, implemented as generator.
isOpen
()isatty
()Return whether this is an 'interactive' stream.
log_event
(payload, duration_ns)Log the read/write event with performance data.
DEPRECATED - has no use
open
()Open port with current settings.
read
([size])Read bytes from the serial port and log the event.
read_all
()Read all bytes currently available in the buffer of the OS.
read_until
([expected, size])Read until an expected sequence is found (' ' by default), the size is exceeded or until timeout occurs.
readable
()Return whether object was opened for reading.
readall
()Read until EOF, using multiple read() call.
readinto
(b)readline
([size])Read a line from the serial port and log the event.
readlines
([hint])Return a list of lines from the stream.
Clear input buffer, discarding all that is in the buffer.
Clear output buffer, aborting the current output and discarding all that is in the buffer.
Change stream position.
seekable
()Return whether object supports random access.
sendBreak
([duration])send_break
([duration])Send break condition.
setDTR
([value])setPort
(port)setRTS
([value])set_input_flow_control
([enable])Manually control flow - when software flow control is enabled.
set_low_latency_mode
(low_latency_settings)set_output_flow_control
([enable])Manually control flow of outgoing data - when hardware or software flow control is enabled.
tell
()Return current stream position.
Truncate file to size bytes.
writable
()Return whether object was opened for writing.
write
(data)Write data to the serial port and log the event.
writelines
(lines, /)Write a list of lines to stream.
Attributes
BAUDRATES
BAUDRATE_CONSTANTS
BYTESIZES
PARITIES
STOPBITS
Get the current baud rate setting.
break_condition
Get the current byte size setting.
Carrier Detect
closed
Clear To Send
Data Set Ready
Get the current DSR/DTR flow control setting.
dtr
Get the current exclusive access setting.
Return the number of bytes currently in the input buffer.
interCharTimeout
Get the current inter-character timeout setting.
Return the number of bytes currently in the output buffer.
Get the current parity setting.
Get the current port setting.
Ring Indicator
Enable RS485 mode and apply new settings, set to None to disable.
rts
Get the current RTS/CTS flow control setting.
Get the current stop bits setting.
Get the current timeout setting.
writeTimeout
Get the current timeout setting.
Get the current XON/XOFF setting.
- apply_settings(d)
Apply stored settings from a dictionary returned from get_settings(). It’s allowed to delete keys from the dictionary. These values will simply left unchanged.
- close()
Close port
- fileno()
For easier use of the serial port instance with select. WARNING: this function is not portable to different platforms!
- flush()
Flush of file like objects. In this case, wait until all data is written.
- get_settings()
Get current port settings as a dictionary. For use with apply_settings().
- iread_until(*args, **kwargs)
Read lines, implemented as generator. It will raise StopIteration on timeout (empty read).
- isatty()
Return whether this is an ‘interactive’ stream.
Return False if it can’t be determined.
- log_event(payload: bytes, duration_ns: int) → None
Log the read/write event with performance data.
- Parameters:
payload (bytes) – The data that was read or written.
duration_ns (int) – The duration of the read/write operation in nanoseconds.
- nonblocking()
DEPRECATED - has no use
- open()
Open port with current settings. This may throw a SerialException if the port cannot be opened.
- read(size=1) → bytes
Read bytes from the serial port and log the event.
- Parameters:
size (int, optional) – The number of bytes to read, by default 1.
- Returns:
The bytes read from the serial port.
- Return type:
bytes
- read_all()
Read all bytes currently available in the buffer of the OS.
- read_until(expected=b'\n', size=None)
Read until an expected sequence is found (’ ‘ by default), the size
is exceeded or until timeout occurs.
- readable()
Return whether object was opened for reading.
If False, read() will raise OSError.
- readall()
Read until EOF, using multiple read() call.
- readline(size: Optional[int] = -1, /) → bytes
Read a line from the serial port and log the event.
- Parameters:
size (int, optional) – The maximum number of bytes to read, by default -1 (read until timeout).
- Returns:
The line read from the serial port.
- Return type:
bytes
- readlines(hint=-1, /)
Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.
- reset_input_buffer()
Clear input buffer, discarding all that is in the buffer.
- reset_output_buffer()
Clear output buffer, aborting the current output and discarding all that is in the buffer.
- seek()
Change stream position.
Change the stream position to the given byte offset. The offset is interpreted relative to the position indicated by whence. Values for whence are:
0 – start of stream (the default); offset should be zero or positive
1 – current stream position; offset may be negative
2 – end of stream; offset is usually negative
Return the new absolute position.
- seekable()
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().
- send_break(duration=0.25)
Send break condition. Timed, returns to idle state after given duration.
- set_input_flow_control(enable=True)
Manually control flow - when software flow control is enabled. This will send XON (true) or XOFF (false) to the other device. WARNING: this function is not portable to different platforms!
- set_output_flow_control(enable=True)
Manually control flow of outgoing data - when hardware or software flow control is enabled. WARNING: this function is not portable to different platforms!
- tell()
Return current stream position.
- truncate()
Truncate file to size bytes.
File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.
- writable()
Return whether object was opened for writing.
If False, write() will raise OSError.
- write(data: bytes)
Write data to the serial port and log the event.
- Parameters:
data (bytes) – Data to be written to the serial port.
- writelines(lines, /)
Write a list of lines to stream.
Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.
- property baudrate
Get the current baud rate setting.
- property bytesize
Get the current byte size setting.
- property cd
Carrier Detect
- Type:
Read terminal status line
- property cts
Clear To Send
- Type:
Read terminal status line
- property dsr
Data Set Ready
- Type:
Read terminal status line
- property dsrdtr
Get the current DSR/DTR flow control setting.
- property exclusive
Get the current exclusive access setting.
- property in_waiting
Return the number of bytes currently in the input buffer.
- property inter_byte_timeout
Get the current inter-character timeout setting.
- property out_waiting
Return the number of bytes currently in the output buffer.
- property parity
Get the current parity setting.
- property port
Get the current port setting. The value that was passed on init or using setPort() is passed back.
- property ri
Ring Indicator
- Type:
Read terminal status line
- property rs485_mode
Enable RS485 mode and apply new settings, set to None to disable. See serial.rs485.RS485Settings for more info about the value.
- property rtscts
Get the current RTS/CTS flow control setting.
- property stopbits
Get the current stop bits setting.
- property timeout
Get the current timeout setting.
- property write_timeout
Get the current timeout setting.
- property xonxoff
Get the current XON/XOFF setting.