tokio-modbus
tokio-modbus copied to clipboard
RTU Custom Request Mismatching Function Code
Thanks for this awesome crate!
I can use read_holding_registers without issue. However, when I send a custom request with function code 0x03 (to mimic read_holding_registers), the call
let request = tokio_modbus::Request::Custom(3, Cow::Owned([0x01, 0x52, 0x00, 0x01].to_vec()));
ctx.call(request).await??;
returns:
Error: mismatching function codes: 3 Ok(ReadHoldingRegisters([47826]))
I skimmed through the source code but still couldn’t figure out where this mismatch is coming from. And the value 47826 is correct.
Am I misunderstanding how the custom request is supposed to be used?
Are you sure that the server also sends back 0x03?
The check is generally done here: https://github.com/slowtec/tokio-modbus/blob/4a061c4d0f16835606b85fb2a62285e3967cba2c/src/service/rtu.rs#L84-L94