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+
130package processing .app .windows ;
231
332import java .io .BufferedReader ;
837
938/**
1039 * Interprets the output of listComPorts.exe
11- * <p/ >
40+ * <p>
1241 * https://github.com/todbot/usbSearch/
1342 */
1443public class ListComPortsParser {
@@ -25,9 +54,11 @@ public String extractVIDAndPID(String output, String serial) throws IOException
2554 BufferedReader reader = new BufferedReader (new StringReader (output ));
2655 String line ;
2756 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 );
3162 if (vidMatcher .find () && pidMatcher .find ()) {
3263 return ("0x" + vidMatcher .group (1 ) + "_0x" + pidMatcher .group (1 )).toUpperCase ();
3364 }
0 commit comments