From 3159ad30681e16943b42f43ba6fc57fcb2d8e713 Mon Sep 17 00:00:00 2001 From: Pavel Vymetálek Date: Mon, 6 Apr 2020 16:30:04 +0200 Subject: Fix serial port initialization --- sercp.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/sercp.c b/sercp.c index 21069bc..bd22357 100644 --- a/sercp.c +++ b/sercp.c @@ -65,7 +65,7 @@ #define FALSE 0 #define true 1 #define TRUE 1 -const char* _version = "v0.3.3"; +const char* _version = "v0.3.4"; // SERIAL FILE *tapout_fd = NULL; int is_outfile = 0; @@ -87,7 +87,7 @@ int scp = 0; int is_scp_read = 0; int is_continue = 1; -char MODEMDEVICE[64] = { +char SERIALDEVICE[128] = { #ifdef _WIN32 "\\\\.\\COM1" #else @@ -166,11 +166,11 @@ void TestArgs (int argc, char *argv[]) switch (c) { case 'd': #ifdef _WIN32 - sprintf(MODEMDEVICE, "\\\\.\\%s", optarg); + sprintf(SERIALDEVICE, "\\\\.\\%s", optarg); #else - sprintf(MODEMDEVICE, "%s", optarg); + sprintf(SERIALDEVICE, "%s", optarg); #endif - printf ("Serial port: %s\n", MODEMDEVICE); + printf ("Serial port: %s\n", SERIALDEVICE); break; case 'b': baud_rate = atoi(optarg); @@ -645,7 +645,7 @@ int OpenUart() { DCB sDCB; COMMTIMEOUTS sCommTimeouts; - serial_fd = CreateFile(MODEMDEVICE, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); + serial_fd = CreateFile(SERIALDEVICE, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (serial_fd == INVALID_HANDLE_VALUE) { return (-1); } @@ -683,9 +683,9 @@ int OpenUart() { #else struct termios oldtio, newtio; /* open the device to be non-blocking (read will return immediatly) */ - serial_fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + serial_fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); if (serial_fd < 0) { - perror(MODEMDEVICE); + perror(SERIALDEVICE); return(-1); } tcgetattr(serial_fd, &oldtio); /* save current port settings */ @@ -724,12 +724,13 @@ int OpenUart() { cfsetspeed(&newtio, baud_rate); #if defined (__APPLE__) || defined (BSD) // pro jabkace | CNEW_RTSCTS - newtio.c_cflag = CS8 | CLOCAL | CREAD | CCTS_OFLOW | CRTS_IFLOW; // CSTOPB - two stop bits NOT + newtio.c_cflag |= CS8 | CLOCAL | CREAD | CCTS_OFLOW | CRTS_IFLOW; // CSTOPB - two stop bits NOT #else - newtio.c_cflag = CS8 | CLOCAL | CREAD | CRTSCTS; + newtio.c_cflag |= CS8 | CLOCAL | CREAD | CRTSCTS; #endif - - printf ("Serial device: %s, communication speed is: %d Bd\n", MODEMDEVICE, baud_rate); + newtio.c_iflag &= ~(IXON | IXOFF | IXANY); + newtio.c_oflag &= ~(OPOST); + printf ("Serial device: %s, communication speed is: %d Bd\n", SERIALDEVICE, baud_rate); newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 0; tcsetattr(serial_fd, TCSANOW, &newtio); -- cgit