armink / FreeModbus_Slave-Master-RTT-STM32

Add master mode to FreeModbus. | 在 FreeModbus 中添加主机模式
Other
1.6k stars 820 forks source link

多处疑似bug #30

Closed PentzWoods closed 5 years ago

PentzWoods commented 5 years ago

库主是否实机运行过,在移植的过程中,发现代码有多处bug,如操作holding register时(eMBMasterRegHoldingCB函数)的读写方向

switch (eMode) { / read current register values from the protocol stack. / case MB_REG_READ: while (usNRegs > 0) { pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] >> 8); pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] & 0xFF); iRegIndex++; usNRegs--; } break; / write current register values with new values from the protocol stack. / case MB_REG_WRITE: while (usNRegs > 0) { pusRegHoldingBuf[iRegIndex] = pucRegBuffer++ << 8; pusRegHoldingBuf[iRegIndex] |= pucRegBuffer++; iRegIndex++; usNRegs--; } break; }

PentzWoods commented 5 years ago

啊,我看错了,前面还有一句eMode = MB_REG_WRITE;限定了读写方向。 可是这样的写法并不是太好,逻辑上不直观