|
|
|
@ -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); |
|
|
|
|