NamNamIoT / RAK3172_CANOPUS

Examples for Canopus_RAK3172 board
https://canopus-iot.com/
MIT License
56 stars 8 forks source link

[Fixed:data loss when value in modbus register > 255] #6

Closed duyle1402 closed 6 months ago

duyle1402 commented 6 months ago

Hi a Nam, I tested rak3172_canopus and using Canopus_modbus.h lib with rak_v1, when reading Modbus register when value > 255 (1 byte) i lost data. I think problem in https://github.com/NamNamIoT/RAK3172_CANOPUS/blob/main/examples/RAK3172_ModbusRTU_Master/Canopus_Modbus.cpp line 697, 708, 723. Try this code below to fix it

  1. Line 697: _u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 4] << 8) | u8ModbusADU[2 * i + 3];
  2. Line 708: _u16ResponseBuffer[i] = (0 << 8) | u8ModbusADU[2 * i + 3];
  3. Line 723: _u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 3] << 8) | u8ModbusADU[2 * i + 4];
NamNamIoT commented 6 months ago

You are correct. Solved! Thank you.