修复串口有时打不开的bug。
This commit is contained in:
@@ -7,33 +7,51 @@
|
|||||||
#include <options/options.h>
|
#include <options/options.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
using std::cout;
|
using namespace std;
|
||||||
using std::cerr;
|
|
||||||
using std::clog;
|
|
||||||
using std::dec;
|
|
||||||
using std::endl;
|
|
||||||
using std::hex;
|
|
||||||
|
|
||||||
GMAngle_t aim;
|
GMAngle_t aim;
|
||||||
|
|
||||||
|
string get_uart_dev_name(){
|
||||||
|
FILE* ls = popen("ls /dev/ttyUSB* --color=never", "r");
|
||||||
|
char name[20] = {0};
|
||||||
|
fscanf(ls, "%s", name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
Uart::Uart(){
|
Uart::Uart(){
|
||||||
if(wait_uart){
|
if(wait_uart){
|
||||||
while((fd = open("/dev/ttyUSB0", O_RDWR)) < 0);
|
string name;
|
||||||
|
do{
|
||||||
|
name = get_uart_dev_name();
|
||||||
|
if(name == ""){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}while((fd=open(name.data(), O_RDWR)) < 0);
|
||||||
}else{
|
}else{
|
||||||
fd = open("/dev/ttyUSB0", O_RDWR);
|
string name = get_uart_dev_name();
|
||||||
|
if(name == ""){
|
||||||
|
cerr<<"open port error"<<endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fd = open(name.data(), O_RDWR);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
cerr<<"open port error"<<endl;
|
cerr<<"open port error"<<endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fd = open("/dev/ttyUSB1", O_RDWR);
|
||||||
|
// if(fd < 0) {
|
||||||
|
// cerr<<"open port error"<<endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
if(set_opt(fd, 115200, 8, 'N', 1) < 0 )
|
if(set_opt(fd, 115200, 8, 'N', 1) < 0 )
|
||||||
{
|
{
|
||||||
cerr<<"set opt error"<<endl;
|
cerr<<"set opt error"<<endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cout<<"uart port success"<<endl;
|
cout << "uart port success" << endl;
|
||||||
|
|
||||||
buff[0] = 's';
|
buff[0] = 's';
|
||||||
buff[1] = '+';
|
buff[1] = '+';
|
||||||
|
|||||||
Reference in New Issue
Block a user