Search code examples
linuxserial-portttyserial-communicationpty

How to configure virtual serial port's baud rate


I created a serial port by using socat PTY,link=/tmp/ttys0,raw,echo=0 PTY,link=/tmp/ttys1,raw,echo=0 & I think it created 2 PTY under /dev and let /tmp/ttys0 and /tmp/ttys1 pointing to them.

% ls -ltr /tmp/

lrwxr-xr-x 1 hankboyu wheel 12 Mar 1 13:22 ttys0 -> /dev/ttys009

lrwxr-xr-x 1 hankboyu wheel 12 Mar 1 13:22 ttys1 -> /dev/ttys010

Now I want to change the baud rate of the serial ports from default value 9600 to 115200, how do I do that?

Also, do I need to change the baud rate on all 4 file descriptors?

The virtual serial port was created for 2 micro-services to communicates with each other, each micro-service listens on different PTY.


Solution

  • You may apply Socat option b115200 when creating the PTYs.

    With something like

    stty -f /dev/ttys009 115200

    it might be possible to change the speed afterwards.