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

How to specify custom response decoder? #310

Open
daiguangbao opened this issue Dec 18, 2024 · 4 comments
Open

How to specify custom response decoder? #310

daiguangbao opened this issue Dec 18, 2024 · 4 comments
Labels

Comments

@daiguangbao
Copy link

it's now trying to get a valid function code (of course there won't be, since the function code is custom), and give up after 20 retries.
tokio-modbus-0.16.1\src\codec\rtu.rs 265 ---> Failed to decode response frame: Invalid function code: 0x65
Is there a way users can specify their own decoder outside?

@uklotzde
Copy link
Member

Decoding of user-defined function codes (65..=72 and 100..=110) has not been implemented yet.

get_response_pdu_len() only supports a limited subset of functions codes while decode_response_pdu_bytes() already passes through all unhandled function codes.

@uklotzde
Copy link
Member

There is also a considerable amount of redundancy between the code of the mentioned functions. Could probably be rewritten in a better way.

@daiguangbao
Copy link
Author

yes, when I return a correct number for a custom function code in get_response_pdu_len(), it goes correctly. but there's many other function codes and only the user knowns what len is expected.

@uklotzde
Copy link
Member

yes, when I return a correct number for a custom function code in get_response_pdu_len(), it goes correctly. but there's many other function codes and only the user knowns what len is expected.

Checking the expected size only is an additional safety measure. The CRC code in the ADU serves as the sentinel.

Decoding of ADU/PDU frames should be rewritten. I have vague ideas, but unfortunately no time to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants