
Ubuntu下Linux COM串口应用例程源码
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本资源提供在Ubuntu Linux环境下进行COM串口编程的应用示例源代码,涵盖基本配置、数据收发等操作,适合初学者学习和参考。
Linux(Ubuntu)COM串口应用例程源码:
/* 打开串口函数 */
int open_port(int com_port)
{
int fd;
#if (COM_TYPE == GNR_COM)
char *dev[] = {/dev/ttyS0, /dev/ttyS1, /dev/ttyS2};
#else
char *dev[] = {/dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2};
#endif
if ((com_port < 0) || (com_port > MAX_COM_NUM)) {
return -1;
}
fd = open(dev[com_port - 1], O_RDWR|O_NOCTTY|O_NDELAY);
if (fd < 0) {
perror(open serial port);
return(-1);
}
/* 恢复串口为阻塞状态 */
if (fcntl(fd, F_SETFL, 0) < 0) {
perror(fc);
return -1;
}
return fd;
}
全部评论 (0)
还没有任何评论哟~


