I have figured it out and it's actually my bad.
I'm checking the wrong flag. CycleStopped is true only if the Cycle Stop button is pressed.
- Code: Select all
if(exec.CycleStopped && System.IO.File.Exists(AutoloadFile)){
The correct flag is exec.stopped which is true when the program ends or if the machine is in idle after the execution of a single line. Not true when feed hold is active or the program is running.
- Code: Select all
if(exec.stopped && System.IO.File.Exists(AutoloadFile)){
Here is the code. There is no need to edit the M30 this way.
- Code: Select all
string AutoloadFile = Environment.GetEnvironmentVariable("TEMP") + @"\AutoloadUCCNC.tmp";
string gcodeFile = "";
//MessageBox.Show(AutoloadFile);
if(exec.stopped && System.IO.File.Exists(AutoloadFile)){
//read the file, it should have only one line
gcodeFile = System.IO.File.ReadAllText(AutoloadFile);
//clean the string
gcodeFile = gcodeFile.TrimEnd('\r', '\n');
//load the gcode
exec.Loadfile(gcodeFile);
while(exec.IsLoading()){}
//delete the tmp file, not the gcode
System.IO.File.Delete(AutoloadFile);
}