-
-
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
Modbus library will skip first byte received #1476
Comments
<20ms sleeps are not manageable with nanoFramework. The next best option would be with |
Thanks for your information. as sleep function may not be accurate enough, I'll do more investigations on this. I think there's difference between RS232 and RS485 in the nanoframework and we should have different logic for either mode. Will keey you guys updated. |
After some digginer, I think the best solution for now is read 3 bytes and do a pattern check ([id]-[fcode]) from first 2 bytes.
hbTimeout.SetInteger((CLR_INT64)pThis[FIELD___readTimeout].NumericByRef().s4 * TIME_CONVERSION__TO_MILLISECONDS);
NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeoutTicks));
Conclution: Ideally Modbus library should have configuable frame timing to fit various use cases. however I think do the 3 bytes pattern detection should be fine for now. |
I'm strongly advocating for the 3 (maybe 4) dummy bytes read to acomplish an "as close as possible" timming for this. |
Hi @josesimoes , I agree it may slow the performance, but I can't find a better solution because:
|
I think I found a solution, will create a prototype for test. |
@JohnMasen any progress on this? |
Hi @josesimoes , sorry I'm working on an urgent case these days, may take a few weeks to finish. I'll back to this after that. I'm using an internal buffer, pattern match and "fixed skip size" combination to archive performance and memory consumption. The code will read 4+n(n=bytes skipped lasttime) bytes into internal memory, then try to skip n bytes and decode message, if it fails then it fall back to the start of buffer and begin pattern match. Please feel free to close the issue by now, I can create a new PR and link it back to this issue when everything is ready. |
No worries. Take your time. Good luck for whatever you need it and let's keep this one open for the moment to track this. |
Library/API/IoT binding
nanoFramework.IoT.Device.ModBus
Visual Studio version
VS2022
.NET nanoFramework extension version
2022.3.0.78
Target name(s)
No response
Firmware version
No response
Device capabilities
No response
Description
Modbus document requries a 3.5 characters timing between sending and receving.
Instead of wait a certain time, the library will do a dummy read as sleep function after sending a request.
Here's a demo chart shows 2 different cases.
In case 2, the first byte was skipped. This happends when my device is running a web server as background service. It could also happends on multi-threaded application or low performance CPU device.
How to reproduce
Expected behaviour
The library should return correct server response.
Screenshots
No response
Sample project or code
No response
Aditional information
No response
The text was updated successfully, but these errors were encountered: