stop in while

I not resolved!
The program work fine ... but i want add this event for not wait minutes until cnc finished cutting and can comunicate with esp8266 again!

costy35:
The program work fine ... but i want add this event for not wait minutes until cnc finished cutting and can comunicate with esp8266 again!

Then either post the complete program or (better still) make a short program that illustrates the problem and post that.

...R

You might need to reconsider how you do things.

Consider the following code. It's taken from your first post, and I've made a couple of small changes to turn it into a program (it won't compile, because I have not added the SD headers) but it will illustrate my point.

bool file_processed = false;


void setup() {
  Serial.begin(9600)
}

void loop() {
	
  if(!file_processed) {
    costel();
  }
}

void costel() {
  String message="";
  String gcodex="";
  String gcodey="";
  char t;
  int a;
  
  File f = SPIFFS.open("/test.nc", "r");
  while(f.available()) {
    t = f.read();
    // G01 X123.456 Y567.890\n
    message += t;
    if(t=='X'){
      a=1;gcodex=""; //read line until 'X' (attention X high!!!)
    } 
    if(t=='Y'){
      a=2;gcodey=""; //read line until 'Y' (attention Y high!!!)
    } 
    if(t=='\n'){ //if line end
      a=0;
      Serial.println(message); //send gcode line to gcode interpreter
      message="";       //empty gcode string
    }
    if(a==1)
      if(t !='X' && t !=' ')
        gcodex +=t; //write svg coordonate without 'X' and space
    if(a==2)
      if(t !='Y' && t !=' ')
        gcodey +=t; //write svg coordonate without 'X' and space
  }
  
  f.close();
  file_processed = true;;
}

Okay. Loop will call costel() once.
costel will open your file, read it and print every line out.
while costel is running, the arduino will do nothing until costel is finished.
you can add other function calls in there, but essentially, this routine is 'blocking'

Now, consider the next bit of code.
Again, taken from your first post, with some small modifications to turn it into a program to illustrate my point

bool file_opened = false;
bool file_processed = false;
bool EOL_found = false;
File f;
  
String message="";
String gcodex="";
String gcodey="";


void setup() {
  Serial.begin(9600)
}

void loop() {
	
  if(!file_processed) {
    costel();
  }
}

void costel() {

  char t;
  int a;
  
  if (file_not_opened) {
    f = SPIFFS.open("/test.nc", "r");
    file_not_opened = false;
  }
  EOL_found = false;
  while(f.available()&& !EOL_found) {
    t = f.read();
    // G01 X123.456 Y567.890\n
    message += t;
    if(t=='X'){
      a=1;gcodex="";  //read line until 'X' (attention X high!!!)
    }
    if(t=='Y'){
      a=2;gcodey=""; //read line until 'Y' (attention Y high!!!)
    } 
    if(t=='\n'){ //if line end
      a=0;
      Serial.println(message); //send gcode line to gcode interpreter
      message="";       //empty gcode string
      EOL_found = true;
    }
    if(a==1)
      if(t !='X' && t !=' ')
        gcodex +=t; //write svg coordonate without 'X' and space
    if(a==2)
      if(t !='Y' && t !=' ')
        gcodey +=t; //write svg coordonate without 'X' and space
  }
  if(!f.available()) {
    f.close();
    file_processed = true;
  }
}

This bit of code will do the same thing as the top bit, but it does it in a different manner.

loop() calls costel() many times. The first time costel() is called it will open your file, read a line then print the line to serial
Each subsequent time costel() gets called, it will read a line, then print it to serial
When there are no more lines to read, costel() will close the file and set a flag (file_processed=true). This will stop loop from calling costel().

The point is this... With the top version, costel() was blocking until it read and processed the entire file.
The bottom version will block for only one line!

This means that loop can now do things like (sort of pseudocode)

START

  ...
  process one line of your file
  see to stepper motor
  update display
  ...

GOTO START