- 论坛徽章:
- 0
|
dos下的串口通讯,
[quote]原帖由 "yanpg"]急需一个在dos下的串口通讯,大哥大姐帮忙呀,用c语言编 ?(我是菜鸟)[/quote 发表:
可以用c编,很容易的,可以找到这方面的资料,我给你一个参考程序
int init_serial(struct nread message1[],struct nread message2[])
{
int fd;
struct termios oflags,nflags,options;
fd=open("/dev/ttyS0",O_RDWR|O_NDELAY|O_NOCTTY);
if(fd<0)
{
printf("open GSM module failure!\n" ;
exit(1);
}
bzero(&options,sizeof(options));
options.c_cflag=CS8|CLOCAL|CREAD;
options.c_iflag=IGNPAR;
options.c_oflag=0;
options.c_lflag=0;
options.c_cc[VTIME]=20;
options.c_cc[VMIN]=0;
cfsetispeed( &options ,B9600);
cfsetospeed( &options ,B9600);
tcsetattr(fd,TCSANOW,&options);
printf("serial open\n" ;
} |
|