main() { do { if (gvarget(400)!=0) //if #400!=0, run g-code, otherwise continue to test #400 { do{ a=gvarget(6065); }while(a!=0); //wait Motion Controller ready to accept new program gvarset(100001,1); //Reset G-code pointer to start timer=5; do{ timer--;}while(timer>0); //0.5 sec Pause gvarset(100002,1); //Start G-code }; }while(1); //endless loop exit(99); }; //If variable #400 will be set to non-zero value, ENDLESS.plc process will be finished