If I open a port with Pyserial then try to write GCode to a printer controller board twice, the second command does not execute. If I close the port after the first time data is written, then reopen it and write again, it works fine. I have found another stackoverflow post detailing the same problem, but the solution does not apply to my code because the serial object instantiation defaults to dsrdtr=False
. Here is my code:
from serial import Serial
from typing import cast
import time
serial = Serial(str('COM4'), 115200, timeout=2, writeTimeout=3) # Open port
time.sleep(1) # Wait for board to boot
serial.write(b'G00 X25\n') # Rotate stepper motor
time.sleep(2) # Wait 2 seconds or else the port will close before the motor stops rotating
serial.close()
serial.open()
time.sleep(1) # Wait for board to boot
serial.write(b'G00 X25\n') # Rotate stepper motor
What could explain this behavior?