user6549804
user6549804

Reputation:

If you can use treat serial data as files in C++, what's the purpose of termios?

I heard you might be able to just do this like so:

ostream dev("tty.mydevice");
dev < "hi";

So, why do we need termios. In other words, what's the purpose of the code in this question?

Reading Serial Data From C (OSX /dev/tty)

Upvotes: 1

Views: 114

Answers (1)

user149341
user149341

Reputation:

termios provides functionality specific to serial ports and terminals which isn't available through standard I/O. For example, it allows for:

  • Setting the baud rate
  • Reading and writing control lines like RTS/CTS and sending break sequences
  • Configuring certain character translation options (local echo, CR/CRLF conversion, support for strange things like teletypes and hardcopy terminals)
  • Configuring the effect of control sequences in a terminal (to handle ^C, ^Z, etc)
  • Getting information about the foreground process in a terminal (job control)
  • Getting the window size of a terminal

Upvotes: 2

Related Questions