Skip to content

Commit

Permalink
fix tty & default databits, add more baud_rate (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericsii authored Apr 10, 2023
1 parent 141cf59 commit 9a75ac8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rmoss_base/include/rmoss_base/uart_transporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class UartTransporter : public TransporterInterface
public:
UartTransporter(
const std::string & device_path = "/dev/ttyUSB0", int speed = 115200,
int flow_ctrl = 0, int databits = 0, int stopbits = 1, int parity = 'N')
int flow_ctrl = 0, int databits = 8, int stopbits = 1, int parity = 'N')
: device_path_(device_path), speed_(speed), flow_ctrl_(flow_ctrl),
databits_(databits), stopbits_(stopbits), parity_(parity) {}

Expand Down
13 changes: 6 additions & 7 deletions rmoss_base/src/transporter_driver/uart_transporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ namespace rmoss_base
bool UartTransporter::set_param(int speed, int flow_ctrl, int databits, int stopbits, int parity)
{
// 设置串口数据帧格式
int speed_arr[] = {B115200, B19200, B9600, B4800, B2400, B1200, B300};
int name_arr[] = {115200, 19200, 9600, 4800, 2400, 1200, 300};
int speed_arr[] =
{B1152000, B1000000, B921600, B576000, B500000, B460800, B230400, B115200, B19200, B9600,
B4800, B2400, B1200, B300};
int name_arr[] =
{1152000, 1000000, 921600, 576000, 500000, 460800, 230400, 115200, 19200, 9600, 4800, 2400,
1200, 300};
struct termios options;
// tcgetattr(fd,&options)得到与fd指向对象的相关参数,并将它们保存于options,该函数还可以测试配置是否正确,
// 该串口是否可用等。若调用成功,函数返回值为0,若调用失败,函数返回值为1.
Expand Down Expand Up @@ -156,11 +160,6 @@ bool UartTransporter::open()
error_message_ = "fcntl failed";
return false;
}
// 测试是否为终端设备
if (0 == isatty(STDIN_FILENO)) {
error_message_ = "standard input is not a terminal device";
return false;
}
// 设置串口数据帧格式
if (!set_param(speed_, flow_ctrl_, databits_, stopbits_, parity_)) {
return false;
Expand Down

0 comments on commit 9a75ac8

Please sign in to comment.