Closed duyle1402 closed 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
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 4] << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (0 << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 3] << 8) | u8ModbusADU[2 * i + 4];
You are correct. Solved! Thank you.
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
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 4] << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (0 << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 3] << 8) | u8ModbusADU[2 * i + 4];