-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[FR] Support for gcode sending with line numbers and checksums to improve communicaton reliability #2839
Comments
I analyzed the data corruption I'm experiencing. Sometimes a bytes is lost. I am working on adding checksum capabilities to the TFT, and have some first results. This proved to be simpler than I initially anticipated because some code I needed is already there. MARLIN LOG
GCODE FILE These are the Gcodes that Marlin should receive
Conclusion, serial data corruption occurred, but was successfully handled and corrected. |
I did some more tests to find out what causes the serial data corruption. I connected a PC serial interface to the RX pin of the motherboard (MKS Monster8 V1.0). This way I can review the data that is send to the motherboard.. The strange thing is that I never get a corrupted character, I only have a missing character. Perhaps the motherboard is not fast enough to always reliably process the data at 250K baud? Marlin uses Arduino STM32 to read (and send) serial data with the help of interrupts. At 250K baud this means that a character takes 40us. So if the motherboard is for some reason not able to process the received character within 40us then a byte could be lost, which should trigger an Overrun error (if enabled). So let me see what error code is reported.
When I disable the code at the end, which should help to recover from the error, the communication just continues. I found that |
@rondlh if you have already implemented a working (also supporting the re-transmission of corrupted gcodes (not implemented by me in the past)) CRC feature it could be useful in this moment also to me just to simplify the flow analysis in one of my printers. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Recently I've tested some serial communication algorithms by comparing the original gcode to the gcodes received by the motherboard running Marlin. I did that by logging the received commands, filtering out some lines (temp reports, M220, M221 etc.) and comparing the files with WinMerge.
To my surprise I found data corruption, which typically showed as a character missing at the host side. I never saw that any data got changed.
The resulting Gcode was still valid, so Marlin (almost) never reported any warnings/errors.
A typical line of gcode: "G1 X117.317 Y86.664 E190.36879"
When considering losing 1 character, then only in a few cases Marlin will complain:
Missing first "1" (invalid gcode command), or missing last "." (too long extrusion prevented if enabled in Marlin).
So the user might stay unaware of any issues.
I found missing character happened about once every 6-10MB of Gcode send at 250K baud.
It still happened at 115200, but a lower error rate.
Online I found that 2-wire serial communication cannot be considered to be reliable. Lowering the transmission speed can help, but it only reduces the data error rate. So the recommendation is:
"You don't achieve reliable communication by eliminating errors - you achieve it by detecting and recovering from errors."
I think that is a good point.
Marlin offers a way to achieve this by using line number and CRC checks for the gcode.
You could allow for higher baud rates, because errors can be handles when needed.
Programs like Pronterface and Octoprint use this strategy.
Online I found this:
Reset line number count with gcode command: "M110 N"
The CRC and line number can be added to a line of gcode like this: (thanks @digant73)
Some error messages need to be processed:
"Error:Line Number is not Last Line Number+1, Last Line: "
"Error: checksum mismatch, Last Line: "
"Error: No Checksum with line number, Last Line: "
And resend request:
"Resend: "
When not using ADVANCED_OK, this becomes quite trivial, because the last line just needs to be resend.
When using ADVANCED_OK an index of the last line numbers and gcode file indexes could be kept like this:
Line 120 --> file index 1000
Line 121 --> file index 1040
Line 122 --> file index 1082
Line 123 --> file index 1090
Line 124 --> file index 1130
Line 125 --> file index 1160
Line 126 --> file index 1170
Line 127 --> file index 1200
After a "Resend: 123", printing should resume at line 123, file index 1090
The text was updated successfully, but these errors were encountered: