why virtual ports in linux don't change behavior when i change terminal attributes?

114 views Asked by At

i try to test serial communication using virtual-serial-ports in linux. these are the steps i do:

  1. create the virtual ports: socat -d -d pty,raw,echo=0 pty,raw,echo=0 & that allocate /dev/pts/1 and /dev/pts/2
  2. open connections from both sides and set different baudrates:
// from thread 1:
int fd1 = open("/dev/pts/1", O_RDWR | O_NOCTTY);
int baudrate = B115200;
struct termios newtio;
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = baudrate | CRTSCTS | CLOCAL | CREAD;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);

// from thread 2:
int fd2 = open("/dev/pts/2", O_RDWR | O_NOCTTY);
int baudrate = B9600;
struct termios newtio;
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = baudrate | CRTSCTS | CLOCAL | CREAD;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);

// notice that the baudrate is configured different
  1. start to communicate between them:
// from thread 1:
write(fd1, "test\n", 5);

// from thread 2:
read(fd2, buffer, MAX_RECEIVED_LEN);

and for some reason, the communication succeed although the baudrate is not the same. and even if i change any other attribute i still work. why doesn't it fail? is the virtual port doesn't simulate real serial communication?

0

There are 0 answers