use of gnu.io.NoSuchPortException in project jop by jop-devel.
the class JavaDown method openSerialPort.
/**
* Opens and configures a serial port
*
* @param commPortId
* @return
* @throws NoSuchPortException if the identifier does not specify a serial port
* @throws PortInUseException if the port is in use
* @throws UnsupportedCommOperationException if the settings are not supported
*/
private SerialPort openSerialPort(CommPortIdentifier commPortId) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException {
if (commPortId.getPortType() != CommPortIdentifier.PORT_SERIAL) {
throw new gnu.io.NoSuchPortException();
}
SerialPort serialPort = (SerialPort) commPortId.open(IJOPLaunchConfigurationConstants.COMM_PORT_OWNER_ID, SERIAL_PORT_TIMEOUT);
serialPort.setSerialPortParams(SERIAL_PORT_BAUDRATE, SERIAL_PORT_DATABITS, SERIAL_PORT_STOPBITS, SERIAL_PORT_PARITY);
return serialPort;
}
use of gnu.io.NoSuchPortException in project openhab1-addons by openhab.
the class PowerMaxSerialConnector method open.
/**
* {@inheritDoc}
**/
@Override
public void open() {
logger.debug("open(): Opening Serial Connection");
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.disableReceiveTimeout();
setInput(serialPort.getInputStream());
setOutput(serialPort.getOutputStream());
getOutput().flush();
if (getInput().markSupported()) {
getInput().reset();
}
setReaderThread(new SerialReaderThread(getInput(), this));
getReaderThread().start();
setConnected(true);
} catch (NoSuchPortException noSuchPortException) {
logger.debug("open(): No Such Port Exception: {}", noSuchPortException.getMessage());
setConnected(false);
} catch (PortInUseException portInUseException) {
logger.debug("open(): Port in Use Exception: {}", portInUseException.getMessage());
setConnected(false);
} catch (UnsupportedCommOperationException unsupportedCommOperationException) {
logger.debug("open(): Unsupported Comm Operation Exception: {}", unsupportedCommOperationException.getMessage());
setConnected(false);
} catch (UnsupportedEncodingException unsupportedEncodingException) {
logger.debug("open(): Unsupported Encoding Exception: {}", unsupportedEncodingException.getMessage());
setConnected(false);
} catch (IOException ioException) {
logger.debug("open(): IO Exception: ", ioException.getMessage());
setConnected(false);
}
}
use of gnu.io.NoSuchPortException in project openhab1-addons by openhab.
the class Connection method open.
/**
* Opens the serial port associated with this connection.
*
* @throws IOException
* if any kind of error occurs opening the serial port.
*/
public void open() throws IOException {
CommPortIdentifier portIdentifier;
try {
portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
} catch (NoSuchPortException e) {
throw new IOException("Serial port with given name does not exist", e);
}
if (portIdentifier.isCurrentlyOwned()) {
throw new IOException("Serial port is currently in use.");
}
// fixed issue as rxtx library originally used in j62056 does use
// different version of rxtx
// com port in their version is using gnu.io.CommPort
RXTXPort commPort;
try {
commPort = portIdentifier.open(this.getClass().getName(), 2000);
} catch (PortInUseException e) {
throw new IOException("Serial port is currently in use.", e);
}
if (!(commPort instanceof SerialPort)) {
commPort.close();
throw new IOException("The specified CommPort is not a serial port");
}
serialPort = commPort;
try {
os = new DataOutputStream(serialPort.getOutputStream());
is = new DataInputStream(serialPort.getInputStream());
} catch (IOException e) {
serialPort.close();
serialPort = null;
throw new IOException("Error getting input or output or input stream from serial port", e);
}
}
use of gnu.io.NoSuchPortException in project openhab1-addons by openhab.
the class SerialIOStream method open.
@Override
public boolean open() {
try {
updateSerialProperties(m_devName);
CommPortIdentifier ci = CommPortIdentifier.getPortIdentifier(m_devName);
CommPort cp = ci.open(m_appName, 1000);
if (cp instanceof SerialPort) {
m_port = (SerialPort) cp;
} else {
throw new IllegalStateException("unknown port type");
}
m_port.setSerialPortParams(m_speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
m_port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
logger.debug("setting port speed to {}", m_speed);
m_port.disableReceiveFraming();
m_port.enableReceiveThreshold(1);
// m_port.disableReceiveTimeout();
m_port.enableReceiveTimeout(1000);
m_in = m_port.getInputStream();
m_out = m_port.getOutputStream();
logger.info("successfully opened port {}", m_devName);
return true;
} catch (IOException e) {
logger.error("cannot open port: {}, got IOException ", m_devName, e);
} catch (PortInUseException e) {
logger.error("cannot open port: {}, it is in use!", m_devName);
} catch (UnsupportedCommOperationException e) {
logger.error("got unsupported operation {} on port {}", e.getMessage(), m_devName);
} catch (NoSuchPortException e) {
logger.error("got no such port for {}", m_devName);
} catch (IllegalStateException e) {
logger.error("got unknown port type for {}", m_devName);
}
return false;
}
use of gnu.io.NoSuchPortException in project openhab1-addons by openhab.
the class SerialConnector method open.
/**
* {@inheritDoc}
**/
public void open() {
try {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1);
serialPort.disableReceiveTimeout();
serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII");
serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
setSerialEventHandler(this);
connected = true;
} catch (NoSuchPortException noSuchPortException) {
logger.error("open(): No Such Port Exception: ", noSuchPortException);
connected = false;
} catch (PortInUseException portInUseException) {
logger.error("open(): Port in Use Exception: ", portInUseException);
connected = false;
} catch (UnsupportedCommOperationException unsupportedCommOperationException) {
logger.error("open(): Unsupported Comm Operation Exception: ", unsupportedCommOperationException);
connected = false;
} catch (UnsupportedEncodingException unsupportedEncodingException) {
logger.error("open(): Unsupported Encoding Exception: ", unsupportedEncodingException);
connected = false;
} catch (IOException ioException) {
logger.error("open(): IO Exception: ", ioException);
connected = false;
}
}
Aggregations