1
+ /*
2
+ * This file is part of Arduino.
3
+ *
4
+ * Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5
+ *
6
+ * Arduino is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ *
20
+ * As a special exception, you may use this file as part of a free software
21
+ * library without restriction. Specifically, if other files instantiate
22
+ * templates or use macros or inline functions from this file, or you compile
23
+ * this file and link it with other files to produce an executable, this
24
+ * file does not by itself cause the resulting executable to be covered by
25
+ * the GNU General Public License. This exception does not however
26
+ * invalidate any other reasons why the executable file might be covered by
27
+ * the GNU General Public License.
28
+ */
29
+
1
30
package processing .app .windows ;
2
31
3
32
import java .io .BufferedReader ;
8
37
9
38
/**
10
39
* Interprets the output of listComPorts.exe
11
- * <p/ >
40
+ * <p>
12
41
* https://github.com/todbot/usbSearch/
13
42
*/
14
43
public class ListComPortsParser {
@@ -25,9 +54,11 @@ public String extractVIDAndPID(String output, String serial) throws IOException
25
54
BufferedReader reader = new BufferedReader (new StringReader (output ));
26
55
String line ;
27
56
while ((line = reader .readLine ()) != null ) {
28
- if (line .startsWith (serial .toUpperCase ())) {
29
- Matcher vidMatcher = vidRegExp .matcher (line );
30
- Matcher pidMatcher = pidRegExp .matcher (line );
57
+ String [] lineParts = line .split (" " );
58
+ if (lineParts .length > 0 && lineParts [0 ].toUpperCase ().equals (serial .toUpperCase ())) {
59
+ String vidPidPart = lineParts [lineParts .length - 1 ];
60
+ Matcher vidMatcher = vidRegExp .matcher (vidPidPart );
61
+ Matcher pidMatcher = pidRegExp .matcher (vidPidPart );
31
62
if (vidMatcher .find () && pidMatcher .find ()) {
32
63
return ("0x" + vidMatcher .group (1 ) + "_0x" + pidMatcher .group (1 )).toUpperCase ();
33
64
}
0 commit comments