Created
February 13, 2020 21:15
-
-
Save MarkJB/6aa6c979c601f2c044cae67f06e254d1 to your computer and use it in GitHub Desktop.
Processing gcode sender thing (first pass at sending gcode to grbl)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial myPort = new Serial(this, "COM6", 115200); | |
int counter =0; | |
boolean grblInit = false; | |
void senderInit(String initCommand) { | |
println("In init"); | |
String val = ""; | |
while (myPort.available()==0){println("waiting for serial port");} | |
while (myPort.available()>0) { | |
println("Waiting for init..."); | |
val = myPort.readString(); | |
if (val.contains("Grbl 1.1f")) { | |
delay(2000); | |
myPort.clear(); | |
println("Grbl initalized"); | |
grblInit = true; | |
print("Sending init command: "); | |
println(initCommand); | |
myPort.write(initCommand); | |
myPort.write("\n"); | |
while(myPort.available()==0){println("waiting for response");} | |
print("Got response "); | |
val = myPort.readString(); | |
myPort.clear(); | |
println(val); | |
delay(1000); | |
} | |
} | |
println("Exiting init"); | |
} | |
void sender(String gcode) { | |
println("In sender function"); | |
String val = ""; | |
if (grblInit) { | |
println("grbl has been initalized so sending some gcode"); | |
println(gcode); | |
myPort.clear(); | |
//delay(1000); | |
myPort.write(gcode); | |
myPort.write("\n"); | |
println("Waiting for 4 bytes e.g. 'ok'"); | |
counter++; | |
println(counter); | |
while(myPort.available()==4){;} | |
if(myPort.available()>1){ | |
print("Number of bytes in serial buffer: "); | |
println(myPort.available()); | |
val = myPort.readString(); | |
myPort.clear(); | |
} | |
println(val); | |
} | |
println(val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment