From a520d8f17f42883af99af7d2bbc0bb0ec28c217d Mon Sep 17 00:00:00 2001 From: Kerem Date: Sun, 9 Nov 2025 21:13:07 +0100 Subject: [PATCH] port configuration corected --- uart/uart_kit/uart_core.py | 25 +++++++++++++++++++++++-- uart/uart_kit/uart_core_widget.py | 3 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/uart/uart_kit/uart_core.py b/uart/uart_kit/uart_core.py index a0e4fec..c04d11a 100644 --- a/uart/uart_kit/uart_core.py +++ b/uart/uart_kit/uart_core.py @@ -116,6 +116,9 @@ class UARTConfig: device: Serial device path (e.g., "/dev/ttyUSB0") 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 read_chunk_size: Max bytes to read per loop iteration @@ -130,6 +133,9 @@ class UARTConfig: """ device: str baudrate: int + data_bits: int = 8 + stop_bits: int = 1 + parity: str = 'N' buffer_size: int = 496 read_chunk_size: int = 512 @@ -301,12 +307,27 @@ def uart_open(port: UARTPort) -> Status: return Status.ALREADY_OPEN 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=port.config.device, 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 - 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 diff --git a/uart/uart_kit/uart_core_widget.py b/uart/uart_kit/uart_core_widget.py index bc947f8..e09ce2e 100644 --- a/uart/uart_kit/uart_core_widget.py +++ b/uart/uart_kit/uart_core_widget.py @@ -469,6 +469,9 @@ class UARTWidget(QWidget): config = UARTConfig( device=device, baudrate=baudrate, + data_bits=int(self.combo_databits.currentText()), + stop_bits=int(self.combo_stopbits.currentText()), + parity='N' if self.combo_parity.currentText() == 'None' else self.combo_parity.currentText()[0], buffer_size=4096, stop_mode=stop_mode, stop_timeout_ms=self.spin_timeout.value(),