mini2440 시리얼통신에서 read() 함수가 잘 안되네요

hello0711의 이미지

안녕하세요 질문이 있어서 글을 올립니다.

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;
}

------------------------------------------------------------------------------------------------

답변 부탁드립니다 ㅠ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.