aboutsummaryrefslogtreecommitdiffstats
path: root/sercp.c
diff options
context:
space:
mode:
authorPavel Vymetálek <pavel@vym.cz>2020-04-06 16:30:04 +0200
committerPavel Vymetálek <pavel@vym.cz>2020-04-06 16:30:04 +0200
commit3159ad30681e16943b42f43ba6fc57fcb2d8e713 (patch)
treec87716667d265a9be0b75d19e33ce2e261617d98 /sercp.c
parent18699ca29d46d87d94ea8623148457157389f4ce (diff)
downloadsercp-pc-3159ad30681e16943b42f43ba6fc57fcb2d8e713.tar.gz
Fix serial port initialization
Diffstat (limited to 'sercp.c')
-rw-r--r--sercp.c25
1 files 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);