|
|
谁能提供关于RS232串口通信的源代码?(UNIX)(AIX)
| mengwg 回复于:2003-07-20 20:34:57
| 参考一下
[code:1:29ae1537aa]
int OpenComm(char * commstr,char * boundstr)
{
struct termio t;
char filename[20];
int comid;
#ifndef SCOUNIX_SYS
sprintf(filename, "/dev/tty%s", commstr);
#else
sprintf(filename, "/dev/tty%da", (*commstr) - 'a' + 1);
#endif
comid=(int)(tolower(*commstr)-'a');
if(comid<0||comid>10)
{
printf("system unable to open %s!\n", filename);
return 0;
}
if((INFO.CommFd[comid] = open(filename, O_RDWR )) < 0)
{
printf("system unable to open %s!\n", filename);
return 0;
};
if(ioctl(INFO.CommFd[comid], TCGETA, &t) < 0)
{
printf("system unable to open %s!\n", filename);
return 0;
};
if(fcntl(INFO.CommFd[comid],F_SETFL,O_NDELAY)<0)
{
printf("system unable to open %s!\n", filename);
return 0;
};
t.c_cflag = CLOCAL | PARENB | CS7 | CREAD |ChkBound(boundstr);
t.c_iflag = IGNCR |BRKINT | IGNPAR | IXON | IXANY | IXOFF;
t.c_oflag = OPOST ;
t.c_lflag = 0;
t.c_line = 0;
t.c_cc[4] = 1;
if(ioctl(INFO.CommFd[comid], TCSETA, &t) < 0)
{
printf("system unable to open %s!\n", filename);
close(INFO.CommFd[comid]);
return 0;
}
printf("system open %s: handle: %d successfully!\n", filename,INFO.CommFd[comid]);
return 1;
}
[/code:1:29ae1537aa]
| | liuqingzhu 回复于:2003-07-21 14:08:32
| 谢谢你!
你能把详细的代码写出来吗?
我是指正常的通信(READ,WRITE,SEND,OPEN);
谢谢!
| | wayne168 回复于:2003-07-24 10:52:37
| 网上太多了,去搜一下吧。
| |
|