Skip to content

Commit

Permalink
[C ser2tcp] clarify defaults & options, improving settings checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed May 9, 2023
1 parent aeb99f3 commit 9c6c4bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tools/ser2tcp/eg_c/ser2tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ static void usage (char *pname) {
" -h, --help print this help menu\n"
" -V, --version print version and exit\n"
" -v, --verbose print I/O read sizes\n"
" -c, --comport serial device name (mandatory)\n"
" -c, --comport <name> serial device name (mandatory)\n"
" -b, --baudrate <115200> serial baud rate\n"
" -d, --databits <8> serial databits 5|6|7|8\n"
" -s, --stopbits <One> serial stopbits [None|One|Two]\n"
" -p, --parity <None> serial parity [Even|None|Odd]\n"
" -i, --ip <localhost> Host name / Address\n"
" -t, --tcpport <5761> IP port\n"
" -z, --buffersize Buffersize (ignored)\n");
" -t, --tcpport <5762> IP port\n"
" -z, --buffersize <n> Buffersize (ignored)\n");
exit(1);
}

Expand Down
24 changes: 15 additions & 9 deletions tools/ser2tcp/eg_c/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ int open_serial(serial_opts_t *sopts) {
int fd;
fd = open(sopts->devname, O_RDWR|O_NOCTTY);
if(fd != -1) {
struct termios tio;
memset (&tio, 0, sizeof(tio));
int res;
struct termios tio;
memset (&tio, 0, sizeof(tio));
#ifdef __linux__
ioctl(fd, TCGETS, &tio);
res = ioctl(fd, TCGETS, &tio);
#else
tcgetattr(fd, &tio);
res = tcgetattr(fd, &tio);
#endif
if (res != -1) {
// cfmakeraw ...
tio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
tio.c_oflag &= ~OPOST;
Expand Down Expand Up @@ -157,14 +159,18 @@ int open_serial(serial_opts_t *sopts) {
}
}
#ifdef __linux__
ioctl(fd, TCSETS, &tio);
res = ioctl(fd, TCSETS, &tio);
#else
tcsetattr(fd,TCSANOW,&tio);
res = tcsetattr(fd,TCSANOW,&tio);
#endif
if(set_fd_speed(fd, sopts->baudrate) == -1) {
close(fd);
fd = -1;
if (res != -1) {
res = set_fd_speed(fd, sopts->baudrate);
if (res == -1) {
close(fd);
fd = -1;
}
}
}
}
return fd;
}

0 comments on commit 9c6c4bf

Please sign in to comment.