Browse Source

Fix serial port redirection (index ≠ port num) (#16687)

Robby Candra 4 years ago
parent
commit
a0a93e35ae
3 changed files with 10 additions and 11 deletions
  1. 1
    1
      Marlin/src/core/serial.cpp
  2. 8
    9
      Marlin/src/gcode/queue.cpp
  3. 1
    1
      Marlin/src/gcode/queue.h

+ 1
- 1
Marlin/src/core/serial.cpp View File

@@ -29,7 +29,7 @@ static const char errormagic[] PROGMEM = "Error:";
29 29
 static const char echomagic[]  PROGMEM = "echo:";
30 30
 
31 31
 #if NUM_SERIAL > 1
32
-  int8_t serial_port_index = SERIAL_PORT;
32
+  int8_t serial_port_index = 0;
33 33
 #endif
34 34
 
35 35
 void serialprintPGM(PGM_P str) {

+ 8
- 9
Marlin/src/gcode/queue.cpp View File

@@ -191,7 +191,6 @@ bool GCodeQueue::process_injected_command() {
191 191
   // Execute command if non-blank
192 192
   if (i) {
193 193
     parser.parse(cmd);
194
-    PORT_REDIRECT(SERIAL_PORT);
195 194
     gcode.process_parsed_command();
196 195
   }
197 196
   return true;
@@ -243,7 +242,7 @@ void GCodeQueue::ok_to_send() {
243 242
   #if NUM_SERIAL > 1
244 243
     const int16_t pn = port[index_r];
245 244
     if (pn < 0) return;
246
-    PORT_REDIRECT(pn);
245
+    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
247 246
   #endif
248 247
   if (!send_ok[index_r]) return;
249 248
   SERIAL_ECHOPGM(MSG_OK);
@@ -267,9 +266,9 @@ void GCodeQueue::ok_to_send() {
267 266
  */
268 267
 void GCodeQueue::flush_and_request_resend() {
269 268
   #if NUM_SERIAL > 1
270
-    const int16_t p = port[index_r];
271
-    if (p < 0) return;
272
-    PORT_REDIRECT(p);
269
+    const int16_t pn = port[index_r];
270
+    if (pn < 0) return;
271
+    PORT_REDIRECT(pn);                    // Reply to the serial port that sent the command
273 272
   #endif
274 273
   SERIAL_FLUSH();
275 274
   SERIAL_ECHOPGM(MSG_RESEND);
@@ -296,14 +295,14 @@ inline int read_serial(const uint8_t index) {
296 295
   }
297 296
 }
298 297
 
299
-void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t port) {
300
-  PORT_REDIRECT(port);
298
+void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
299
+  PORT_REDIRECT(pn);                      // Reply to the serial port that sent the command
301 300
   SERIAL_ERROR_START();
302 301
   serialprintPGM(err);
303 302
   SERIAL_ECHOLN(last_N);
304
-  while (read_serial(port) != -1);           // clear out the RX buffer
303
+  while (read_serial(pn) != -1);          // Clear out the RX buffer
305 304
   flush_and_request_resend();
306
-  serial_count[port] = 0;
305
+  serial_count[pn] = 0;
307 306
 }
308 307
 
309 308
 FORCE_INLINE bool is_M29(const char * const cmd) {  // matches "M29" & "M29 ", but not "M290", etc

+ 1
- 1
Marlin/src/gcode/queue.h View File

@@ -150,7 +150,7 @@ private:
150 150
    */
151 151
   static bool enqueue_one(const char* cmd);
152 152
 
153
-  static void gcode_line_error(PGM_P const err, const int8_t port);
153
+  static void gcode_line_error(PGM_P const err, const int8_t pn);
154 154
 
155 155
 };
156 156
 

Loading…
Cancel
Save