Hi,
I am communicating with a 3D Printer running Marlin. I am trying to determine when a command like G28 is finished processing.
Marlin sends out data letting you know while it is "echo:busy: processing". I want to know when it is done "ok P15 B3".
The issue I am having is I am using memcmp to compare the received data on the serial port to my byte array holding the "ok P15 B3" data.
The "echo:busy: processing" is sent out as one character string, but when the "ok P15 B3" is sent is is received with 91 characters and the part I care about is last. Like such:
echo:busy: processing
Active Extruder: 0
X:190.00 Y:155.00 Z:10.00 E:0.00 Count X:15200 Y:12400 Z:4000
ok P15 B3
What would be the proper way to go about this as I normally do not do this type of coding.
bool ok_message = false;
do{
uint8_t nBytes = comportReceive(&pData[0], MSGBUFFERSIZE);
if (nBytes > 0){
if(!memcmp(pData, okData, sizeof(okData))){
Serial.println("TRUE");
Serial.write(pData, nBytes);
Serial.println("");
ok_message = true;
}else{
Serial.println("FALSE");
Serial.println(nBytes);
Serial.write(pData, nBytes);
ok_message = false;
}
}
Serial.println("(okData != pData)");
delay(1000);
}while(!ok_message);
// ------------------------------------------------------------------------------------------------------
// comportReceive
// ------------------------------------------------------------------------------------------------------
// pMsg = Message buffer
// nLen = Message buffer length
//
int comportReceive(byte* pMsg, int nLen)
{
// Declarations
int nBytes = 0;
// Read serial data
while(Serial2.available() > 0)
{
pMsg[nBytes++] = (byte)Serial2.read();
if(nBytes >= nLen)
break;
}// end while
return nBytes;
}// end comportReceive
Any help and guidance is appreciate as I have searched exhaustively for a while now. Is an option to only read the Serial port until I get the newline character "\n", and break up my Serial port reads that way? I would like to learn the best way to do such a coding task.
I am creating an ESP32 Bluetooth PS4 Controller interface for 3D Printers. I just want to make it safe, and so the user knows when the process is completed and prevents them from trying to tell Marlin to do something while it is busy. I have quite a bit of it done and plan on open-sourcing it on Github.
Thank you,
/retnel