2

I have found a script to send a g-code to GRBL but, i would like this script to repeat 30 times. how do i write this into the code?

The code i am trying to repeat is G91Y-20X15F500 G90Y3.00F250

I have research on while and loops but i do not understand why "print" is used so frequently. Thank you for any help!

Sociopath
  • 13,068
  • 19
  • 47
  • 75

1 Answers1

2

It seems like you need to put your g-code into a file, then pass the filename to the command:

$ python stream.py commands.gcode /path/to/serial-device
Initializing grbl...
SND: 1 : G91Y-20X15F500 BUF: 15 REC:
SND: 2 : G90Y3.00F250 BUF: 28 REC:
G-code streaming finished!

WARNING: Wait until grbl completes buffered g-code blocks before exiting.
  Press <Enter> to exit and disable grbl.

Not sure about the waiting for buffered blocks to finish running, but to run the script 30 times you'd use a loop, for example in bash:

for i in `seq 1 30`; do python stream.py commands.gcode /path/to/serial-device; done

You could also do the loop with Windows batch commands or another Python script. I'd recommend putting the code you linked to inside of a function to make it easier to call from other Python code.

You'd probably want it to run unattended, so you'd have to remove the raw_input(...) line and replace it with either a call to sleep() or some additional operations with the serial device to poll whether the script has finished running on the machine.

The print statements are used for displaying the current status of the program (when the device is initialized, when a line of code is sent to the device, when it's finished, etc.).

Steven Kryskalla
  • 14,179
  • 2
  • 40
  • 42