Welcome! Log In Create A New Profile

Advanced

How Do Marlin and Host Software Handshake?

Posted by Kyle R 
How Do Marlin and Host Software Handshake?
August 20, 2015 09:41AM
Hi, I am a 3D printer enthusiast and a novice programmer. I am writing my own 3D printer host software in Python. I am able to send individual lines of G-code to my home-built printer (Marlin firmware), and now I want to try some test prints with many hundreds of lines of G-code. My slicing program saves it's G-code into a text file, and the program grabs a line and sends it serially to the printer.

My question: For sending multiple lines in order, and getting the timing right, there must be some sort of confirmation from Marlin to the host software that the previous command was completed, right? My Python host software would just send line-by-line everything in my text document as quickly as possible if there isn't some sort of handshake put into place. Can someone please help me understand how other host software deals with this?

I appreciate it.

Kyle
Re: How Do Marlin and Host Software Handshake?
August 20, 2015 11:36AM
I believe marlin sends "ok" when clear to send
Re: How Do Marlin and Host Software Handshake?
August 20, 2015 12:19PM
If you are using printer electronics which implements the USB port over a serial link without flow control, such as any electronics based on the atmega2560 chip, then you have to wait for the OK response to each command before you know it is safe to send another one. This makes it tricky to get good throughput without hogging the CPU, because if you yield the CPU every time you are waiting for an ACK, you may not get scheduled often enough to maintain throughput. This is why you often see print stuttering if you use Pronterface (which is also written in Python) to send the data, especially if you are running anything else on the PC at the same time.

If you are using more modern electronics with a native USB port, you can just send the data anyway, and the device driver will block when the buffer is full.

Repetier host and Pronterface both have configuration options to say whether to wait for the OK or not. In Repetier host I am told it is called "Ping pong". In Pronterface it is called TCP Streaming mode.

Edited 1 time(s). Last edit at 08/20/2015 12:27PM by dc42.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: How Do Marlin and Host Software Handshake?
August 20, 2015 03:00PM
Thank you, I'm seeing the "ok" coming from Marlin now.
Re: How Do Marlin and Host Software Handshake?
August 23, 2015 11:16AM
Thank you dc42, maybe I should consider spawning a thread, or using a subprocess to listen for the ACK? The way I've programmed it now, my GUI freezes while it is printing, because I'm stuck in a loop waiting for the ACK, before I send the next line of g-code.
Re: How Do Marlin and Host Software Handshake?
August 23, 2015 05:04PM
Preferably, use modern electronics that has proper flow control so that you don't need to wait for the OK response. But if you want to support old electronics that needs the application-level handshake, then I suggest you have a separate process or thread to listen for the OK, and when it sees it, pick up the next line of gcode from a queue that the main thread fills, and send it.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: How Do Marlin and Host Software Handshake?
March 31, 2017 11:06AM
I am really a bit surprised that Arduino creators decided to reinvent the wheel. RTS/CTS is a very good and very simple method of flow control that was used for decades on RS-232 interface. Actually, if it were implemented on Arduino, one could simply use a file copy routine to send data to Marlin. Like, DOS command copy filename.gcode COM3 would work. In reality, if you try it with Marlin (and I tried it), it gets stuck after a few lines of g-code. I have an HP plotter built around 1980 (with laser LED fitted), I am running it thru a USB-to-RS232 converter from Ebay. And it works like a charm using RTS/CTS.

I am also writing some host software for Marlin and also came across this problem. Guess, I am going to have to process "ok" messages after sending each line of code.

Edited 1 time(s). Last edit at 03/31/2017 11:07AM by AngelOfGrief.
Sorry, only registered users may post in this forum.

Click here to login