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

Does not handle writes to 'invalid' holding registers on ModbusServer #112

Open
Mjacq79 opened this issue Jul 10, 2024 · 0 comments
Open

Comments

@Mjacq79
Copy link

Mjacq79 commented Jul 10, 2024

Based on the server sample, it seems that the intention is for a server application to define the maximum number of holding registers (65535). When a client writes holding registers, the ModbusServer will check that the write is within the bounds of the maximum possible holding register but there is no check to ensure that the write is within the defined holding registers.

I have a bit of experience working with Modbus Servers in an industrial setting, and I do not think I have ever seen a server that supports writes to all possible holding registers. Typically, a write to a register beyond what the server supports will result in a modbus exception being returned to the client.

If I use EasyModbus server to define 100 holding registers (0-100), any write to a holding register outside of that range will cause an IndexOutOfRange exception at ModbusServer.cs:WriteMultipleRegisters(). Instead of a Modbus Exception returned to the client, it just results in the TCP socket being closed.

As far as I am aware, the Modbus protocol allows servers to reject requests to specific register ranges, but I see no way to do that with the EasyModbus library. Ideally there would be some mechanism to define which holding registers within the address space are valid and which are invalid (allowing for distinct chunks of addresses to be used) but at the very least, I think that writes outside the number of registers defined by the holdingRegisters array should return the proper Modbus Exception instead of crashing.

--
As it stands, I cannot find a way to define a server that rejects writes to some holding registers. Either I define all registers, and the ModbusServer accepts a client request to write any of the registers, or I define a subset of the full address space and the ModbusServer fails to handle requests outside of the defined space.

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

1 participant