-
Notifications
You must be signed in to change notification settings - Fork 75
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
Check byte count in DetectFrame method. #75
Conversation
Good catch & thanks for the PR! Your solution makes sense. However, could you please extend your frame length check to make sure it is not a Modbus error frame? I think something like Here is the layout of both frame types:
|
Thank you for reminding the error response case! |
@Apollo3zehn, after your approval in branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Check byte count in DetectFrame method.
@iberisoft The package is released now, also as v3.2.2. |
Best regards. |
@jmsqlr, it should be solved now. When I started developing FluentModbus, I was on Windows and had no easy way to test the Modbus RTU part automatically. Now I am on Linux and the project is compiled using GitHub Actions. So now we can maybe link two virtual COM ports to run Modbus RTU unit tests to avoid issues like the one you described. |
Hello @Apollo3zehn,
I have found an issue with the current logic of how the Modbus RTU frame is detected. This issue occurs under seldom circumstances, let me share an example.
We have a temperature sensor with unit identifier 1 providing data thru input register 0. The corresponding Modbus request frame is
01 04 00 00 00 01 31 CA
. Response frames depend on the actual temperature getting as Celsius degrees multiplied by 100. However, there is a special value that we must focus on: 7.69 degrees. The Modbus response frame for value 769 is01 04 02 03 01 78 00
.The
DetectFrame
method is called from the response pump. Our sensor returns a frame as entirely (7 bytes) as divided into segments (e.g. 6+1 bytes). The described issue occurs when theDetectFrame
method is called for the response frame mentioned in the previous paragraph without the last byte (6-byte incomplete segment).Theoretically, such trimmed frames should be identified in
DetectFrame
due to relying on CRC. Unfortunately, the CRC-based check is not enough for this particular case. Look at the discussed response frame trimmed to01 04 02 03 01 78
. The frame-detection code treats this frame as successfully detected because sequence01 04 02 03
generates CRC0x7801
. Obviously,01 04 02 03 01 78
is incomplete by the standard because it indicates 2 bytes of data in the third byte but it has only one data byte.So I have added a couple of lines into the method to additionally check the byte count field declared by the Modbus RTU specification.