Skip to content

Commit 34b5bfa

Browse files
committed
Read away trash coming before slave id
1 parent 17d9c5b commit 34b5bfa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ void recvSerial() {
127127
static byte serialIn[MODBUS_SIZE];
128128
while (mySerial.available() > 0) {
129129
byte b = mySerial.read();
130-
if (rxNdx == 0 && queueData[0] != b) {
131-
if(recvMicroTimer.isOver())
130+
if (rxNdx == 0 && queueData[0] != b) { // TODO maybe duplicate check? See the check bellow.
131+
if (recvMicroTimer.isOver())
132132
break;
133133
// wait a bit to the buffer to clean up
134-
recvMicroTimer.sleep(charTimeOut());
135-
}
136-
else if (rxNdx < MODBUS_SIZE) {
134+
recvMicroTimer.sleep(charTimeOut());
135+
data.errorCnt[ERROR_RTU]++;
136+
} else if (rxNdx < MODBUS_SIZE) {
137137
serialIn[rxNdx] = b;
138138
rxNdx++;
139139
} // if frame longer than maximum allowed, CRC will fail and data.errorCnt[ERROR_RTU] will be recorded down the road

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
v7.3 2024-01-16 Bugfix Modbus RTU Request form, code comments
2828
v7.4 2024-12-16 CSS improvement, code optimization, simplify DHCP renew, better README (solution to ethernet reset issue)
2929
v8.0 2025-03-09 Fix 404 error page, code optimization
30+
v8.1 2025-03-30 Read away trash coming before slave id
3031
*/
3132

32-
const byte VERSION[] = { 8, 0 };
33+
const byte VERSION[] = { 8, 1 };
3334

3435
#include <SPI.h>
3536
#include <Ethernet.h>

0 commit comments

Comments
 (0)