1 year ago

#211050

test-img

CNord

How to send multible g-code comands via pySerial without time-delay

I have a python script that creates a serial connection to my Arduino-Mega (ramps1. 4). I am using the pyserial library, with which I send G-Code commands via the COM. There "Marlin 2.0x" reads the input and acts on any G-Code.

So far everything works. I can write any G-Code via serial.write() and Marlin understands it. But unfortunately I had to add a time delay if I want to act on multiple commands. Is there a nice way of circumventing that?

Here is an example code of Extruding 1mm of Filament twice.

import serial
import time  

ser1 = serial.Serial('COM3', 250000)
time.sleep(1)
ser1.write(('G92 E1\n').encode())
time.sleep(1)
ser1.write(('G92 E1\n').encode())

Ideally it'd look like this without the delays:

import serial
import time  

ser1 = serial.Serial('COM3', 250000)
ser1.write(('G92 E1\n').encode())
ser1.write(('G92 E1\n').encode())

But then commands get skipped.

python

serial-port

pyserial

g-code

0 Answers

Your Answer

Accepted video resources