connection to multiple rs485 modbus rtu slaves
I have a groov epic with two GRV-CSERI-4 modules, in the second module, on a single channel I have wired two identical drives in serial RS485 MODBUS RTU, slave 1 and slave 2.
Communication Works correctly.
In the code you can see that I change the address of the slave with a for, which goes from 1 to the number of connected devices.
The initial record is 100, and the return is 10 records, in the table ch1_nt03HoldingRegAsIntReturnValues the data from slave 1 and 2 arrive and are overwritten, for this I make the move with the MoveNumTableToNumTable function from ch1_nt03HoldingRegAsIntReturnValues to ch1_ntDatastoreModbus, moving the index with the variables “( ch1_indexScanDevice-1)*ch1_returnNregister;”
that is, in the ch1_ntDatastoreModbus table from index 0 to index 9 is slave 1 and from index 10 to 19 is slave 2;
The problem is that after a while the data of the slaves are exchanged, index 0-9 is slave 2 and index 10-19 is slave 1, it is as if the response was delayed and that of slave 1 arrived when the response was already requested of slave 2.
place a variable that when equal to 1 closes and open the communication port, after doing this, the indices return to their normal state, index 0- 9 slave 1 and index 10-19 is slave 2, but after a while the same thing happens again.
note:
delayMsec(ch1_msDelayScan); // = 100
ch1_fMasterReadDelay = 0.5;
also use:
delayMsec(ch1_msDelayScan); // = 1000
ch1_fMasterReadDelay = 1;
But the problem continues.
What can cause this problem?