-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Write function code for HandleHoldingRegisters #32
Comments
Pull Request #33 |
Hi shantanoo, first off, thanks for the pull request! I'm trying to keep the code/API simple and concise, so I'm trying to understand the rationale behind this. Why would you need to differentiate between holding reg write opcodes? |
Need to take action based on opcode. E.g. only write multiple registers should be supported and single register should return error. Might be better to different handler functions for single and multiple registers to have one-to-one mapping as per modbus specification. |
If what you're trying to achieve is to make sure that multiple registers are being written atomically (instead of a single register), would testing on Quantity work in your handler? Something along those lines: if isWrite && req.Quantity < 2 {
err = ErrIllegalDataValue
return
} Note that your handler still wouldn't be able to tell if that request came through opcode 0x6 or through 0x10 with a single register, but that shouldn't be a concern for your use case. Note that this technique can also be used on reads, if you ever want to ensure that reads are atomic as well. |
Actually I am trying to read the modbus request on TCP server/slave and get the data from RTU client/master. In that case, server don't know what type of request comes from the client. Hence needed to differentiate between function code 6 and 16 (0x10). |
Wait, so you'd like to reject writes using 0x6, but not 0x10, in the TCP server, so you can reject 0x6 requests which are not supported by your RTU slave, right? Why not just use 0x10 on the RTU client then? |
In TCP server implementation, how to find whether the function code was 6 or 16 (0x10)? And how to respond to it specifically?
The text was updated successfully, but these errors were encountered: