linux 시리얼 통신 도중 문제가 생깁니다.

rkakdrhfi의 이미지

    fd = OpenSerial(devName,baud,0,1);
    if(fd < 0 ) return -2;
    printf("Opend %s device\n",devName);
 
    sData.mode = 0x03;
    sData.type = 0;
    sData.number = 20;
    sData.data = writeData;
 
    sleep(1);
 
    buf[0]=0x01;
    buf[1]=0x03;
    buf[2]=0x00;
    buf[3]=0x00;
    buf[4]=0x00;
    buf[5]=0x14;
    buf[6]=0x45;
    buf[7]=0xC5;
    printf("Data sending test start....\n");
    for(idx=0;idx<10;++idx){
        count = 0;
        //WriteData(fd,&sData);
        printf("He");
        write(fd,buf,8);
        printf("llo");
        while(count<45){
            usleep(1000);
            printf("received data: ");
            rdcnt = read(fd,rxBuf+count,sizeof(rxBuf));
            printf("%2d_%2d\n",rdcnt,count);
            if(count == rdcnt+count){
                break;
            }
            count = rdcnt+count;
        }
        rxBuf[count] = '\0';
        printf("<%s rd=%2d> %s\n",devName, count,rxBuf);
        printf("I will sleep 100ms\n");
        usleep(100*1000);
        printf("I waked up\n");
    }
    printf("Data sending test end....\n");
 
    CloseSerial(fd);


int OpenSerial(char* devName, int baud, int vTime, int vMin)
{
    int fd;
    struct termios newtio;
    fd = open(devName, O_RDWR | O_NOCTTY);
    if( fd < 0 )
    {
        printf("Can`t open Device");
        return -1;
    }
 
    tcgetattr(fd,&oldtio);
 
    memset(&newtio, 0, sizeof(newtio));
    newtio.c_iflag = IGNPAR;
    newtio.c_oflag = 0;
    newtio.c_cflag = CS8 | CLOCAL | CREAD;
    switch( baud )
    {
        case 115200 : newtio.c_cflag |= B115200; break;
        case 57600 : newtio.c_cflag |= B57600; break;
        case 38400 : newtio.c_cflag |= B38400; break;
        case 19200 : newtio.c_cflag |= B19200; break;
        case 9600 : newtio.c_cflag |= B9600; break;
        case 4800 : newtio.c_cflag |= B4800; break;
        case 2400 : newtio.c_cflag |= B2400; break;
        default : newtio.c_cflag |= B115200; break;
    }
    newtio.c_lflag = 0;
    newtio.c_cc[VTIME] = vTime;
    newtio.c_cc[VMIN] = vMin;
    tcflush( fd, TCIFLUSH);
    tcsetattr( fd, TCSANOW, &newtio);
    return fd;
}
 
void CloseSerial(int fd)
{
    tcsetattr(fd,TCSANOW,&oldtio);
    close(fd);
}
 

현재 코드 상태는 이렇습니다. 프로그램 동작시 로그 내용은
Opend /dev/ttyUSB0 device
Data sending test start....
Helloreceived data:  1_ 0
received data: 12_ 1
received data: 12_13
received data: 11_25
received data:  9_36
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data: 11_ 0
received data: 12_11
received data: 11_23
received data: 11_34
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data: 10_ 0
received data: 11_10
received data: 12_21
received data: 11_33
received data:  1_44
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data:  8_ 0
received data: 11_ 8
received data: 12_19
received data: 14_31
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data:  6_ 0
received data: 11_ 6
received data: 12_17
received data: 11_29
received data:  5_40
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data:  4_ 0
received data: 12_ 4
received data: 11_16
received data: 12_27
received data:  6_39
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data:  3_ 0
received data: 11_ 3
received data: 12_14
received data: 11_26
received data:  8_37
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up
Helloreceived data:  1_ 0
received data: 11_ 1
received data: 12_12
received data: 11_24
received data: 10_35
</dev/ttyUSB0 rd=45>
I will sleep 100ms
I waked up

이렇게 나옵니다. 마지막 출력에서 I waked up 다음 멈추더라도 시리얼 통신 write전에 He 출력 후 write에서 멈추지 않을까 싶은데 바로 멈춰서 당황스럽네여... 혹시 이러한 멈춤 현상에 대해 해결방법이나 어디서 문제가 생기는지 궁금합니다.

댓글 달기

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