Skip to content

Modbus Exception, wrong byte order in toRaw() method #20

@leszekkedzierski-a4bee

Description

@leszekkedzierski-a4bee

Inside the method toRaw() from ModbusException byte order is wrong. Below is the code with the correct order:

Corrected:

std::vector<uint8_t> ModbusException::toRaw() const noexcept {
  std::vector<uint8_t> result(3);

  result[0] = _slaveId;
  result[1] = static_cast<uint8_t>(_functionCode | 0b10000000);
  result[2] = static_cast<uint8_t>(_errorCode);

  return result;
}

Original:

std::vector<uint8_t> ModbusException::toRaw() const noexcept {
  std::vector<uint8_t> result(3);

  result[0] = _slaveId;
  result[1] = static_cast<uint8_t>(_errorCode | 0b10000000);
  result[2] = static_cast<uint8_t>(_functionCode);

  return result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions