Re: Help serial port communication
"Jens B. Jorgensen" <jjorgens@bdsinc.com> writes:
> Here's some code you can build on:
>
> struct termios ti;
> int modem;
>
> modem = open("/dev/ttyS1", O_RDWR, 0);
I think it's generally necessary to do O_RDWR|O_NONBLOCK to open a
disconnected serial port, then set CLOCAL with termios, and finally
turn off O_NONBLOCK with fcntl. Of course, for just setting the speed
it should be enough to change the open().
> ioctl(modem, TCGETS, &ti); /* fill the termios struct with the current settings */
> cfsetispeed(&ti, B9600); /* set input speed to 9600, could be B300 - B230400 */
> cfsetospeed(&ti, B9600); /* set output speed */
> ioctl(modem, TCSETS, &ti);
> close(modem);
I prefer to use tcgetattr and tcsetattr than ioctl, although the end
result is exactly the same.
> You can check out the termios man page for more details.
Although it describes *how* to do it, it's a bit short on what and
why. You could try looking at the source for things like minicom, dip
and pppd.
--
Carey Evans http://home.clear.net.nz/pages/c.evans/
GNU GPL: "The Source will be with you... always."
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: