-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
Fix G-Code queue #21122
Fix G-Code queue #21122
Conversation
Kick meatpack out of the queue code, and instead let it implement a serial interface like any other serial class (this should remove bugs in the queue code)
It's not because it builds that it works. And I'm almost sure it does not.
ab39baa
to
08adacf
Compare
8b1ddb6
to
eeb73fb
Compare
Make multiserial actually composable to handle multiple multiserial as child Document everything
I've installed the editorconfig plugin on VSCode.
I tried printing with this patch and something went wrong starting at line 37250 in the attached log. |
Don't do that now, it's full of debugging code for a LPC1769 platform with multiserial hardcoded in it, so it'll break serial output. I'll inform you when it's ready, but for now, it's not ready... |
In fact your serial log was very useful. The issue you had around line 37250 is due to a serial error and the printer actually resumed from the error (this does not happen with the code in bugfix) so this means that the fixes in this PR works. Upon error, it's starting to dump all the serial state (character by character) so it becomes crazy in your log but it's very useful for me to figure out what's happening. The error you've experienced is here
So the printer failed to understand the command with line N17690 (I think the 'N' did not work). So it's asking to resend it and your host does that, and it resumes from the error. |
I know the PR is a draft but I tried it anyway because I was hopeful it would fix a long-standing issue with my printer where the first few characters of a command is sporadically lost. I've explained it in more detail here. I'm sure it is not caused by a bad serial cable and it only happens when the gcode contains arcs. My guess is that it has something to do with the serial queue and how the string is processed when received. |
In your case, you can monitor the number of bytes in your USB's serial port with the 'A:' part of the answer. If it's goes above the size of the buffer (I'm not speaking about BUFSIZE, but the Arduino's serial port internal buffer), the data will be lost resulting to a truncated command (as seen above). If you look closely, at line 37660 and later, you'll see that you'll get errors when this number becomes larger than 63, I suspect you have a 64 byte buffer for the serial port. If I were you, I would reduce BUFSIZE, (it's almost useless anyway) to 4 or 8, and look at your framework's serial buffer size (look for HardwareSerial or CDCSerial, I don't know) and increase the buffer from 64 to 128. |
… step), don't pull this." This reverts commit 9f9b82e.
@ldursw Try to set |
08065f4
to
4543a88
Compare
Just tested the PR up to 052bc24 and MeatPack broke again with missing characters. This patch makes it work again. diff --git a/Marlin/src/feature/meatpack.h b/Marlin/src/feature/meatpack.h
index e439913da6e3785aa22fb9e4c9cf38db26114117..96bab6d88dcee1e618c55bfca9c28ff3df26e65b 100644
--- a/Marlin/src/feature/meatpack.h
+++ b/Marlin/src/feature/meatpack.h
@@ -146,16 +146,16 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
// There is a potential issue here with multiserial, since it'll return its decoded buffer whatever the serial index here.
// So, instead of doing MeatpackSerial<MultiSerial<...>> we should do MultiSerial<MeatpackSerial<...>, MeatpackSerial<...>>
// TODO, let's fix this later on
- if (!charCount) {
- // Don't read in read method, instead do it here, so we can make progress in the read method
- while (out.available(index) > 0) {
- const int r = out.read(index);
- if (r == -1) return 0; // This is an error from the underlying serial code
- meatpack.handle_rx_char((uint8_t)r, index);
- charCount = meatpack.get_result_char(serialBuffer);
- readIndex = 0;
- }
+
+ // Don't read in read method, instead do it here, so we can make progress in the read method
+ while (charCount == 0 && out.available(index) > 0) {
+ const int r = out.read(index);
+ if (r == -1) return 0; // This is an error from the underlying serial code
+ meatpack.handle_rx_char((uint8_t)r, index);
+ charCount = meatpack.get_result_char(serialBuffer);
+ readIndex = 0;
}
+
return charCount;
} If As an alternative the loop could be replaced with an if statement to prevent an infinite loop. I've also tested this patch and it works as well. diff --git a/Marlin/src/feature/meatpack.h b/Marlin/src/feature/meatpack.h
index e439913da6e3785aa22fb9e4c9cf38db26114117..0b9d51e857521b881291c0aa60c37673910b7b8e 100644
--- a/Marlin/src/feature/meatpack.h
+++ b/Marlin/src/feature/meatpack.h
@@ -146,16 +146,17 @@ struct MeatpackSerial : public SerialBase <MeatpackSerial < SerialT >> {
// There is a potential issue here with multiserial, since it'll return its decoded buffer whatever the serial index here.
// So, instead of doing MeatpackSerial<MultiSerial<...>> we should do MultiSerial<MeatpackSerial<...>, MeatpackSerial<...>>
// TODO, let's fix this later on
- if (!charCount) {
- // Don't read in read method, instead do it here, so we can make progress in the read method
- while (out.available(index) > 0) {
- const int r = out.read(index);
- if (r == -1) return 0; // This is an error from the underlying serial code
- meatpack.handle_rx_char((uint8_t)r, index);
- charCount = meatpack.get_result_char(serialBuffer);
- readIndex = 0;
- }
- }
+
+ if (charCount > 0) return charCount; // The buffer still has data
+ if (out.available(index) <= 0) return 0; // No data to read
+
+ // Don't read in read method, instead do it here, so we can make progress in the read method
+ const int r = out.read(index);
+ if (r == -1) return 0; // This is an error from the underlying serial code
+ meatpack.handle_rx_char((uint8_t)r, index);
+ charCount = meatpack.get_result_char(serialBuffer);
+ readIndex = 0;
+
return charCount;
} |
This PR broke BINARY_FILE_TRANSFER feature:
this diff below probably will fix it, but I'm not sure in solution, haven't tried to use binary transfer to validate fix. People more familiar with that part of code, please double check: diff --git a/Marlin/src/gcode/sd/M28_M29.cpp b/Marlin/src/gcode/sd/M28_M29.cpp
index 6f3f2450a1..f34edb6f7c 100644
--- a/Marlin/src/gcode/sd/M28_M29.cpp
+++ b/Marlin/src/gcode/sd/M28_M29.cpp
@@ -49,7 +49,7 @@ void GcodeSuite::M28() {
// Binary transfer mode
if ((card.flag.binary_mode = binary_mode)) {
SERIAL_ECHO_MSG("Switching to Binary Protocol");
- TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.port[queue.index_r]);
+ TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.ring_buffer.command_port());
}
else
card.openFileWrite(p); |
Please open a bug report. |
@kad, Yep you're right and your fix is correct IMHO. Either you open a PR with this fix, or I can do it if you don't know how. |
Ok, I've done it. Thanks for the report! |
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Description
This fix many subtle and hard to find bugs in the G-Code queue, see #21119 for details.
Mainly:
It also fix a bug in LPC176x serial class I've missing in my previous round of fixes due to incompatible HardwareSerial method signatures (see #21010)
I've also removed Meatpack from the queue code and instead made it a serial class so it's transparent for Marlin and there is no special case anymore for Meatpack (and, in consequence, removed one level of looping in the queue code, so we can break out the loop upon error and continue processing the other serial port, instead of returning and dropping over serial port's data).
Requirements
Any board should be used
Benefits
It should fix #21010 and #21119
Configurations
See configuration attached in #21010
Related Issues
#21010 #21119