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 <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9