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 | int matchStatus; | 46 | int matchStatus; |
| 47 | regex_t regex; | 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* | 49 | if (_failedOpenAttempts < 2) { |
| 50 | if((devDir = opendir("/dev"))) { | 50 | // if we've already failed to open the detected interface twice then don't try again |
| 51 | while((entry = readdir(devDir))) { | 51 | |
| 52 | regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | 52 | // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* |
| 53 | matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); | 53 | if((devDir = opendir("/dev"))) { |
| 54 | if (matchStatus == 0) { | 54 | while((entry = readdir(devDir))) { |
| 55 | char *serialPortname = new char[100]; | 55 | regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); |
| 56 | sprintf(serialPortname, "/dev/%s", entry->d_name); | 56 | matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); |
| 57 | 57 | if (matchStatus == 0) { | |
| 58 | initializePort(serialPortname, 115200); | 58 | char *serialPortname = new char[100]; |
| 59 | 59 | sprintf(serialPortname, "/dev/%s", entry->d_name); | |
| 60 | delete [] serialPortname; | 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 | // connect to the serial port | 74 | // connect to the serial port |