Transcript

1.
9-1Chapter 9 Linux Serial ProgrammingArchitecturePort SettingsThe devices /dev/ttyS*All parameters can be easily configured from within a program. The configuration is stored in astructure struct termios, which is defined in <asm/termbits.h>:

2.
9-21. c_iflag handle all input processing, which means that the characters sent from the device can be processed before they are read with read.2. c_oflag handles the output processing. c_cflag contains the settings for the port, as the baudrate, bits per character, stop bits, etc..3. c_lflag determine if characters are echoed, signals are sent to your program, etc..4. c_cc defines the control characters for end of file, stop, etc.. Default values for the control characters are defined in <asm/termios.h>. Canonical Input ProcessingThis is the normal processing mode for terminals, which means that a read will only return afull line of input. A line is by default terminated by a NL (ASCII LF), an end of file, or an endof line character.

10.
9-10/* terminal settings done, now handle input In this example, inputting a z at the beginning of a line will exit the program.*/ while (STOP==FALSE) { /* loop until we have a terminating condition */ /* read blocks program execution until a line terminating character is input, even if more than 255 chars are input. If the number of characters read is smaller than the number of chars available, subsequent reads will return the remaining chars. res will be set to the actual number of characters actually read */ res = read(fd,buf,255); buf[res]=0; /* set end of string, so we can printf */ printf(":%s:%dn", buf, res); if (buf[0]==z) STOP=TRUE; } /* restore the old port settings */