All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.jbidibc.jserialcomm.PortIdentifierUtils Maven / Gradle / Ivy

There is a newer version: 2.0.28
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy