*  Added ability to find serial ports by device id
     - /dev/serial/by-id/
     - and the traditional /dev/tty...
pull/1/head
David Freese 2013-03-10 13:33:15 -05:00
rodzic 093796f7ce
commit 6e9a943a87
1 zmienionych plików z 21 dodań i 4 usunięć

Wyświetl plik

@ -57,6 +57,7 @@
# include <dirent.h>
# include <limits.h>
# include <errno.h>
# include <glob.h>
#endif
#ifdef __APPLE__
# include <glob.h>
@ -891,12 +892,11 @@ static bool open_serial(const char* dev)
void configuration::testCommPorts()
{
int retval;
// int retval;
inpTTYdev->clear();
inpRIGdev->clear();
inpXmlRigDevice->clear();
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
@ -908,6 +908,7 @@ void configuration::testCommPorts()
char ttyname[PATH_MAX + 1];
#endif
/*
#ifdef __linux__
bool ret = false;
DIR* sys = NULL;
@ -948,8 +949,7 @@ out:
return;
#endif // __linux__
// TODO: will the mingw probing work for cygwin too?
*/
const char* tty_fmt[] = {
#if defined(__linux__)
"/dev/ttyS%u",
@ -977,6 +977,23 @@ out:
# define TTY_MAX 4
#else
# define TTY_MAX 8
glob_t gbuf;
#endif
#ifdef __linux__
glob("/dev/serial/by-id/*", 0, NULL, &gbuf);
for (size_t j = 0; j < gbuf.gl_pathc; j++) {
if ( !(stat(gbuf.gl_pathv[j], &st) == 0 && S_ISCHR(st.st_mode)) ||
strstr(gbuf.gl_pathv[j], "modem") )
continue;
LOG_INFO("Found serial port %s", gbuf.gl_pathv[j]);
inpTTYdev->add(gbuf.gl_pathv[j]);
# if USE_HAMLIB
inpRIGdev->add(gbuf.gl_pathv[j]);
# endif
inpXmlRigDevice->add(gbuf.gl_pathv[j]);
}
globfree(&gbuf);
#endif
for (size_t i = 0; i < sizeof(tty_fmt)/sizeof(*tty_fmt); i++) {