- 论坛徽章:
- 0
|
int main( int argc, char *argv[])
{
int fd, nread;
ssize_t len;
int bitspeed=9600;
char buff[BUFSIZE];
char *dev ="/dev/ttyAM1";
switch (argc){
//case 3:
// strcpy(dev,argv[1]);
// bitspeed=(int)argv[2];
// break;
case 2:
strcpy(dev,argv[1]);
break;
case 1:
printf("No Argc ,used default value\n \
Port:/dev/ttyAM1 \n \
Speed:9600\n");
break;
default:
printf("Argc Error\n");
exit(-1);
}
fd = OpenDev(dev);
if (fd>0)
set_speed(fd,bitspeed);
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,BUFSIZE))>0)
{
//printf("\nLen %d\n",nread);
buff[nread]='\n';
//printf("\ns",buff);
if( write(STDOUT_FILENO,buff,nread) !=nread )
perror("write error");
}
}
//close(fd);
//exit(0);
}
我编译完了,没有报错,但一执行就出现段错误。我是这样打的
[root@localhost serial]# ./serial /dev/ttyS0
段错误
[root@localhost serial]#
忘高人指点,小弟刚入门,虚心请教!!
[ 本帖最后由 wzj071227 于 2008-8-20 12:28 编辑 ] |
|