Skip to content

Commit 17d9c5b

Browse files
authored
Merge pull request #37 from pj-r/read-trash
Read away trash coming before slave id
2 parents cf81971 + 8abcefa commit 17d9c5b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arduino-modbus-rtu-tcp-gateway/03-modbus-rtu.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ void recvSerial() {
127127
static byte serialIn[MODBUS_SIZE];
128128
while (mySerial.available() > 0) {
129129
byte b = mySerial.read();
130-
if (rxNdx < MODBUS_SIZE) {
130+
if (rxNdx == 0 && queueData[0] != b) {
131+
if(recvMicroTimer.isOver())
132+
break;
133+
// wait a bit to the buffer to clean up
134+
recvMicroTimer.sleep(charTimeOut());
135+
}
136+
else if (rxNdx < MODBUS_SIZE) {
131137
serialIn[rxNdx] = b;
132138
rxNdx++;
133139
} // if frame longer than maximum allowed, CRC will fail and data.errorCnt[ERROR_RTU] will be recorded down the road

0 commit comments

Comments
 (0)