History

Merge remote-tracking branch 'upstream/master'

Philip Rosedale committed 13 years ago

Commit eedbb982 parents f39fa35 915d6e511 files · +198 −186Browse files

Showing the changes to interface/src/SerialInterface.cpp (1 of 11 files). Show all

Unified · Split

interface/src/SerialInterface.cpp+20−15
@@ -43,25 +43,29 @@ void SerialInterface::pair() { · 42 unmodified lines
4343 int matchStatus;
4444 regex_t regex;
4545
46− // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
47− if((devDir = opendir("/dev"))) {
48− while((entry = readdir(devDir))) {
49− regcomp(&regex, "tty\\.usb", REG_EXTENDED|REG_NOSUB);
50− matchStatus = regexec(&regex, entry->d_name, (size_t) 0, NULL, 0);
51− if (matchStatus == 0) {
52− char *serialPortname = new char[100];
53− sprintf(serialPortname, "/dev/%s", entry->d_name);
54−
55− initializePort(serialPortname, 115200);
56−
57− delete [] serialPortname;
46+ if (_failedOpenAttempts < 2) {
47+ // if we've already failed to open the detected interface twice then don't try again
48+
49+ // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
50+ if((devDir = opendir("/dev"))) {
51+ while((entry = readdir(devDir))) {
52+ regcomp(&regex, "tty\\.usb", REG_EXTENDED|REG_NOSUB);
53+ matchStatus = regexec(&regex, entry->d_name, (size_t) 0, NULL, 0);
54+ if (matchStatus == 0) {
55+ char *serialPortname = new char[100];
56+ sprintf(serialPortname, "/dev/%s", entry->d_name);
57+
58+ initializePort(serialPortname, 115200);
59+
60+ delete [] serialPortname;
61+ }
62+ regfree(&regex);
5863 }
59− regfree(&regex);
64+ closedir(devDir);
6065 }
61− closedir(devDir);
6266 }
63−#endif
6467
68+#endif
6569 }
6670
6771 // connect to the serial port
@@ -73,6 +77,7 @@ int SerialInterface::initializePort(char* portname, int baud) { · 5 unmodified lines
7377
7478 if (serialFd == -1) {
7579 printLog("Failed.\n");
80+ _failedOpenAttempts++;
7681 return -1; // Failed to open port
7782 }
7883 struct termios options;