greadey
04-30-2001, 04:34 PM
Hi peeps, I am trying (must be a masochist) to write my own C-code to read and write to a serial port. One of my biggest problems is I have to understand why I'm doing something. So here we go;
the serial port is programmed with the use of the termios.h header which allows a struct of type termios to be defined. This struct contains the various flags to set serial port parameters. This much I have no problem with, what is bugging me is the way that the following is written;
newtio.c_cflag = BAUDRATE | CRTCTS | CS8 | CLOCAL | CREAD;
where newtio is predeclared as:-
struct termios newtio;
and BAUDRATE is #defined as "B9600".
c_cflag is obviously an array variable in newtio, what I don't understand is the apparently strange way of filling it. The code suggests to me that newtio.c_cflag can take any of the values assigned to it, and that termios.h knows which one it needs and where. Am I correct or way of base? If someone can help, this naive newbie would be very grateful.
greadey :confused:
the serial port is programmed with the use of the termios.h header which allows a struct of type termios to be defined. This struct contains the various flags to set serial port parameters. This much I have no problem with, what is bugging me is the way that the following is written;
newtio.c_cflag = BAUDRATE | CRTCTS | CS8 | CLOCAL | CREAD;
where newtio is predeclared as:-
struct termios newtio;
and BAUDRATE is #defined as "B9600".
c_cflag is obviously an array variable in newtio, what I don't understand is the apparently strange way of filling it. The code suggests to me that newtio.c_cflag can take any of the values assigned to it, and that termios.h knows which one it needs and where. Am I correct or way of base? If someone can help, this naive newbie would be very grateful.
greadey :confused: