From b4582f3209a4916ffaa54baa716ab27a87bb961a Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 27 Jun 2019 23:08:01 +0200 Subject: can accept incoming calls --- src/serial.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/serial.c') diff --git a/src/serial.c b/src/serial.c index 01f27bb..fe0f8f0 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,8 +1,4 @@ -#include -#include -#include -#include -#include +#include "serial.h" int set_interface_attribs (int fd, int speed, int parity) @@ -11,7 +7,7 @@ set_interface_attribs (int fd, int speed, int parity) memset (&tty, 0, sizeof tty); if (tcgetattr (fd, &tty) != 0) { - error_message ("error %d from tcgetattr", errno); + //error_message ("error %d from tcgetattr", errno); return -1; } @@ -39,7 +35,7 @@ set_interface_attribs (int fd, int speed, int parity) if (tcsetattr (fd, TCSANOW, &tty) != 0) { - error_message ("error %d from tcsetattr", errno); + //error_message ("error %d from tcsetattr", errno); return -1; } return 0; @@ -52,13 +48,35 @@ set_blocking (int fd, int should_block) memset (&tty, 0, sizeof tty); if (tcgetattr (fd, &tty) != 0) { - error_message ("error %d from tggetattr", errno); + //error_message ("error %d from tggetattr", errno); return; } tty.c_cc[VMIN] = should_block ? 1 : 0; tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout - if (tcsetattr (fd, TCSANOW, &tty) != 0) - error_message ("error %d setting term attributes", errno); + //if (tcsetattr (fd, TCSANOW, &tty) != 0) + //error_message ("error %d setting term attributes", errno); +} + +/* +... +char *portname = "/dev/ttyUSB1" + ... +int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); +if (fd < 0) +{ + error_message ("error %d opening %s: %s", errno, portname, strerror (errno)); + return; } + +set_interface_attribs (fd, B115200, 0); // set speed to 115,200 bps, 8n1 (no parity) +set_blocking (fd, 0); // set no blocking + +write (fd, "hello!\n", 7); // send 7 character greeting + +usleep ((7 + 25) * 100); // sleep enough to transmit the 7 plus + // receive 25: approx 100 uS per char transmit +char buf [100]; +int n = read (fd, buf, sizeof buf); // read up to 100 characters if ready to read +*/ -- cgit v1.2.3