coassoftwaresystems / delphi-modbus

Delphi ModbusTCP components
114 stars 61 forks source link

InputBuffer noty cleared after timeout #42

Open thomsentaastrup opened 4 years ago

thomsentaastrup commented 4 years ago

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;