On Sat, 31 Jul 2010 19:05:17 +0200, Andrea Crotti wrote:
>> Is it a serial interface or a USB interface? If you just want a serial
>> interface, use a pseudo-tty (pty). See e.g.:
>>
>> http://www.kernel.org/doc/man-pages/...an7/pty.7.html
>
> Mm not sure, it's a usb device but we simply write data with "write" on
> /dev/ttyUSB0.
> So I'm not really sure if it's the linux kernel that manages it or what
> really happens.
/dev/ttyUSB0 is a "terminal" device; typically a USB-to-RS232 converter,
although a wide variety of specialised USB devices use the CDC
(communication device class, i.e. "modem") interface, simply because
there's bound to be a suitable driver included in the OS.
For Linux, the main driver is cdc-acm.ko. This provides a serial
interface (/dev/ttyUSB*) for any device implementing the CDC interface.
I've used it to interface to PIC18 devices programmed with Microchip's
CDC implementation. From the perspective of a program accessing the
device, it looks just like a physical serial port.
A pseudo-TTY (pty) is similar to a socket pair (like a pipe, only
bi-directional), but implements the TTY line discipline (i.e. tcsetattr,
line-buffering, Ctrl-C/Ctrl-Z, etc). ptys are fundamental to any type of
"virtual terminal", including terminal emulators (xterm etc) and remote
login servers (telnetd, sshd, etc). They are needed any time that you need
to run a program with its stdin/stdout/stderr connected to something which
"looks like" a terminal.
The controlling application (e.g. xterm, sshd) creates and opens the
"master" device. It can then query the name of the slave device, which
will typically be /dev/pts/<N> (or, with the older BSD interface,
something like /dev/ttyp1). It can either open the slave itself and use it
for the std{in,out,err} of a child process (shell, login, whatever), or it
can just wait until something else explicitly opens it (e.g. manually
running "echo ... > /dev/pts/0" etc).