리눅스 시리얼 통신 중입니다.
글쓴이: gksendbs / 작성시간: 화, 2012/10/30 - 4:57오후
디바이스는 안드로이드기기인데 리눅스를 깔아놨구요
장치명은 ttyUSB0입니다.
그냥 이 디바이스로부터 들어오는 데이터를 읽기만 하면 됩니다.
그래서 저는 시리얼로 기기에서 보내는 데이터를 받고 싶은데
컴파일되고 실행도 되는데 실행하면 아무것도 뜨지 않습니다.
가만히 기다리면 segmentation fault가 뜹니다.
고수님들 도와주세요.ㅜㅜ
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/signal.h>
#include<sys/ioctl.h>
#include<sys/poll.h>
#include<termios.h>
int main(){
int fd,rdcnt;
char cc,buf[128];
struct termios newtio;
fd=open("/dev/ttyUSB0",O_RDWR|O_NOCTTY);
if(fd<0){
printf("device open fail /dev/tty0");
}
memset(&newtio,0,sizeof(newtio));
// newtio.c_iflag=IGNPAR;
newtio.c_oflag=0;
newtio.c_cflag=B115200|CS8|CLOCAL|CREAD;
newtio.c_lflag=IGNPAR;
newtio.c_cc[VTIME]=0;
newtio.c_cc[VMIN]=1;
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
while(1)
{
rdcnt=read(fd,&buf,1);
if(rdcnt>0){
buf[rdcnt]='\0';
printf("<%s rc=/dev/tty0>%s\n",
rdcnt,buf);
fflush(stdout);
}
}
printf("Serial test end\n");
close(fd);
return 0;
}Forums:


rdcnt=read(fd,&buf,1);
rdcnt=read(fd,&buf,1); -> rdcnt=read(fd,buf,1); 가 맞는 거 같은데요?
댓글 달기