Makergear M2 Serial GCode Buffer?

Ask the MakerGear community for assistance...
Post Reply
sorna
Posts: 3
Joined: Thu Feb 01, 2018 12:37 pm

Makergear M2 Serial GCode Buffer?

Post by sorna » Wed Feb 07, 2018 8:45 pm

Hey everyone,

In a previous post I had had issues sending serial commands via Python to my Makergear M2 printer.
Those issues have since been resolved, after I gave my serial port the proper amount of time to initialize before sending my first command.

I have now moved onto writing simple code in Python that reads in a text file line by line (GCode), and sends each line serially to the M2 to be executed.

For relatively short text files, this process worked flawlessly. However, for a more lengthy GCode file, the printer can only execute a handful of commands before stopping.

What I imagine is happening is that as soon as my code says the serial port is good to go, it spits out GCode commands as fast as the baud rate allows, overwhelming the serial port, sending in all ~ 500 lines of code at once.

Is there some sort of buffer size limit that the M2 is able to take in? I would imagine that as GCode commands are executed, those lines are removed to make room for incoming data.

I have also attempted to put a slight wait in between each successive send command, but I'm still running a risk of overwhelming the M2. In these cases the printer continues to execute commands, but will frequently skip over commands, affecting print quality. Increasing this wait time ends up sending commands too infrequently that my print has slight pauses between each command, affecting my overall print quality with excess extrusion.

Any suggestions on how I should handle sending commands to the M2 such that movement remains continuous without overwhelming the port, and skipping over commands. My one thought was to send commands in chunks, with longer waits between them, but I have yet to try that out.

Thanks!

User avatar
ednisley
Posts: 1016
Joined: Fri Apr 11, 2014 5:34 pm
Location: Halfway up the Hudson
Contact:

Re: Makergear M2 Serial GCode Buffer?

Post by ednisley » Fri Feb 09, 2018 12:08 am

sorna wrote:sending in all ~ 500 lines of code at once

The MEGA2560 microcontroller has 8 kB of RAM, with a serial buffer on the order of a few hundred bytes, tops. You must pace your serial output by monitoring the responses from the microcontroller, but it's complicated: Marlin doesn't send a response for every command.

Take a look at the Printrun source code (in Python!) for ideas on how to make it work:
https://github.com/kliment/Printrun

Post Reply