From 5e95fb8c7e74ce7f80a1aa7ceafa2a45bf77b60c Mon Sep 17 00:00:00 2001 From: Lizongdi <1210855344@qq.com> Date: Mon, 10 Aug 2026 16:34:46 +0800 Subject: [PATCH] =?UTF-8?q?spoolend=20=E3=80=90=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E3=80=91=E5=B7=AE=E5=BC=82=E7=82=B9=E6=A2=B3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/Spoolend/README.md | 12 ++++++------ project/Spoolend/modbus.c | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/project/Spoolend/README.md b/project/Spoolend/README.md index 7de76db..eb6168e 100644 --- a/project/Spoolend/README.md +++ b/project/Spoolend/README.md @@ -221,7 +221,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| | 操作 | 发送: `34 03 000B 0002 CRC` (从地址11开始读2个) | -| 预期响应 | `34 83 02 CRC` (异常码 0x02: 非法数据地址) | +| 预期响应 | `34 80 02 CRC` (异常码 0x02: 非法数据地址) | ### TC-MODBUS-04: FC06 写单个寄存器 — 写 K1 控制 @@ -236,7 +236,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| | 操作 | 发送: `34 06 000C 0000 CRC` (地址 12 超出范围) | -| 预期响应 | `34 86 02 CRC` (异常码 0x02) | +| 预期响应 | `34 80 02 CRC` (异常码 0x02) | ### TC-MODBUS-06: FC10 写多个寄存器 — 批量写入 K1-K4 @@ -251,7 +251,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| | 操作 | 发送: `34 10 0000 0004 04 0001 0000 CRC` (byteCount=4 但 registerCount=4 需要 8 字节) | -| 预期响应 | `34 90 03 CRC` (异常码 0x03) | +| 预期响应 | `34 80 03 CRC` (异常码 0x03) | ### TC-MODBUS-08: FC10 写多个寄存器 — 只读寄存器保护 @@ -273,7 +273,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| | 操作 | 发送: `34 01 0000 0001 CRC` (FC01 不支持) | -| 预期响应 | `34 81 01 CRC` (异常码 0x01) | +| 预期响应 | 无响应(静默丢弃) | --- @@ -310,7 +310,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| -| 前置条件 | holdingRegisters[5]=0 (自动), [4]=0 (正极性), [7]=5000 (5秒超时) | +| 前置条件 | holdingRegisters[5]=0 (自动), [4]=0 (正极性), [7]=0x1388 (5秒超时) | | 操作 | 持续发送 Modbus 命令(间隔 < 5秒) | | 预期 | K5 引脚保持低电平(电源开启,正极性时 RESET=开) | @@ -424,7 +424,7 @@ set(SRC_LIST | 项目 | 内容 | |------|------| -| 操作 | 修改 K1-K4 为自定义值,FC06 写 holdingRegisters[10]=55 | +| 操作 | 修改 K1-K4 为自定义值,FC06 写 holdingRegisters[10]=0x37 | | 预期 | 参数写入 Flash 最后一页;holdingRegisters[10] 自动变为 1 | | 验证 | 发送 FC03 读取确认 [10]=1 | diff --git a/project/Spoolend/modbus.c b/project/Spoolend/modbus.c index b457600..1b725e7 100644 --- a/project/Spoolend/modbus.c +++ b/project/Spoolend/modbus.c @@ -91,7 +91,7 @@ int Modbus_Slave_Check(char *_pBuffer, uint32_t _iSize) } break; default: - return -1; + return -1; // 由于这一行导致当前的不支持功能码的行为也是静默不响应 } if (_iSize < expected_len) return 0; @@ -150,13 +150,13 @@ void Modbus_Slave_Decode(const char *_pBuffer, uint32_t _iSize) } else { - Modbus_SendExceptionResponse(0x03); + Modbus_SendExceptionResponse(0x03);// 数据长度错误 } } break; default: - Modbus_SendExceptionResponse(0x01); + //Modbus_SendExceptionResponse(0x01); // 不支持的功能码 break; } } @@ -170,7 +170,7 @@ static void Modbus_HandleFunction03(uint16_t startAddress, uint16_t registerCoun || startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT || registerCount > 0x7D) { - Modbus_SendExceptionResponse(0x02); + Modbus_SendExceptionResponse(0x02);// 地址错误 return; } @@ -208,7 +208,7 @@ static void Modbus_HandleFunction06(uint16_t registerAddress, uint16_t value) if (registerAddress < REGISTER_START_ADDRESS || registerAddress >= REGISTER_START_ADDRESS + REGISTER_COUNT) { - Modbus_SendExceptionResponse(0x02); + Modbus_SendExceptionResponse(0x02);// 地址错误 return; } @@ -239,7 +239,7 @@ static void Modbus_HandleFunction10(uint16_t startAddress, uint16_t registerCoun || startAddress + registerCount > REGISTER_START_ADDRESS + REGISTER_COUNT || registerCount == 0 || registerCount > 0x7B) { - Modbus_SendExceptionResponse(0x02); + Modbus_SendExceptionResponse(0x02);// 地址错误 return; } @@ -278,7 +278,7 @@ static void Modbus_SendExceptionResponse(uint8_t exceptionCode) extern TComCtrl *g_ptRS485_1; response[0] = MODBUS_SLAVE_ADDRESS; - response[1] = 0x80; + response[1] = 0x80; //这里与原版差异为直接回复0x80而不是与一个功能码 response[2] = exceptionCode; uint16_t crc = CalculateCRC(response, 3);