Hello,
A couple weeks ago I
got some help (from DJ Delorie) with respect to using termios to set
up,read from and write to ttyS2. This was very helpful for me but it seems that
cfsetispeed,cfsetospeed did not set the input and output baud rates to the speed
required. This may be something I am overlooking or unaware
of.
When I run my code,
It executes without errors but when I check the ttyS2 settings (using the
command line stty
-a -F /dev/ttyS2) it says the baud rate is 4800
instead of 19200 that I tried setting it to. Here is the setup part of the
code:
fd_ttyS2 = open_port();
tcgetattr (fd_ttyS2,&options);
i_speed = cfsetispeed(&options, B19200);
//setting input baud
o_speed =
cfsetospeed(&options, B19200); //setting output
baud
cfmakeraw(&attr);
options.c_iflag &= ~( INPCK |
IXON); // setting up input options
options.c_iflag |= IGNBRK;
options.c_lflag &= ~(ICANON | ECHO |
ECHOE | ISIG);
options.c_cflag &= ~ (PARENB | CSTOP |
CSIZE | CRTSCTS);
options.c_cflag |= (CS8 | CLOCAL
|CREAD);
options.c_oflag &=
~OPOST;
options.c_cc[VTIME] =
5; //wait half a second for data
set_attr = tcsetattr(fd_ttyS2, TCSANOW, &options); //set options
now
if (i_speed <
0)
fputs("Unable to set input speed!\n",
stderr);
if (o_speed <
0)
fputs("Unable to set output speed!\n",
stderr);
if (set_attr<
0)
fputs("Attempt to set attributes
failed!\n", stderr);
this is the output
seen when I check the settings using the command line:
# stty -a -F
/dev/ttyS2
speed 4800 baud;
rows 0; columns 0;
intr = ^C; quit =
^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 =
<undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase =
^W;
lnext = ^V; flush =
^O; min = 1; time = 5;
-parenb -parodd cs8
hupcl -cstopb cread clocal -crtscts
ignbrk -brkint
-ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon
-ixoff
-iuclc -ixany
-imaxbel
-opost -olcuc -ocrnl
onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
ff0
-isig -icanon
-iexten -echo -echoe echok -echonl -noflsh -xcase -tostop
-echoprt echoctl
echoke
#
Any help with this would be appreciated.
Thanks,
Nicole