Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
211 stars 72 forks source link

About Message Receive #58

Open tonyjianhu opened 2 years ago

tonyjianhu commented 2 years ago

In Slave mode of the library, I can't seem to find a place to receive messages from the Master. For example, if the Master sends a request message with 03 function code, where can I receive it? I also want to be able to determine what function code the Master is requesting and what data it is receiving

Apollo3zehn commented 2 years ago

That's a valid question. You can control the response of the server using a validator function:

https://github.com/Apollo3zehn/FluentModbus/blob/master/doc/samples/modbus_validator.md/

However, there is no direct way to set the response data. You can only manipulate the server.GetHoldingRegisters() array (for example) from within the frame validation routine.