org.bidib.jbidibc.jserialcomm.PortIdentifierUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbidibc-jserialcomm Show documentation
Show all versions of jbidibc-jserialcomm Show documentation
jBiDiB jbidibc jserialcomm POM
package org.bidib.jbidibc.jserialcomm;
import java.util.ArrayList;
import java.util.List;
import org.bidib.jbidibc.messages.exception.InvalidLibraryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fazecast.jSerialComm.SerialPort;
public class PortIdentifierUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(PortIdentifierUtils.class);
public static List getPortIdentifiers() {
List portIdentifiers = new ArrayList();
try {
SerialPort serials[] = SerialPort.getCommPorts();
for (SerialPort serialPort : serials) {
portIdentifiers.add(serialPort.getSystemPortName());
}
}
catch (UnsatisfiedLinkError ule) {
LOGGER.warn("Get comm port identifiers failed.", ule);
throw new InvalidLibraryException(ule.getMessage(), ule.getCause());
}
catch (Error error) {
LOGGER.warn("Get comm port identifiers failed.", error);
throw new RuntimeException(error.getMessage(), error.getCause());
}
return portIdentifiers;
}
}