Serial port filter by name
This commit is contained in:
parent
fd2ff86476
commit
286d0f8a47
2 changed files with 12 additions and 3 deletions
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
|
@ -16,6 +16,7 @@ public class LEDControl {
|
|||
public static final int LED_NUM = WIDTH * HEIGHT;
|
||||
public static final int BAUD = 1000000;
|
||||
private static final int FRAME_MS = 40;
|
||||
private static final String SERIAL_NAME = "CH340";
|
||||
|
||||
|
||||
private SerialPort port;
|
||||
|
@ -86,7 +87,17 @@ public class LEDControl {
|
|||
private boolean connect() {
|
||||
SerialPort[] ports = SerialPort.getCommPorts();
|
||||
if (ports.length > 0) {
|
||||
port = SerialPort.getCommPorts()[0];
|
||||
port = null;
|
||||
for(SerialPort p : ports) {
|
||||
if(p.getDescriptivePortName().contains(SERIAL_NAME)){
|
||||
port = p;
|
||||
}
|
||||
}
|
||||
if(port == null){
|
||||
System.err.println("No Serial port matching name \""+SERIAL_NAME+"\" found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
System.out.println("Connect to " + port.getDescriptivePortName() + " " + port.getSystemPortName() + " ");
|
||||
port.setComPortParameters(BAUD, 8, 1, 0);
|
||||
if (port.openPort()) {
|
||||
|
|
Loading…
Reference in a new issue