LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 809|回复: 5

兄弟帮我看可那错在那里

[复制链接]
发表于 2004-8-2 20:38:41 | 显示全部楼层 |阅读模式
#include <stdlib.h>
#include <stdlib.h>
#include <unsisted.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <erro.h>

#define BAUDRATE B19200

char *dev="/dev/ttys1";

void setup_com(int fd){
struct termios options;
tcgetattr(fd, &options);

/* Set the baud rates to 19200..*/
cfsetispeed(&options, BAUDRATE);
cfsetospeed(&options, BAUDRATE);

/* Enable the receiver and set local mode...*/
options.c_cflag |= (CLOCAL | CREAD);

/* Set c_cflag options.*/
options.c_cflag &= ~PARENB; //无校验
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB; //1个停止位
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8; //8个数据位

/* Set c_iflag input options */
options.c_iflag &=~(IXON | IXOFF | IXANY);
options.c_iflag &=~(INLCR | IGNCR | ICRNL);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

/* Set c_oflag output options */
options.c_oflag &= ~OPOST; //RAW数据模式

/* Set the timeout options */
options.c_cc[VMIN] = 10;
options.c_cc[VTIME] = 0;
tcsetattr(fd, TCSANOW, &options); //设置COM参数并立即生效
}


int main(int argc, char **argv)
{
int fd;
int nread;
char buff[512];
char *dev ="/dev/ttyS1";
fd = OpenDev(dev);
if (fd>0)
set_speed(fd,19200);
else
{
printf("Can't Open Serial Port!\n");
exit(0);
}

while(1)
{
while((nread = read(fd,buff,512))>0)
{
printf("\nLen %d\n",nread);
buff[nread+1]='\0';
printf("\n%s",buff);
}
}
//close(fd);
//exit(0);
}
发表于 2004-8-2 22:03:46 | 显示全部楼层
错误是什么?让我们猜吗?
 楼主| 发表于 2004-8-2 22:12:04 | 显示全部楼层
我也不知道。
发表于 2004-8-3 13:11:00 | 显示全部楼层
编译后的错误要贴出来啊
发表于 2004-8-3 13:20:00 | 显示全部楼层
病人:医生,帮我看看我得什么病了?
医生:你哪里不舒服?
病人:我也不知道。
医生:……#¥!#·^!!%@&
发表于 2004-8-3 13:20:14 | 显示全部楼层
病人:医生,帮我看看我得什么病了?
医生:你哪里不舒服?
病人:我也不知道。
医生:……#¥!#·^!!%@&
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表