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
| #include <iostream>
#include <SerialStream.h>
#include <stdio.h>
using namespace std;
using namespace LibSerial;
SerialStream ardu;
void open() {
cout << "Ouverture du serial \n",
/*The arduino must be setup to use the same baud rate*/
ardu.Open("/dev/ttyUSB0");
ardu.SetBaudRate(SerialStreamBuf::BAUD_9600);
ardu.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
};
int main() {
open();
// Write an array of data from the serial port.
ardu << 'A';
ardu << '5';
ardu << '0';
ardu << '0';
ardu << '\n';
while(1)
{
// Read a whole array of data from the serial port.
const int BUFFER_SIZE_IN = 7 ;
int index = 0;
char input_buffer[BUFFER_SIZE_IN];
string buf;
ardu >> buf;
cout << buf << "\n";
}
cout << "Au revoir";
ardu.Close() ;
} |
Partager