# How do you send G-code from a USB port with Python?

I'm working on a project for my masters where I'm trying to detect print errors using object detection and I want to be able to pause the printer when a potential fault is detected. However I can't seem to figure out the correct way to send G-code to my printer from a Python script. Does anyone happen to know how this works?

• I'm working on an identical project, I couldn't find any contact in your profile. If you want to discuss/share approaches let me know. Via SO chat chat.stackoverflow.com/users/6859185/nickdgreg or my github is in my profile – NickDGreg Dec 18 '20 at 18:24

The process is pretty straightforward, you open a serial connection and send the instructions over the serial connection. The printer reports "OK" when received (not when the command has been executed).