리눅스 시리얼 통신 관련 질문 드립니다.

rma8806의 이미지

리눅스 시리얼 통신 관련 질문 드립니다.

# ls /dev
audio hdb loop6 mtdblock7 ptyp7 sdb3 ttyp6
audio1 hdb1 loop7 mtdr0 ram snd ttyp7
audio2 hdb2 mem mtdr1 ram0 spisd urandom
basic-io hdb3 misc mtdr2 ram1 tty vcs
console hdb4 mixer mtdr3 ram2 tty0 vcs1
cuam0 hdb5 mtd0 mtdr4 ram3 tty1 vcs2
cuam1 hdb6 mtd1 mtdr5 random tty2 vcs3
dsp hdb7 mtd2 mtdr6 rawctl tty3 vcs4
dsp1 input mtd3 mtdr7 rtc tty4 vcs5
dsp2 kmem mtd4 null rtc0 tty5 vcs6
fb lirc mtd5 printkA rtc1 tty6 vcs7
fb0 lircd mtd6 ptmx rtc2 tty7 vcsa
hda lircm mtd7 pts rtc3 ttyAM0 vcsa1
hda1 log mtdblock0 ptyp0 sda ttyAM1 vcsa2
hda2 loop0 mtdblock1 ptyp1 sda1 ttyp0 vcsa3
hda3 loop1 mtdblock2 ptyp2 sda2 ttyp1 vcsa4
hda4 loop2 mtdblock3 ptyp3 sda3 ttyp2 vcsa5
hda5 loop3 mtdblock4 ptyp4 sdb ttyp3 vcsa6
hda6 loop4 mtdblock5 ptyp5 sdb1 ttyp4 vcsa7
hda7 loop5 mtdblock6 ptyp6 sdb2 ttyp5 zero
#

리눅스가 올라간 임베디드 보드에서 시리얼 포트 ttyAM0을 통해서 외부 단말과 통신을 하려 합니다.

int m_hdivce=open("ttyAM0",O_RDWR | O_NOCTTY | O_NONBLOCK);

read() / write()...

그런데, read()로 데이터를 읽으면 시리얼에 읽을 데이터가 없으면 바로 -1을 리턴 하더라고요..

원하는 방식은 데이터가 올때 까지 블로킹 되어 있다가 데이터가 오면 return하는 방식으로 처리하고 싶고(계속 read로 읽으면 클럭 낭비니까..),

그리고 외부에서 메시지가 특정 오면 read()에 걸린 블럭킹을 해제 하고, 메시지 핸들러를 호출 하는 방향으로 가고 싶습니다.

윈도우에서는 read()하고 있다가 write()이벤트가 발생하면 이벤트 핸들러에서 write()동작을 하고 다시 read()를 하는 방식으로 구현을 했는데, 리눅스에서 하려니 좀 막막하네요. ^^;

어떤 함수를 사용해서 위의 메커니즘을 구현 해줄수 있을까요?

rma8806의 이미지

글이 3개나 등록 되었네요 ㅜㅜ

KLDP는 처음이라서 반복으로누르면 글이 다중 등록 되는지 몰랐네요 ^^;

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.