시리얼통신 8바이트 보내기가 왜이렇게 힘들죠 -_-;;;

forevermc의 이미지

안녕하십니까.

시리얼 통신에서 read 값은 알필요가 없습니다. 단지!! 오로지!! 보내는것만 신경쓰면되는데

저는 그게 잘 안되는군요(초보자란...ㅠㅠ;;)

char buffer[8]; 을 보내야하는데 값은 헥사 값입니다.
0x00, 0xff, 0x04, 0x20, 0x00, 0x40, 0x44, NULL 이런식입니다.

시리얼 통신으로 제어하는 장치가 -_-;; 움직일때가 있고 안움직일때가 있습니다.

버퍼때문에 그런건가요? ㅡ0ㅡ;;

대략 수십번은 수행해줘야 움직이던데 ㅠ.ㅠ;; 왜그런거죠??

------------------ 아래 소스 에서 어디부분을 건드려야할까요? ----------
main()
{
int fd,c, res;
struct termios oldtio,newtio;
char buf[8];

buf[0]=0x00;
buf[1]=0xff;
buf[2]=0x04;
buf[3]=0x20;
buf[4]=0x00;
buf[5]=0x40;
buf[6]=0x44;

fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );

tcgetattr(fd,&oldtio);

bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;

newtio.c_lflag = 0;

newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 5;

tcflush(fd, TCOFLUSH);
tcsetattr(fd,TCSANOW,&newtio);

write(fd, buf, sizeof(buf));

tcsetattr(fd,TCSANOW,&oldtio);
}

----------------------------------------------------------------------------
도대체 왜이런건지 ㅠ.ㅠ;;;; 아... 소스 ㅠ.ㅠ;;;

서지훈의 이미지

buf[7]=0x00;

이게 빠졌네요.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <beer.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

forevermc의 이미지

안되는데 ㅡ0ㅡ

어떤 속성값을 수정해야만 하는건 아닐까요.. -_-

cshwang의 이미지

Hardware Flow Control를 사용하는지 여부를 확인하시고 사용하지
않는다면, newtio.c_cflag 에서 CRTSCTS를 제거해야 합니다.

forevermc의 이미지

어디 설정이 잘못되었을까요?/

혹시 버퍼때문이 아닐까요?

버퍼는 어떻게 다루는거죠?? ㅠㅠ.

익명사용자의 이미지

tcflush(fd, TCOFLUSH);
이 함수를 마지막에 한번 더 써줘야할 것 같고요.
fd 는 오픈 했으면 다시 클로즈해주세요~

kicom95의 이미지

이 게시판에서 비슷한 글 타래를 읽은 적이 있습니다

write 후에 sleep 를 하셔서 대기를 함 해보심이....

가자 해외로 ~ .. 돈 벌러.

익명사용자의 이미지

newtio.c_cc[VMIN] = 5;

이부분을

newtio.c_cc[VMIN] = 1;

이렇게...

forevermc의 이미지

아 정말 관심 많이 가져주셔서 감사합니다.
아직 정확한 원인을 못찾았지만^^

똑같은 경우가 나올수있으니 찾으면 여기에 반드시 리플올릴께요^^

모두 감사합니다~^0^

mach의 이미지

int writeN(int fd, char *buf, int len)
{
   int offset=0;
 
   while(1) {
      sent = write(fd, buf+offset, len-offset);
      if ( sent <= 0 ) {
          perror("write fail:");
          return -1;
      }
      else  {
         offset = offset + sent;
         if ( offset == len )
             return offset;
      }
   }
}
 
main()
{
....
// write(fd, buf, sizeof(buf));
writeN(fd, buf, sizeof(buf));
}

대략 이런식으로 해보세요.

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

forevermc의 이미지

sleep(1)을 write 하고난뒤에 주니까... 되기는 하는데.. 그게 -_-;;; 최초 한번만되요

하드웨어를 켜면 초기화(하드웨어가 알아서 초기화함) 하고난뒤에 write 하면 명령은 한번은 먹혀요 ㅡ0ㅡ;

그런데 두번은 안먹힙니다 ㅡ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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.