@@ -14,7 +14,8 @@ public class SystemProfilerParser {
14
14
private static final String VID = "vid" ;
15
15
private static final String PID = "pid" ;
16
16
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-" ;
18
19
private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem" ;
19
20
private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem" ;
20
21
@@ -34,7 +35,11 @@ public String extractVIDAndPID(String output, String serial) throws IOException
34
35
BufferedReader reader = new BufferedReader (new StringReader (output ));
35
36
36
37
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 )) {
38
43
devicePrefix = DEV_TTY_USBMODEM ;
39
44
} else {
40
45
devicePrefix = DEV_CU_USBMODEM ;
@@ -50,15 +55,24 @@ public String extractVIDAndPID(String output, String serial) throws IOException
50
55
51
56
if ((matcher = serialNumberRegex .matcher (line )).matches ()) {
52
57
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 ()) {
55
63
String suffix = matcher .group (1 ).substring (2 , 6 ).replaceAll ("0" , "" );
56
- devicePath = devicePath + suffix + "1" ;
64
+ String devicePath = devicePrefix + suffix + "1" ;
57
65
device .put (DEVICE_PATH , devicePath );
58
66
} 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 );
60
71
} 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 );
62
76
} else if (line .equals ("" )) {
63
77
if (device .containsKey (DEVICE_PATH ) && device .get (DEVICE_PATH ).equals (serial )) {
64
78
return (device .get (VID ) + "_" + device .get (PID )).toUpperCase ();
0 commit comments