unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ioctl_tty.2: Add example how to get or set baudrate on the serial port
@ 2021-07-30  9:53 Pali Rohár via Libc-alpha
  2021-07-30 11:47 ` Alejandro Colomar (man-pages) via Libc-alpha
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Pali Rohár via Libc-alpha @ 2021-07-30  9:53 UTC (permalink / raw)
  To: linux-man, Alejandro Colomar, Michael Kerrisk
  Cc: Marek Behún, libc-alpha

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 man2/ioctl_tty.2 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/man2/ioctl_tty.2 b/man2/ioctl_tty.2
index 0b0083c671a7..9d394572ae93 100644
--- a/man2/ioctl_tty.2
+++ b/man2/ioctl_tty.2
@@ -750,6 +750,66 @@ main(void)
     close(fd);
 }
 .EE
+.PP
+Get or set arbitrary baudrate on the serial port.
+.PP
+.EX
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <asm/termbits.h>
+
+int
+main(int argc, char *argv[])
+{
+#if !defined(TCGETS2) || !defined(TCSETS2) || !defined(BOTHER)
+    fprintf(stderr, "TCGETS2, TCSETS2 or BOTHER is unsupported\\n");
+    return 1;
+#else
+    struct termios2 tio2;
+    int fd, rc;
+
+    if (argc != 2 && argc != 3) {
+        fprintf(stderr, "Usage: %s device [new_baudrate]\\n", argv[0]);
+        return 1;
+    }
+
+    fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
+    if (fd < 0) {
+        perror("open");
+        return 1;
+    }
+
+    rc = ioctl(fd, TCGETS2, &tio2);
+    if (rc) {
+        perror("TCGETS2");
+        close(fd);
+        return 1;
+    }
+
+    printf("%u\\n", tio2.c_ospeed);
+
+    if (argc == 3) {
+        tio2.c_cflag &= ~CBAUD;
+        tio2.c_cflag |= BOTHER;
+        tio2.c_ospeed = tio2.c_ispeed = atoi(argv[2]);
+
+        rc = ioctl(fd, TCSETS2, &tio2);
+        if (rc) {
+            perror("TCSETS2");
+            close(fd);
+            return 1;
+        }
+    }
+
+    close(fd);
+    return 0;
+#endif
+}
+.EE
 .SH SEE ALSO
 .BR ldattach (1),
 .BR ioctl (2),
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2021-09-10 13:40 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30  9:53 [PATCH] ioctl_tty.2: Add example how to get or set baudrate on the serial port Pali Rohár via Libc-alpha
2021-07-30 11:47 ` Alejandro Colomar (man-pages) via Libc-alpha
2021-07-30 12:05   ` Pali Rohár via Libc-alpha
2021-07-30 12:21     ` Alejandro Colomar (man-pages) via Libc-alpha
2021-07-30 13:02 ` [PATCH v2] " Pali Rohár via Libc-alpha
2021-08-01 13:51 ` [PATCH v3] " Pali Rohár via Libc-alpha
2021-08-04 22:08   ` Pali Rohár via Libc-alpha
2021-08-05  5:52     ` Greg Kroah-Hartman via Libc-alpha
2021-08-05  8:22       ` Pali Rohár via Libc-alpha
2021-08-05  8:30         ` Greg Kroah-Hartman via Libc-alpha
2021-08-05  8:44           ` Pali Rohár via Libc-alpha
2021-08-05  8:50             ` Greg Kroah-Hartman via Libc-alpha
2021-08-05  9:51               ` Pali Rohár via Libc-alpha
2021-08-05 15:28                 ` Alejandro Colomar (man-pages) via Libc-alpha
2021-08-05 16:14                   ` Greg Kroah-Hartman via Libc-alpha
2021-08-05 16:45                     ` Licensing example programs in man-pages (was [PATCH v3] ioctl_tty.2: Add example how to get or set baudrate on the serial port) Alejandro Colomar (man-pages) via Libc-alpha
2021-08-05 17:54                       ` Greg Kroah-Hartman via Libc-alpha
2021-08-06  7:22                         ` Alejandro Colomar (man-pages) via Libc-alpha
2021-08-06  8:32                           ` Pali Rohár via Libc-alpha
2021-08-08  8:35   ` [PATCH v3] ioctl_tty.2: Add example how to get or set baudrate on the serial port Alejandro Colomar (man-pages) via Libc-alpha
2021-08-08 21:05     ` Pali Rohár via Libc-alpha
2021-08-08 21:19       ` Alejandro Colomar (man-pages) via Libc-alpha
2021-08-10 19:49 ` [PATCH v4] " Pali Rohár via Libc-alpha
2021-08-10 20:11   ` Pali Rohár via Libc-alpha
2021-08-31 20:34   ` Pali Rohár via Libc-alpha
2021-09-10 13:37     ` Alejandro Colomar (man-pages) via Libc-alpha
2021-09-10 13:39       ` Pali Rohár via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).