When reading two or more different register blocks for one dataset and a timeout on a reading occurs then you get the data from the previous block for all the following readings. This is due to the inputbuffer is not cleared. It should be considered to clear the input buffer in all the read procedures.
This code from production show how we do from now on.
function TModBusCom.ReadInputRegisters(RegisterStart, Count: Word): Boolean;
begin
Result := False;
try
// Avoid reading previous data after a read timeout
if FmbClient.Connected then
FmbClient.IOHandler.InputBuffer.Clear;
Result := FmbClient.ReadInputRegisters(RegisterStart, Count, FRegisterData);
except
on E: EIdException do
ModBusError(ModBus_etIndyException, ModBus_ftNotUsed, E.Message);
end;
if Result then
ParseData(mbfReadInputRegs, RegisterStart, Count);
end;
When reading two or more different register blocks for one dataset and a timeout on a reading occurs then you get the data from the previous block for all the following readings. This is due to the inputbuffer is not cleared. It should be considered to clear the input buffer in all the read procedures.
This code from production show how we do from now on.
function TModBusCom.ReadInputRegisters(RegisterStart, Count: Word): Boolean; begin Result := False; try // Avoid reading previous data after a read timeout if FmbClient.Connected then FmbClient.IOHandler.InputBuffer.Clear; Result := FmbClient.ReadInputRegisters(RegisterStart, Count, FRegisterData); except on E: EIdException do ModBusError(ModBus_etIndyException, ModBus_ftNotUsed, E.Message); end; if Result then ParseData(mbfReadInputRegs, RegisterStart, Count); end;