baud rate설정이 올바른지..

leolo의 이미지

지금 baud rate설정이 올바른지 테스트하고 있습니다.
이렇게 하면 결과가 13으로 나오던데요..
올바르게 된건지 모르겠습니다.
제가 보기에는 올바른거 같은데요.. 왜 이렇게 나오죠..


#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>

int main() 
{
    int fd;
    static long baudrate;
    struct termios tio;
    
    fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK , 0644);
    if(fd < 0) {
        printf("Can't open device %s\n", "/dev/ttyS0");
        return -1;
    } else {
        printf("Open %s Device, fd %d : \n", "/dev/ttyS0", fd);
        
        bzero(&tio, sizeof(tio));
        
        baudrate = B9600;

        if((cfsetispeed(&tio, baudrate) < 0 || cfsetospeed(&tio, baudrate) < 0)){  /* baudrate set */
            printf("Can't set baudrate\n");
            close(fd);
            return -1;
        } else {
            if(tcsetattr(fd, TCSANOW, &tio) < 0){     /* termios set */
                printf("Can't set Termios struct\n");
                close(fd);
                return -1;
            } else {
                if(tcflush(fd, TCIOFLUSH) < 0){
                    close(fd);
                    return -1;
                }   
            } 
        }
   }
   printf("%d\n", tio.c_cflag & B9600);
   return fd;
}