<p>I would like to log each line of G-code to the serial port as it is processed.</p>
<p><strong>Steps to achieve</strong>:</p>
<ul>
<li>the printer reads a file from the SD card</li>
<li>each line it reads will be serial logged (this I can't figure out)</li>
<li>those lines can then read via the serial monitor on a laptop</li>
</ul>
<p>So by the end of the print, on my laptop I would have the reconstructed G-code file (plus whatever other logs the printer outputs).</p>
<p>The printer runs the Prusa Firmware. Ideally I would like to achieve the logging from altering the firmware rather than adding an extra plugin/server (For understanding and experimenting purposes).</p>
<p><strong>What I tried</strong></p>
<p>I have looked in code and found <a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/Marlin.h#L99" rel="nofollow noreferrer">the print functions</a> and examples of them in use in the code. This line is the &quot;<a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/cmdqueue.h#L43" rel="nofollow noreferrer">command, which is to be excecuted right now</a>&quot;, but I think that would be the just one command not the full line.</p>
<p>The <a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/cardreader.cpp" rel="nofollow noreferrer">cardreader</a> or <a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/SdBaseFile.cpp" rel="nofollow noreferrer">SdBaseFile</a> are where I would expect a G-code line to be read such that I could add a print statement after it but I did not see where.</p>
<p>Would it be as easy as setting this <a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/cardreader.cpp#L30" rel="nofollow noreferrer">card.logging</a> bool to true?</p>
<p>I imagine this is quite an easy thing to do and that I have just overcomplicated it by trying to understand the firmware. Any advice would be great!</p>

[{'answer_id': 15017, 'author': 'fred_dot_u', 'author_id': 854, 'author_profile': 'https://3dprinting.stackexchange.com/users/854', 'pm_score': 1, 'selected': False, 'text': '<p>If you have the hardware at hand, you can use OctoPrint to collect the data you require. It\'s common for users to create an OctoPrint server on a Raspberry Pi, but it can be installed easily on a Windows or Linux machine as well. Once in place, logging is available for various types of information.</p>\n<p>From the <a href="https://community.octoprint.org/t/where-can-i-find-octoprints-and-octopis-log-files/299" rel="nofollow noreferrer">OctoPrint blog</a>:</p>\n<p>The logs are crucial instruments of analysis and debugging, so it\'s usually in your best interest to provide them when asking for help or reporting a bug, even if not explicitly prompted for them:</p>\n<blockquote>\n<p>octoprint.log: OctoPrint\'s main application log file. Contains a\ngeneral log of everything that happens while OctoPrint is running.\nIncludes version information, installed plugins and a myriad of more\ndata points.</p>\n<p>This must always be included when reporting a bug 47 to allow for\nfurther analysis and reproduction. It is also a very good idea to\nprovide this when asking for help :wink:</p>\n<p>serial.log: A log of all of the communication going on between\nOctoPrint and your printer. Usually disabled for performance reasons,\nenable it through Settings &gt; Serial Connection.</p>\n<p>Either that or at the very least the output in OctoPrint\'s Terminal\ntab is crucial for analysis of any kind of communication issues or\nmisbehaviours observed with your printer, so it\'s important to include\nit when discussing such issues.</p>\n<p>plugin_pluginmanager_console.log: A log of the command line activity\nof the plugin manager. Very important for analysis of such questions\nlike &quot;Why can\'t I install plugin $xyz?&quot;, so if you have such a\nproblem, best include this.</p>\n<p>plugin_softwareupdate_console.log: A log of the command line activity\nof the software updater. Very important for analysis of such questions\nlike &quot;Updating OctoPrint always fails, why?&quot;, so if you have such a\nproblem, best include this.</p>\n</blockquote>\n<p>Third party plugins might also have special log files here. If a plugin author asks you to provide a special log created by their plugin for further analysis, this should be where you can find it.</p>\n<p>The above selection is from the linked site, which also includes embedded links for more information regarding the log files. Note that serial.log is specifically referenced to collect data between OctoPrint and your printer, although it defaults to disabled on install.</p>\n'}, {'answer_id': 15021, 'author': 'NickDGreg', 'author_id': 25679, 'author_profile': 'https://3dprinting.stackexchange.com/users/25679', 'pm_score': 1, 'selected': True, 'text': '<p>In <code>cmdqueue.h</code> the <code>CMDBUFFER_DEBUG</code> macro is defined (<a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/cmdqueue.h#L47" rel="nofollow noreferrer">see here</a>) which will log lots of information related to the commands being processed. Probably more information than you need...</p>\n<p>To log only the commands as they are processed (i.e. when the printer moves and extrudes etc.) you need <a href="https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/Marlin_main.cpp#L3696" rel="nofollow noreferrer">this line from marlin_main.cpp</a>: <code>SERIAL_ECHO(cmdbuffer+bufindr+CMDHDRSIZE);</code>.</p>\n<p>You can copy this outside of the <code>#ifdef CMDBUFFER_DEBUG</code> condition and compile the firmware then when you connect to the serial port each G-code line the printer processes will be logged.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/15016', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/25679/']