linux两个进程同时打开串口,linux 串口多线程 读写

该博客介绍了如何在Linux环境下实现两个线程分别进行串口读写操作。通过创建线程并使用`pthread_create`,一个线程负责读取串口数据,另一个线程负责写入数据。代码示例中展示了如何打开串口、设置串口参数,并使用`read`和`write`函数进行数据传输。
摘要由CSDN通过智能技术生成

#include #define NUM 20

int fd;

void writeThread(void* arg);

void readThread(void* arg);

/*

int openport(void)

{

// int fd;

struct termios options;

if((fd=open("/dev/tts/0",O_RDWR|O_NOCTTY|O_NONBLOCK|O_NDELAY))==-1)

{

perror("Can't open serial1 port.");

return -1;

}

/* tcgetattr(fd,&options);

cfsetispeed(&options,B9600);

cfsetospeed(&options,B9600);

options.c_cflag|=(CLOCAL|CREAD); //忽略控制信号线和使能读功能

options.c_cflag|=PARENB; //奇偶检验

options.c_cflag&=~PARODD; //偶校验

options.c_iflag |= (INPCK | ISTRIP);

options.c_cflag|=CSTOPB; //两个停止位

options.c_cflag&=~CSIZE;

options.c_cflag|=CS8; //8个数据位

options.c_lflag&=~(ICANON|ECHO|ISIG); //原始输入模式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值