class
SerialBridge
One of the board's serial ports, open on this computer.
from hardlabs_sdk.serial import SerialBridgeReturned by Board.serial. Bytes pass through unchanged in both directions, so binary protocols arrive as sent. The address stays the same while the board restarts.
As on a real serial line, bytes the firmware sends while nothing has the port open are dropped. A pseudo-terminal keeps them in its buffer (a few KB) until you open it again.
pyserial's socket:// close waits 0.3 s before returning. Closing one of these ports skips that wait when the port was opened in the same Python process, so a framework that opens and closes the port around every command runs at the board's pace.
On macOS, reset_output_buffer() on a pseudo-terminal discards bytes written but not yet sent to the board. Use the socket:// address with a framework that calls it.
Usage
import serial
with board.serial("rs485") as bus:
port = serial.serial_for_url(bus.url, baudrate=115200, timeout=5)
port.write(b"~ ~")Attributes
urlstr- What pyserial's
serial_for_urlopens:socket://127.0.0.1:53817, or the pseudo-terminal's path. pathstr | None- The pseudo-terminal's device file (
/dev/ttys012), orNonefor asocket://port. portstr- The board's name for the port:
rs485. bytes_inint- Bytes received from the board.
bytes_outint- Bytes sent to the board.
bytes_droppedint- Bytes from the board dropped because nothing had the port open.
SerialBridge.writemethod
Sends bytes to the board's UART directly, without opening the port.
bridge.write(data)Arguments
databytes- The bytes to send, unchanged.
SerialBridge.closemethod
Closes the port. Board.stop closes every port the board opened.
bridge.close()