Closed epsilonrt closed 1 year ago
#include <Arduino.h>
#include <ModbusSerial.h>
ModbusSerial mb (Serial, 10);
const uint8_t NbOfCoil = 19;
const uint16_t FirstCoil = 20;
const uint32_t CoilValues = 0x056BCD;
void setup() {
Serial.begin (38400);
mb.config (38400);
for (uint8_t i = 0; i < NbOfCoil; i++) {
mb.addCoil (FirstCoil -1 + i, (CoilValues & (1 << i)) != 0);
}
}
void loop() {
mb.task();
}
Reading test with mbpoll :
C:\Users\pasca>mbpoll -a10 -b38400 -t0 -r20 -c19 -1 -v com6
mbpoll 0.1-19 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2015 Pascal JEAN aka epsilonRT
All rights reserved.
This software is governed by the CeCILL license <http://www.cecill.info>
Opening com6 at 38400 bauds (E, 8, 1)
Protocol configuration: Modbus RTU
Slave configuration...: address = [10]
start reference = 20, count = 19
Communication.........: com6, 38400-8E1
t/o 1.00 s, poll rate 1000 ms
Data type.............: discrete output (coil)
-- Polling slave 10...
[0A][01][00][13][00][13][8D][79]
Waiting for a confirmation...
<0A><01><03><4D><EB><05><23><D1>
[20]: 1
[21]: 0
[22]: 1
[23]: 1
[24]: 0
[25]: 0
[26]: 1
[27]: 0
[28]: 1
[29]: 1
[30]: 0
[31]: 1
[32]: 0
[33]: 1
[34]: 1
[35]: 1
[36]: 1
[37]: 0
[38]: 1
The bug is confirmed, the origin of the problem is identical to #1: bad decrementation of the numregs variable
Whole Modbus program hang when read 8 or 16 or 8*n coils using Read Coil Status (FC=01). However it is normal when read 1-7 ,9-15 , 17-23 , etc. The loop is still running. Seem something overflow in the program.