Apollo3zehn / FluentModbus

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

Additional features for ModbusTcpServer #32

Closed mkroesen closed 3 years ago

mkroesen commented 3 years ago

I have some questions about new features for the server.

Is it possible to limit the number of clients? Something like:

server = new ModbusTcpServer();
server.MaxConnections = 5;
server.Start();

Is it possible to disable or to set the max addresses server.MaxInputRegisterAddress = 10 (not only get) for some registers? For example:

- Input Register
- Holding Register
- Read Coils
...

So that you get an "Illegal function"-Error in ModbusPoll or something.

Would be great if there was a solution for this.

Apollo3zehn commented 3 years ago

Yes that sounds like a good extension (both suggestions). I will prepare a draft once the other issue with the endiannes is clarified.

Apollo3zehn commented 3 years ago

I have prepared the draft pull request (#33) but I am not yet done with the documentation updates. I had to implement everything a bit different than suggested:

Thus I added two new methods: Span<short> GetInputRegisters() and Span<short> GetHoldingRegisters(). The return value is a Span<short> and there are several extension methods for this type. These are:

An example usage can be found here: https://github.com/Apollo3zehn/FluentModbus/blob/feature/server-extensions/tests/FluentModbus.Tests/ModbusServerTests.cs#L47-L71

The advantage with Span<short> is that I don't need any startOffset property anymore.

The performance is quite good for my understanding:

grafik

grafik

I´ll finish this tomorrow.

mkroesen commented 3 years ago

That sounds great. I appreciate your changes then. Will you also update the nuget package? Thanks.

Apollo3zehn commented 3 years ago

The update is finished now (there have been minor naming changes):

https://github.com/Apollo3zehn/FluentModbus/releases/tag/v2.2.0 The nuget package is also updated: https://www.nuget.org/packages/FluentModbus/

I hope this solves your issues and fits to your needs. If not, please come back to discuss further modifications.