|
|
|
@ -116,6 +116,9 @@ class UARTConfig:
|
|
|
|
|
|
|
|
|
|
|
|
device: Serial device path (e.g., "/dev/ttyUSB0")
|
|
|
|
device: Serial device path (e.g., "/dev/ttyUSB0")
|
|
|
|
baudrate: Baud rate (e.g., 115200)
|
|
|
|
baudrate: Baud rate (e.g., 115200)
|
|
|
|
|
|
|
|
data_bits: Data bits (7 or 8)
|
|
|
|
|
|
|
|
stop_bits: Stop bits (1 or 2)
|
|
|
|
|
|
|
|
parity: Parity ('N', 'E', 'O', 'M', 'S')
|
|
|
|
buffer_size: RX circular buffer capacity in bytes
|
|
|
|
buffer_size: RX circular buffer capacity in bytes
|
|
|
|
read_chunk_size: Max bytes to read per loop iteration
|
|
|
|
read_chunk_size: Max bytes to read per loop iteration
|
|
|
|
|
|
|
|
|
|
|
|
@ -130,6 +133,9 @@ class UARTConfig:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
device: str
|
|
|
|
device: str
|
|
|
|
baudrate: int
|
|
|
|
baudrate: int
|
|
|
|
|
|
|
|
data_bits: int = 8
|
|
|
|
|
|
|
|
stop_bits: int = 1
|
|
|
|
|
|
|
|
parity: str = 'N'
|
|
|
|
buffer_size: int = 496
|
|
|
|
buffer_size: int = 496
|
|
|
|
read_chunk_size: int = 512
|
|
|
|
read_chunk_size: int = 512
|
|
|
|
|
|
|
|
|
|
|
|
@ -301,12 +307,27 @@ def uart_open(port: UARTPort) -> Status:
|
|
|
|
return Status.ALREADY_OPEN
|
|
|
|
return Status.ALREADY_OPEN
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Open serial port
|
|
|
|
# Map parity
|
|
|
|
|
|
|
|
parity_map = {
|
|
|
|
|
|
|
|
'N': serial.PARITY_NONE,
|
|
|
|
|
|
|
|
'E': serial.PARITY_EVEN,
|
|
|
|
|
|
|
|
'O': serial.PARITY_ODD,
|
|
|
|
|
|
|
|
'M': serial.PARITY_MARK,
|
|
|
|
|
|
|
|
'S': serial.PARITY_SPACE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Open serial port with FULL configuration
|
|
|
|
port._serial_port = serial.Serial(
|
|
|
|
port._serial_port = serial.Serial(
|
|
|
|
port=port.config.device,
|
|
|
|
port=port.config.device,
|
|
|
|
baudrate=port.config.baudrate,
|
|
|
|
baudrate=port.config.baudrate,
|
|
|
|
|
|
|
|
bytesize=port.config.data_bits,
|
|
|
|
|
|
|
|
parity=parity_map.get(port.config.parity, serial.PARITY_NONE),
|
|
|
|
|
|
|
|
stopbits=port.config.stop_bits,
|
|
|
|
timeout=0.01, # Non-blocking with small timeout
|
|
|
|
timeout=0.01, # Non-blocking with small timeout
|
|
|
|
write_timeout=0.5
|
|
|
|
write_timeout=0.5,
|
|
|
|
|
|
|
|
xonxoff=False, # Disable software flow control
|
|
|
|
|
|
|
|
rtscts=False, # Disable hardware (RTS/CTS) flow control
|
|
|
|
|
|
|
|
dsrdtr=False # Disable hardware (DSR/DTR) flow control
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Create RX buffer
|
|
|
|
# Create RX buffer
|
|
|
|
|