- 论坛徽章:
- 0
|
#include
#include
#include
#include
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
int speed_arr[]={ B38400, B19200, B9600, B4800, B2400, B1200, B300,
B38400, B19200, B9600, B4800, B2400, B1200, B300,};
int name_arr[]={38400, 19200, 9600, 4800, 2400, 1200, 300,
38400, 19200, 9600, 4800, 2400, 1200, 300};
void set_speed(int fd,int speed)
{
struct termios term;
int i = 0;
int status = 0;
tcgetattr(fd,&term);//取得串口属性,终端也是文件,只是一种特殊的文件
for(i; i0)
set_speed(fd,19200);
else
{
printf("Can't Open Serial Port!\n");
exit(0);
}
if (set_parity(fd,8,1,'N')== FALSE)
{
printf("Set Parity Error\n");
exit(1);
}
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);
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/35079/showart_272442.html |
|