Portability for setting baud rate
Serial port logger which can be used to print to stdout.
Brought to you by:
jame
From a04cbf4ec4009b8690a823049564df2cda120d93 Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson gnu@gisladisker.se
Date: Sun, 22 Apr 2012 03:43:19 +0200
Subject: [PATCH] Portability for setting baud rate.
Portability needs cfsetispeed() and cfsetospeed().
Succesful on OpenSolaris, OpenBSD, FreeBSD, NetBSD,
and DragonFly BSD. Clean compilation on all after
inclusion of <strings.h> to get bzero() on Solaris.</strings.h>
ttylog.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/ttylog.c b/ttylog.c
index 1bc1fae..f7817ee 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
@@ -125,10 +126,13 @@ main (int argc, char *argv[])
tcgetattr (fd, &oldtio); /* save current serial port settings */
bzero (&newtio, sizeof (newtio)); /* clear struct for new port settings */
- newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
+ newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNCR;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
+ /* Only truly portable method of setting speed. */
+ cfsetispeed (&newtio, BAUD_B[baud]);
+ cfsetospeed (&newtio, BAUD_B[baud]);
tcflush (fd, TCIFLUSH);
tcsetattr (fd, TCSANOW, &newtio);
--
1.7.9.5
Anonymous
Diff:
Diff:
Diff:
Diff:
Plan to investigate adding this to version v0.2.0.
Diff:
Change to milestone BaudRate.
Released with verion 0.29.