社区
其他开发语言
帖子详情
*******关于 kylix下串口读写**********
piers
2003-09-21 09:23:24
linux下
可把串口当做文件/dev/ttyS0读写
但是在程序里设置波特率不知怎么做到
有没有类似mscomm的控件可用???
...全文
153
2
打赏
收藏
*******关于 kylix下串口读写**********
linux下 可把串口当做文件/dev/ttyS0读写 但是在程序里设置波特率不知怎么做到 有没有类似mscomm的控件可用???
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
piers
2003-09-29
打赏
举报
回复
thanks
swites
2003-09-22
打赏
举报
回复
mscomm是第三方控件,这里时没用的,用下面语句:
/* this is a test program for using serial port */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <time.h>
#include <string.h>
#define SER_DEV1 "/dev/ttyS0"
#define SER_DEV2 "/dev/ttyS1"
#define SER_DEV3 "/dev/ttyS2"
#define SER_DEV4 "/dev/ttyS3"
#define BR1 B19200
#define BR2 B9600
#define ESC 0x1b
#define CR 0x0d
#define LF 0x0a
static struct termios ser1_old, ser1_new;
/* open_port(device) -- open serial port */
int open_port(char *ser_port) {
int fd; /* port file descriptor */
fd = open(ser_port, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) {
printf ("open_port: Unable to open %s\n", SER_DEV1);
}
else fcntl(fd, F_SETFL, 0);
return (fd);
}
void init_port(int port_id) {
tcgetattr(port_id, &ser1_old); /* get the struct for old port settings */
bzero(ser1_new, sizeof(ser1_new)); /* clear struct for new port settings */
cfsetispeed(&ser1_new, BR1);
cfsetospeed(&ser1_new, BR1);
ser1_new.c_cflag |= (CLOCAL | CREAD); /* enable receiving, local state */
ser1_new.c_cflag &= ~PARENB;
ser1_new.c_cflag &= ~CSTOPB;
ser1_new.c_cflag &= ~CSIZE;
ser1_new.c_cflag |= CS8; /* set 8N1 */
ser1_new.c_cflag &= ~CRTSCTS; /* no flow control */
ser1_new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* raw data input */
// ser1_new.c_oflag &= ~OPOST; /* raw data output */
// ser1_new.c_lflag = ICANON; /* input mode: non-canonical, no echo */
ser1_new.c_oflag = 0; /* raw output data */
ser1_new.c_iflag = IGNPAR | ICRNL; /* raw input data */
ser1_new.c_cc[VMIN]=1;
ser1_new.c_cc[VTIME]=0;
tcflush(port_id, TCIFLUSH); /* flush the buffer */
tcsetattr(port_id, TCSANOW, &ser1_new); /* set the new parameters */
}
void restore_port(int port_id) {
tcsetattr(port_id, TCSANOW, &ser1_old); /* restore the old port settings */
}
论文研究-基于
Kylix
的
串口
通信程序设计.pdf
简单分析了Linux和Windows下
串口
通信的异同点,详细介绍了
Kylix
下
串口
通信参数的设置和
串口
的基本操作函数,并举一简单示例。
Linux下PC机
串口
与智能仪器间的数据通信.pdf
Linux下PC机
串口
与智能仪器间的数据通信.pdf
Delphi笔记整理(二)
◇[DELPHI]字符的加密与解密 function cryptstr(const s:string; stype: dword):string; var i: integer; fkey: integer; begin result:=''; case stype of 0: setpass; begin randomize; fkey := random($ff);
学习心得
最常见的20种VC++编译错误信息 1、fatal error C1010: unexpected end of file while looking for precompiled header directive。寻找预编译头文件路径时遇到了不该遇到的文件尾。(一般是没有#include "stdafx.h") 2、fatal error C1083: Cannot open inc
Linux 常用命令汇总--加了注释
目录 第一天 linux简介, 安装, 目录管理命令 第一章 linux简介 X-SHELL 软件的常用快捷键: ctrl+c 强制终止 ctrl+l 清屏 ctrl+u 从光标所在删除到行首 ctrl+a 光标移动到行首 ctrl+e 光标移动到行尾 LAMP: linux+apache+mysql+php php和asp都各有
其他开发语言
3,424
社区成员
15,623
社区内容
发帖
与我相关
我的任务
其他开发语言
其他开发语言 其他开发语言
复制链接
扫一扫
分享
社区描述
其他开发语言 其他开发语言
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章