主题 : QQ2440  串口超级终端不能输出 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 7847
精华: 0
发帖: 3
金钱: 30 两
威望: 30 点
综合积分: 6 分
注册时间: 2009-07-30
最后登录: 2017-09-13
楼主  发表于: 2009-07-30 22:06

 QQ2440  串口超级终端不能输出

管理提醒: 本帖被 qq2440 从 Linux技术交流专区 移动到本区(2009-07-31)

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdlib.h>



int main (void)
{
char buff[]="RS232 Communication\n";
int nread;

int fd;

int status;

int nSpeed, nBits, nStop;
char nEvent;

struct termios newtio, oldtio;





fd=open( "/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY);
if (-1==fd)
{
perror("cann't open serial port 0\n");
}
else printf("open com0 ok\n");





if (tcgetattr( fd, &oldtio) !=0){
perror("setupserial 1");
return -1;
}

bzero(&newtio, sizeof(newtio));
newtio.c_cflag |= CLOCAL|CREAD;
newtio.c_cflag &= ~CSIZE;

newtio.c_cflag |= CS8;
newtio.c_cflag &=~ PARENB;
cfsetispeed(&newtio, B115200);
cfsetospeed(&newtio, B115200);
newtio.c_cflag &= ~CSTOPB;

newtio.c_cc[VTIME]=0;
newtio.c_cc[VMIN]=0;
tcflush(fd, TCIFLUSH);
if((tcsetattr(fd, TCSANOW, &newtio)) !=0)
{
perror("com set error");
return -1;
}

printf("set done!\n");


write(fd,buff,19);

}



生成rs232 bin 文件后

./rs232

然后直接输出RS232 Communication,而不是在超级终端什么也没收到...别外/dev下只有tty,没有tty1,tty2?

*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-07-30 23:18

 Re:QQ2440 串口超级终端不能输出

然后直接输出RS232 Communication,而不是在超级终端什么也没收到...

这句中文语法太强了...
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 7847
精华: 0
发帖: 3
金钱: 30 两
威望: 30 点
综合积分: 6 分
注册时间: 2009-07-30
最后登录: 2017-09-13
2楼  发表于: 2009-07-31 18:22

 Re:QQ2440 串口超级终端不能输出

不好意思,改正一下:
1. 运行rs232程序后,buff里内容直接显示出来, 在电脑超级终端没收到内容.
2. 在QQ2440 /dev 下没有串口1和串口2的? 谢谢.
级别: 新手上路
UID: 7847
精华: 0
发帖: 3
金钱: 30 两
威望: 30 点
综合积分: 6 分
注册时间: 2009-07-30
最后登录: 2017-09-13
3楼  发表于: 2009-08-01 11:41

 Re:QQ2440 串口超级终端不能输出

已经解决