linux下串口的使用

您所在的位置:网站首页 linux使用串口 linux下串口的使用

linux下串口的使用

2023-12-28 07:08| 来源: 网络整理| 查看: 265

 

 

1、串口定义

       串行接口简称串口,也称串行通信接口(通常指COM接口),是采用串行通信方式的扩展接口。

2、Linux下的使用

在Linux下操作、控制串口是通过操作设备文件进行的,可在/dev目录下看到串口设备文件,如ttyS0、ttyS1等。在应该程序中操作串口可进行以下步骤:

打开串口

int comfd;

comfd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NONBLOCK);

      if (comfd

      int  i;

      int  status;

      struct termios  Opt;

      tcgetattr(fd, &Opt);

      for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++) {

             if (baud== name_arr[i]) {   

                    tcflush(fd, TCIOFLUSH);   

                    cfsetispeed(&Opt, baud_arr[i]);

                    cfsetospeed(&Opt, baud_arr[i]); 

                    status = tcsetattr(fd, TCSANOW, &Opt);

                    if (status != 0) {      

                



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3