Добавление флага write в MB_DefineRegistersAddress

И рефакторинг дефайнов размеров сообщения
This commit is contained in:
2025-11-30 21:20:25 +03:00
parent e0ce0e6dbf
commit df3f71cdff
10 changed files with 58 additions and 53 deletions

View File

@@ -374,7 +374,7 @@ static int MB_Define_Size_of_Function(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *
}
}
mb_func_size = RX_FIRST_PART_SIZE + mb_func_size; // size of whole message
mb_func_size = RS_RX_FIRST_PART_SIZE + mb_func_size; // size of whole message
return mb_func_size;
}
@@ -392,7 +392,7 @@ RS_StatusTypeDef MB_Master_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgType
//------INFO ABOUT DATA/MESSAGE------
//-----------[first bytes]-----------
// set ID of slave device
modbus_uart_buff[ind++] = modbus_msg->MbAddr;
modbus_uart_buff[ind++] = modbus_msg->DeviceAddr;
// set function code
modbus_uart_buff[ind++] = modbus_msg->FuncCode;
@@ -472,7 +472,7 @@ RS_StatusTypeDef MB_Master_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDe
int expected_size = 0;
// get ID of slave device
modbus_msg->MbAddr = modbus_uart_buff[ind++];
modbus_msg->DeviceAddr = modbus_uart_buff[ind++];
// get function code (check if error response)
modbus_msg->FuncCode = modbus_uart_buff[ind++];
@@ -633,7 +633,7 @@ RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_COILS(uint8_t slave_addr, uint16_t start
// Copy coil data to message MbData array
for(int i = 0; i < byte_count; i++) {
if(i < DATA_SIZE) {
if(i < MbData_size) {
msg.MbData[i] = coils_data[i];
}
}
@@ -649,7 +649,7 @@ RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_REGS(uint8_t slave_addr, uint16_t start_
msg.ByteCnt = quantity * 2; // Each register is 2 bytes
// Copy register data to message MbData array
for(int i = 0; i < quantity && i < DATA_SIZE; i++) {
for(int i = 0; i < quantity && i < MbData_size; i++) {
msg.MbData[i] = regs_data[i];
}