On Thursday 27 January 2005 08:34, Paul Hewlett wrote:
On Thursday 27 January 2005 14:37, Jose Thadeu Cavalcante wrote:
IF in C use the fopen statement on the device ttyS0 viz:
FILE *fd = fopen("/dev/ttyS0","rw"); You don't really want to use C stdio for a serial device per se. The open(2) system call is better. int fd; fd = open("/dev/ttyS0", O_NOTTY); The you use the termios calls to set the baudrate, et. al. struct termios tios; /* termios structure */ rv = tcgetattr(fd, &tios); /* get current attributes to restore later */
Remember, that the terminal attributes are probably not going to be what you
want on that device. I mentioned a loop back earlier, but another test is
to use a modem. The modem responds to some ASCII commands. You could write
a little program to set the tty to noecho, and send a modem command to the
modem. The modem should respond.
Also note that unlike a block device, the terminal sends and receives a
stream of data. When you read, you may get less data than you plan to in a
single read.
--
Jerry Feldman