001package jmri.jmrix.purejavacomm;
002
003import jmri.jmrix.AbstractSerialPortController;
004
005/**
006 * Comm port identifier.
007 */
008public class CommPortIdentifier {
009
010    private final String _portName;
011
012    private CommPortIdentifier(String portName) {
013        this._portName = portName;
014    }
015
016    public static CommPortIdentifier getPortIdentifier(String portName) throws NoSuchPortException {
017        return new CommPortIdentifier(portName);
018    }
019
020    public SerialPort open(String appName, int timeout) throws PortInUseException, NoSuchPortException {
021        String systemPrefix = appName;
022        jmri.jmrix.SerialPort serialPort = AbstractSerialPortController.activatePort(
023                systemPrefix, _portName, log, 1, jmri.jmrix.SerialPort.Parity.NONE);
024
025        if (serialPort != null) {
026            return new SerialPort(serialPort);
027        } else {
028            throw new NoSuchPortException();
029        }
030    }
031
032    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CommPortIdentifier.class);
033}