examples/modbus: Fix endianess, it was inverted

This commit is contained in:
Alan C. Assis 2021-04-18 16:34:58 -03:00 committed by Xiang Xiao
parent 496393a87b
commit f7880bcca9

View File

@ -458,8 +458,8 @@ eMBErrorCode eMBRegInputCB(uint8_t *buffer, uint16_t address, uint16_t nregs)
index = (int)(address - CONFIG_EXAMPLES_MODBUS_REG_INPUT_START);
while (nregs > 0)
{
*buffer++ = (uint8_t)(g_modbus.reginput[index] >> 8);
*buffer++ = (uint8_t)(g_modbus.reginput[index] & 0xff);
*buffer++ = (uint8_t)(g_modbus.reginput[index] >> 8);
index++;
nregs--;
}
@ -498,8 +498,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
case MB_REG_READ:
while (nregs > 0)
{
*buffer++ = (uint8_t)(g_modbus.regholding[index] >> 8);
*buffer++ = (uint8_t)(g_modbus.regholding[index] & 0xff);
*buffer++ = (uint8_t)(g_modbus.regholding[index] >> 8);
index++;
nregs--;
}
@ -512,8 +512,8 @@ eMBErrorCode eMBRegHoldingCB(uint8_t *buffer, uint16_t address, uint16_t nregs,
case MB_REG_WRITE:
while (nregs > 0)
{
g_modbus.regholding[index] = *buffer++ << 8;
g_modbus.regholding[index] |= *buffer++;
g_modbus.regholding[index] = *buffer++;
g_modbus.regholding[index] |= *buffer++ << 8;
index++;
nregs--;
}