1 | #include <iostream> |
2 | #include <fstream> |
3 | #include <string> |
4 | #include <cstdlib> |
5 |
|
6 | int main() { |
7 | std::cout << "AutoPlow starting..." << std::endl; |
8 |
|
9 | std::cout << "Attempting to set proper device configuration on ARD1" << std::endl; |
10 | system("stty -F /dev/ttyACM0 9600 raw -clocal -echo"); |
11 |
|
12 | std::cout << "Attempting to begin serial data read on ARD1 (Motor Controller) at /dev/ttyACM0" << std::endl; |
13 | std::fstream ttyACM0; |
14 | ttyACM0.open("/dev/ttyACM0", std::fstream::in | std::fstream::out | std::fstream::app); |
15 | if (ttyACM0.good()) { |
16 | std::cout << "Successfully opened serial stream" << std::endl; |
17 | std::cout << "Attempting device reset" << std::endl; |
18 | std::cout << "Dumping contents:" << std::endl; |
19 | ttyACM0 << "Restart;"; |
20 | char buffer[256]; |
21 | std::string string; |
22 | ttyACM0 << "b1;"; |
23 | while (ttyACM0.getline(buffer, sizeof(buffer))) { |
24 | string = std::string(buffer); |
25 | std::cout << string << std::endl; |
26 | } |
27 | std::cout << "Closing file stream" << std::endl; |
28 | ttyACM0.close(); |
29 | } else { |
30 | std::cout << "Unsuccessful in opening serial stream. Make sure the Arduino is plugged in to the RPI." << std::endl; |
31 | return 1; |
32 | } |
33 | return 0; |
34 | } |
35 |
|