Serial¶
Utility Functions¶
- mil_tools.hexify(buff: bytes) bytes [source]¶
Display a buffer of bytes in hex format. This should take a bytes object, and will return a bytes string in hex format.
>>> p = CommandPacket.create_send_packet(data, can_id = can_id) >>> p_bytes = p.to_bytes() >>> print('Sending ', hexify(p_bytes)) Sending c0:14:09:48:45:4c:4c:4f:c1
NoopSerial¶
- class mil_tools.NoopSerial(**kwargs)[source]¶
Inherits from
serial.Serial
, doing nothing for each function.Allows super classes to implement custom behavior for simulating serial devices.
SimulatedSerial¶
- defread
- defreset_input_buffer
- class mil_tools.SimulatedSerial[source]¶
Simulates a serial device, storing a buffer to be read in a program like a normal OS serial device.
Intended to be extended by other classes, which should override the write function to receive writes to the simulated device. These classes simply append to the buffer string which will be returned on reads to the simulated device.
Note:
NoopSerial
andSimulatedSerial
are generic and are candidates for mil_common.- str(x)
Pretty prints the
SimulatedSerial
object, its address, and the start of its buffer.
- repr(x)
Pretty prints the
SimulatedSerial
object, its address, and the start of its buffer. Equivalent tostr(x)
.
- property in_waiting: int¶
The number of bytes waiting to be read. This does not modify the buffer in any way; the buffer is only inspected.
- Returns
The count of bytes in the buffer.
- Return type