Showing the changes to interface/src/SerialInterface.cpp (1 of 11 files). Show all
Unified · Split
| @@ -43,25 +43,29 @@ void SerialInterface::pair() { · 42 unmodified lines | ||
| 43 | 43 | int matchStatus; |
| 44 | 44 | regex_t regex; |
| 45 | 45 | |
| 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(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | |
| 50 | − matchStatus = regexec(®ex, 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(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | |
| 53 | + matchStatus = regexec(®ex, 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(®ex); | |
| 58 | 63 | } |
| 59 | − regfree(®ex); | |
| 64 | + closedir(devDir); | |
| 60 | 65 | } |
| 61 | − closedir(devDir); | |
| 62 | 66 | } |
| 63 | −#endif | |
| 64 | 67 | |
| 68 | +#endif | |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | 71 | // connect to the serial port |
| @@ -73,6 +77,7 @@ int SerialInterface::initializePort(char* portname, int baud) { · 5 unmodified lines | ||
| 73 | 77 | |
| 74 | 78 | if (serialFd == -1) { |
| 75 | 79 | printLog("Failed.\n"); |
| 80 | + _failedOpenAttempts++; | |
| 76 | 81 | return -1; // Failed to open port |
| 77 | 82 | } |
| 78 | 83 | struct termios options; |