-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
53 lines (40 loc) · 1.14 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <fstream>
#include <iostream>
#include "serialib.h"
#define SERIAL_PORT "/dev/USB_ARDUINO"
#define MAX_MESSAGE_LEN 1048
#define BAUDS 115200 //vitesse des données (bit/sec)
serialib init_serial(){
serialib serial;
char errorOpening = serial.openDevice(SERIAL_PORT, BAUDS);
if (errorOpening!=1) exit(errorOpening);
return serial;
}
int main(int argc, char *argv[]) {
std::string filePath;
if (argc == 2) {
filePath = argv[1];
} else {
return 0;
}
std::ifstream file;
file.open(filePath);
std::string line;
getline(file, line);
serialib serial = init_serial();
std::cout << serial.isDeviceOpen() << std::endl;
char myString[MAX_MESSAGE_LEN] = {0};
std::string toSend = "G " + line + "\n";
strcpy(myString, toSend.c_str());
myString[strlen(myString)] = '\0';
int errorCode = serial.writeBytes(toSend.c_str(), toSend.length());
if(errorCode == -1){
std::cerr << "Error while sending data" << std::endl;
}
else {
std::cout << "Data sent: " << errorCode << std::endl;
}
serial.closeDevice();
file.close();
return 0;
}