Showing the changes to interface/src/SerialInterface.cpp (1 of 20 files). Show all
Unified · Split
| @@ -46,25 +46,29 @@ void SerialInterface::pair() { · 45 unmodified lines | ||
| 46 | 46 | int matchStatus; |
| 47 | 47 | regex_t regex; |
| 48 | 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; | |
| 49 | + if (_failedOpenAttempts < 2) { | |
| 50 | + // if we've already failed to open the detected interface twice then don't try again | |
| 51 | + | |
| 52 | + // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* | |
| 53 | + if((devDir = opendir("/dev"))) { | |
| 54 | + while((entry = readdir(devDir))) { | |
| 55 | + regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | |
| 56 | + matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); | |
| 57 | + if (matchStatus == 0) { | |
| 58 | + char *serialPortname = new char[100]; | |
| 59 | + sprintf(serialPortname, "/dev/%s", entry->d_name); | |
| 60 | + | |
| 61 | + initializePort(serialPortname, 115200); | |
| 62 | + | |
| 63 | + delete [] serialPortname; | |
| 64 | + } | |
| 65 | + regfree(®ex); | |
| 61 | 66 | } |
| 62 | − regfree(®ex); | |
| 67 | + closedir(devDir); | |
| 63 | 68 | } |
| 64 | − closedir(devDir); | |
| 65 | 69 | } |
| 66 | −#endif | |
| 67 | 70 | |
| 71 | +#endif | |
| 68 | 72 | } |
| 69 | 73 | |
| 70 | 74 | // connect to the serial port |