-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
75 lines (63 loc) · 1.98 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <stdlib.h>
#include <SerialStream.h>
LibSerial::SerialStream _motor;
void writePort(std::string& str){
_motor << str;//lpBufferToWrite;
std::cout << "wrote the demand "<<str.c_str()<<" written " << std::endl;
}
int main(int argc, char **argv) {
std::string PORT ="/dev/ttyUSB0";
_motor.Open(PORT);
_motor.SetBaudRate(LibSerial::SerialStreamBuf::BAUD_9600);
if ( ! _motor.good() ){
std::cerr << "Error: Could not set the baud rate." <<std::endl;
exit(1);
}
_motor.SetCharSize(LibSerial::SerialStreamBuf::CHAR_SIZE_8);
if ( ! _motor.good() ){
std::cerr << "Error: Could not set the char size." <<std::endl;
exit(1);
}
_motor.SetParity( LibSerial::SerialStreamBuf::PARITY_NONE ) ;
if ( ! _motor.good() ){
std::cerr << "Error: Could not set the parity." <<std::endl;
exit(1);
}
_motor.SetNumOfStopBits( 1 ) ;
if ( ! _motor.good() ) {
std::cerr << "Error: Could not set the number of stop bits."
<< std::endl ;
exit(1) ;
}
_motor.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE ) ;
if ( ! _motor.good() ){
std::cerr << "Error: Could not set the control." <<std::endl;
exit(1);
}
_motor.SetNumOfStopBits(1) ;
if ( ! _motor.good() ){
std::cerr << "Error: Could not set the stopbit." <<std::endl;
exit(1);
}
//std::string enable("1en\n2en\n");
std::string enable("v50\n");
writePort(enable);
//read port
// while( _motor.rdbuf()->in_avail() == 0 )
// {
// usleep(100) ;
// }
// //
// // Keep reading data from serial port and print it to the screen.
// //
// while( _motor.rdbuf()->in_avail() > 0 )
// {
// char next_byte;
// _motor.get(next_byte);
// std::cerr << std::hex << static_cast<int>(next_byte) << " ";
// usleep(100) ;
// }
// std::cerr << std::endl ;
return 0;
}