Add execption for errorCode -1

This commit is contained in:
2024-05-07 21:33:40 +02:00
parent 430771844d
commit 0dce10553c

View File

@@ -4,7 +4,6 @@
#define SERIAL_PORT "/dev/USB_ARDUINO"
#define MAX_MESSAGE_LEN 1048
#define TIME_OUT 500
#define BAUDS 115200 //vitesse des données (bit/sec)
serialib init_serial(){
@@ -30,16 +29,20 @@ int main(int argc, char *argv[]) {
serialib serial = init_serial();
int errorCode;
char myString[MAX_MESSAGE_LEN] = {0};
std::string toSend = "G " + line + "\n";
strcpy(myString, toSend.c_str());
myString[strlen(myString)] = '\0';
errorCode = serial.writeBytes(toSend.c_str(), toSend.length());
int errorCode = serial.writeBytes(toSend.c_str(), toSend.length());
std::cout << "Code received: " << errorCode << std::endl;
if(errorCode == -1){
std::cerr << "Error while sending data" << std::endl;
}
else {
std::cout << "Data sent: " << errorCode << std::endl;
}
serial.closeDevice();
file.close();