@@ -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 ();
0 commit comments