mini2440 시리얼통신에서 read() 함수가 잘 안되네요
안녕하세요 질문이 있어서 글을 올립니다.
mini2440보드로 시리얼통신을 구현중에 있습니다.
보드에 원래 있는 DB9 포트를 통해 PC와 시리얼통신으로 데이터를 주고받는데
write()함수는 잘 되는데...(mini2440에서 PC로 데이터전송)
read()함수는 되지가 않아요 (PC에서 mini2440으로 데이터전송)
read()함수를 폴링방식으로 구현해서 수신버퍼에 데이터가 들어왔다는건 감지하는데
read()를 하면 읽는 값이 죄다 0 이네요............
이건 대체 무슨문제인지...
소스에는 문제가 없는것 같아요
같은 소스로 USB 포트에 USB to Serial 을 이용해서 시리얼통신을 하였을 땐 정상적으로 동작했었습니다.
---------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define dev_name "/dev/ttyUSB0"
int main(void)
{
int fd;
char buf[46];
int rdcnt;
int i=0;
int r_msg=0;
int STOP_flag = FALSE;
struct termios newtio, oldtio;
struct pollfd poll_events;
int poll_state;
fd = open( dev_name, O_RDWR | O_NOCTTY );
if ( fd < 0 )
{
printf( "Device OPEN FAIL %s\n", dev_name );
return -1;
}
memset(&newtio, 0, sizeof(newtio));
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_cflag = CS8|CLOCAL|CREAD; // NO-rts/cts
newtio.c_cflag |= B115200;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 10;
tcflush( fd, TCIFLUSH );
tcsetattr( fd, TCSANOW, &newtio );
poll_events.fd = fd;
poll_events.events = POLLIN|POLLERR;
poll_events.revents = 0;
while(1)
{
poll_state = poll( (struct pollfd*)&poll_events, 1, 1000 );
if( poll_state > 0 )
{
if( poll_events.revents & POLLIN )
{
rdcnt = read( fd, buf, sizeof(buf) );
printf(" received data : %s (%d)\n", buf, rdcnt);
tcflush( fd, TCIFLUSH );
}
if( poll_events.revents & POLLERR )
{
printf("error occur!!\n");
break;
}
}
}
close(fd);
return 0;
}
------------------------------------------------------------------------------------------------
답변 부탁드립니다 ㅠ
댓글 달기