From f8bbc0b00633d2d17da7ce75c0e5806ee255565d Mon Sep 17 00:00:00 2001 From: jenahn0630 Date: Thu, 9 Apr 2026 06:36:21 +0900 Subject: [PATCH] Fix Bug: Update RS485 baud rate configuration to use dlmstp_baud_rate(mstp_port) instead of shared data enum value (#1294) --- ports/linux/dlmstp_port.c | 4 ++-- ports/linux/rs485.c | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ports/linux/dlmstp_port.c b/ports/linux/dlmstp_port.c index 547967b2..8d25abb0 100644 --- a/ports/linux/dlmstp_port.c +++ b/ports/linux/dlmstp_port.c @@ -702,8 +702,8 @@ bool dlmstp_init(void *poPort, char *ifname) */ newtio.c_cflag = poSharedData->RS485MOD | CLOCAL | CREAD | BOTHER | (BOTHER << IBSHIFT); - newtio.c_ispeed = poSharedData->RS485_Baud; - newtio.c_ospeed = poSharedData->RS485_Baud; + newtio.c_ispeed = dlmstp_baud_rate(mstp_port); + newtio.c_ospeed = dlmstp_baud_rate(mstp_port); /* Raw input */ newtio.c_iflag = 0; /* Raw output */ diff --git a/ports/linux/rs485.c b/ports/linux/rs485.c index 146cc9c9..41cb8d7d 100644 --- a/ports/linux/rs485.c +++ b/ports/linux/rs485.c @@ -206,7 +206,13 @@ void RS485_Send_Frame( if (mstp_port && mstp_port->UserData) { poSharedData = (SHARED_MSTP_DATA *)mstp_port->UserData; - baud = poSharedData->RS485_Baud; + /* poSharedData->RS485_Baud stores a termios B-constant (e.g. + * B38400=15), NOT the actual numeric baud rate. Using it directly in + * the turnaround delay formula (40,000,000 / baud) would produce ~2.7 + * seconds instead of the correct ~1ms at 38400 baud. dlmstp_baud_rate() + * converts the termios constant to the real value. + */ + baud = dlmstp_baud_rate(mstp_port); handle = poSharedData->RS485_Handle; }