Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIdModBusServer: WriteRegisters gets triggered multiple times #52

Open
BobanSpasic opened this issue Feb 5, 2022 · 3 comments
Open

Comments

@BobanSpasic
Copy link

Hi,
I have converted your Delphi Slave demo (Indy10) to Lazarus (Version 2.2.0 64bit on Windows 10).
I am sending 32-bit values from PLC to TIdModBusServer by using 16-PresetMultipleRegisters method.
For the sake of debugging, I have modified the code of your demo as follows (added logging to mmoErrorLog):

procedure TfrmMain.msrPLCWriteRegisters(const Sender: TIdContext;
  const RegNr, Count: integer; const Data: TModRegisterData;
  const RequestBuffer: TModBusRequestBuffer; var ErrorCode: byte);
var
  i: integer;
begin
  mmoErrorLog.Lines.Add('Message register = ' + IntToStr(RegNr) +
    ';  Message length= ' + IntToStr(Count));
  for i := 0 to (Count - 1) do
  begin
    SetRegisterValue(RegNr + i, Data[i]);
    mmoErrorLog.Lines.Add('Message value ' + IntToStr(i) + ' = ' + IntToStr(Data[i]));
  end;
end;

I sent the values 3 and 7993, and this is what I get in the ErrorLog:

Message register = 11;  Message length= 2
Message value 0 = 3
Message value 1 = 7993
Message register = 11;  Message length= 2
Message value 0 = 0
Message value 1 = 7993

As you can see, the event gets triggered twice, where the second one contains a wrong value (0 instead of 3).
Any solution to this problem?

@JensMertelmeyer
Copy link
Contributor

  • Can you post a network recording with something like, for example, Wireshark?
  • Can you post the callstack for both times the handler is called?

@BobanSpasic
Copy link
Author

Hi Jens,
you may close the issue - the PLC is sending weird data.
I apologize for the inconvenience.

To explain - the PLC is sending data even if the output registers are not ready, so it is sending "something" that is in the register at the moment. The second problem is the repetition of sending - the PLC sends the Modbus message 1-3 times in one shot, and it happens that the registers do not contain valid data for every repetition.

@JensMertelmeyer
Copy link
Contributor

Yes, I also once had a problem with a client whose PLCs was acting like this. It's good if you're able to tell if you can trust the data you receive.

PS: I cannot close the issue, I am not the repo owner, just a user like you 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants