Skip to content

Commit 12bd098

Browse files
committed
Merge pull request #1668 from Lauszus/ide-1.5.x-upstream2
Can now detect devices with serial number in the port number on OSX
2 parents 0d8e12d + 7706fcf commit 12bd098

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app/src/processing/app/macosx/SystemProfilerParser.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class SystemProfilerParser {
1414
private static final String VID = "vid";
1515
private static final String PID = "pid";
1616
private static final String SERIAL_NUMBER = "serial_number";
17-
private static final String DEV_TTY = "/dev/tty.";
17+
private static final String DEV_TTY_USBSERIAL = "/dev/tty.usbserial-";
18+
private static final String DEV_CU_USBSERIAL = "/dev/cu.usbserial-";
1819
private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem";
1920
private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem";
2021

@@ -34,7 +35,11 @@ public String extractVIDAndPID(String output, String serial) throws IOException
3435
BufferedReader reader = new BufferedReader(new StringReader(output));
3536

3637
String devicePrefix;
37-
if (serial.startsWith(DEV_TTY)) {
38+
if (serial.startsWith(DEV_TTY_USBSERIAL)) {
39+
devicePrefix = DEV_TTY_USBSERIAL;
40+
} else if (serial.startsWith(DEV_CU_USBSERIAL)) {
41+
devicePrefix = DEV_CU_USBSERIAL;
42+
} else if (serial.startsWith(DEV_TTY_USBMODEM)) {
3843
devicePrefix = DEV_TTY_USBMODEM;
3944
} else {
4045
devicePrefix = DEV_CU_USBMODEM;
@@ -50,15 +55,24 @@ public String extractVIDAndPID(String output, String serial) throws IOException
5055

5156
if ((matcher = serialNumberRegex.matcher(line)).matches()) {
5257
device.put(SERIAL_NUMBER, matcher.group(1));
53-
} else if ((matcher = locationRegex.matcher(line)).matches()) {
54-
String devicePath = devicePrefix;
58+
if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) {
59+
String devicePath = devicePrefix + matcher.group(1);
60+
device.put(DEVICE_PATH, devicePath);
61+
}
62+
} else if ((serial.startsWith(DEV_TTY_USBMODEM) || serial.startsWith(DEV_CU_USBMODEM)) && (matcher = locationRegex.matcher(line)).matches()) {
5563
String suffix = matcher.group(1).substring(2, 6).replaceAll("0", "");
56-
devicePath = devicePath + suffix + "1";
64+
String devicePath = devicePrefix + suffix + "1";
5765
device.put(DEVICE_PATH, devicePath);
5866
} else if ((matcher = pidRegex.matcher(line)).matches()) {
59-
device.put(PID, matcher.group(1));
67+
String pid = matcher.group(1);
68+
if (pid.indexOf(" ") > 0)
69+
pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number
70+
device.put(PID, pid);
6071
} else if ((matcher = vidRegex.matcher(line)).matches()) {
61-
device.put(VID, matcher.group(1));
72+
String vid = matcher.group(1);
73+
if (vid.indexOf(" ") > 0)
74+
vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number
75+
device.put(VID, vid);
6276
} else if (line.equals("")) {
6377
if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) {
6478
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();

app/test/processing/app/macosx/SystemProfilerParserTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ public void shouldCorrectlyParse() throws Exception {
4343

4444
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem24131"));
4545
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131"));
46+
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV"));
47+
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV"));
4648
}
4749
}

0 commit comments

Comments
 (0)