Modbus icon indicating copy to clipboard operation
Modbus copied to clipboard

Response Generation Quantity Issue

Open MatthewBoeding opened this issue 10 months ago • 0 comments

When parsing a request to generate a read coils response, the number of inputs is not parsed correctly. The bytes value should be a uint16_t instead of uint8_t. The standard requires 0x0000-0xFFFF. Currently, if you're value is 0x0000-0x00FF, you won't generate any value bytes.

https://github.com/Mazurel/Modbus/blob/9bd2ad492df05f9817bce2437d6195d875231c83/src/modbusResponse.cpp#L46-L51

You'll also need to change the value to be read:

uint16_t bytes; 
  
switch (_functionCode) { 
    case utils::ReadDiscreteOutputCoils: 
    case utils::ReadDiscreteInputContacts: 
    bytes = inputData[2] << 8 + inputData[3]; 

MatthewBoeding avatar Aug 21 '23 14:08 MatthewBoeding