Apollo3zehn / FluentModbus

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

Add events, on data change. #2

Closed Apollo3zehn closed 3 years ago

ChangeTheCode commented 3 years ago

@Apollo3zehn is there a plan when this feature will be come? Currently we have to query the register to see if anything has changed, is this correct ?

Steve0212a commented 3 years ago

I second the need for this. We are looking to convert our Modbus server to .net core and your library works very well. This is the only feature it is missing that we need.

I really like your server, but without this feature, we may have to look elsewhere as we do not want to regularly poll for data changes.

Thanks for writing this server.

Apollo3zehn commented 3 years ago

I'll check that on monday. What is your specific need? Get notifications for single registers or for a full range of registers?

ChangeTheCode commented 3 years ago

For my point of view at the first time it would help if one of both would be supported. So you do not have to poll each time hand have to implement something to detect if something has changed in one register.

Apollo3zehn commented 3 years ago

I have pushed an update (3.0.1-preview.1) to nuget with the requested feature. A sample to get notifications on data change is shown here: https://apollo3zehn.github.io/FluentModbus/index.html#events

It would be great if you could test it and tell me if it suits your needs. Thanks :)

mharrand commented 3 years ago

Hi, I'm working with Steve0212a. I've implemented the new events and they seem to be working. Question though, when operating in Asynchronous mood, should I be using the server lock around the Gets and Sets in the event handlers?

Apollo3zehn commented 3 years ago

Yes you should use lock here, too. Otherwise it could happen that you and a request handler read/write to the same buffer location. Here is the lock statement of the request handler that you should synchronize to with your own lock statement: https://github.com/Apollo3zehn/FluentModbus/blob/master/src/FluentModbus/Server/ModbusRequestHandler.cs#L107