I'm writing a simple emulator for a serial device using a pseudo tty (under Linux). The program that writes to the serial device, writes to the slave side while the emulator (this program) is on the master side.
I create the usual master/slave pair with:
posix_openpt
grantpt
unlockpt
I then create a soft link in /tmp/emulator to whatever ptsname returns. A minor issue is that when the slave closes, select returns and read() returns EIO. Which is somewhat annoying so I open ptsname myself to prevent this (I do the same with pipes usually).
I use tcsetattr to set ICANON on the master side so I (should) read a line at a time. The protocol is line based.
So far so good. Except it doesn't work as expected. If send a single byte to the slave side of the PTY, the select() returns and read() reads that one byte. That's not canonical at all! It's supposed to wait until a \n is received!
I will test with an actual serial port and an Arduino to see if this happens there too.