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
43 int matchStatus;43 int matchStatus;
44 regex_t regex;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*46 if (_failedOpenAttempts < 2) {
47 if((devDir = opendir("/dev"))) {47 // if we've already failed to open the detected interface twice then don't try again
48 while((entry = readdir(devDir))) {48
49 regcomp(&regex, "tty\\.usb", REG_EXTENDED|REG_NOSUB);49 // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
50 matchStatus = regexec(&regex, entry->d_name, (size_t) 0, NULL, 0);50 if((devDir = opendir("/dev"))) {
51 if (matchStatus == 0) {51 while((entry = readdir(devDir))) {
52 char *serialPortname = new char[100];52 regcomp(&regex, "tty\\.usb", REG_EXTENDED|REG_NOSUB);
53 sprintf(serialPortname, "/dev/%s", entry->d_name);53 matchStatus = regexec(&regex, entry->d_name, (size_t) 0, NULL, 0);
54 54 if (matchStatus == 0) {
55 initializePort(serialPortname, 115200);55 char *serialPortname = new char[100];
56 56 sprintf(serialPortname, "/dev/%s", entry->d_name);
57 delete [] serialPortname;57
58 initializePort(serialPortname, 115200);
59
60 delete [] serialPortname;
61 }
62 regfree(&regex);
58 }63 }
59 regfree(&regex);64 closedir(devDir);
60 }65 }
61 closedir(devDir);
62 }66 }
63#endif
64 67
68#endif
65}69}
66 70
67// connect to the serial port71// connect to the serial port
@@ -73,6 +77,7 @@ int SerialInterface::initializePort(char* portname, int baud) { · 5 unmodified lines
73 77
74 if (serialFd == -1) {78 if (serialFd == -1) {
75 printLog("Failed.\n");79 printLog("Failed.\n");
80 _failedOpenAttempts++;
76 return -1; // Failed to open port81 return -1; // Failed to open port
77 } 82 }
78 struct termios options;83 struct termios options;