use of jssc.SerialPort in project arduino-eclipse-plugin by Sloeber.
the class Serial method connect.
public void connect(int maxTries) {
if (this.port == null) {
int count = 0;
while (true) {
try {
this.port = new SerialPort(this.portName);
this.port.openPort();
this.port.setParams(this.rate, this.databits, this.stopbits, this.parity, this.dtr, this.dtr);
int eventMask = SerialPort.MASK_RXCHAR | SerialPort.MASK_BREAK;
this.port.addEventListener(this, eventMask);
return;
} catch (SerialPortException e) {
// handle exception
if (++count == maxTries) {
if (SerialPortException.TYPE_PORT_BUSY.equals(e.getExceptionType())) {
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, // $NON-NLS-1$
"Serial port " + this.portName + // $NON-NLS-1$
" already in use. Try quiting any programs that may be using it", e));
} else if (SerialPortException.TYPE_PORT_NOT_FOUND.equals(e.getExceptionType())) {
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, // $NON-NLS-1$
"Serial port " + this.portName + // $NON-NLS-1$
" not found. Did you select the right one from the project properties -> Sloeber?", e));
} else {
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Error opening serial port " + this.portName, // $NON-NLS-1$
e));
}
return;
}
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
// $NON-NLS-1$
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Sleep failed", e1));
}
}
// If an exception was thrown, delete port variable
this.port = null;
}
}
}
use of jssc.SerialPort in project Universal-G-Code-Sender by winder.
the class JSSCConnection method openPort.
@Override
public boolean openPort() throws Exception {
if (StringUtils.isEmpty(portName) || baudRate == 0) {
throw new ConnectionException("Couldn't open port " + portName + " using baud rate " + baudRate);
}
this.serialPort = new SerialPort(portName);
this.serialPort.openPort();
this.serialPort.setParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, true, true);
this.serialPort.addEventListener(this);
if (this.serialPort == null) {
throw new ConnectionException("Serial port not found.");
}
return serialPort.isOpened();
}
use of jssc.SerialPort in project ma-core-public by infiniteautomation.
the class JsscSerialPortProxy method openImpl.
/*
* (non-Javadoc)
*
* @see com.serotonin.io.serial.SerialPortProxy#open()
*/
@Override
protected void openImpl() throws SerialPortException {
try {
if (LOG.isDebugEnabled())
LOG.debug("Opening Serial Port: " + commPortId);
this.port = new SerialPort(commPortId.getName());
this.port.openPort();
this.port.setFlowControlMode(flowControlIn | flowControlOut);
this.port.setParams(baudRate, dataBits, stopBits, parity);
this.is = new JsscSerialPortInputStream(this.port, this.listeners);
this.os = new JsscSerialPortOutputStream(this.port);
} catch (jssc.SerialPortException e) {
throw new SerialPortException(e);
}
}
use of jssc.SerialPort in project Universal-G-Code-Sender by winder.
the class JSSCConnection method openPort.
@Override
public synchronized boolean openPort(String name, int baud) throws Exception {
this.inputBuffer = new StringBuilder();
this.serialPort = new SerialPort(name);
this.serialPort.openPort();
this.serialPort.setParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, true, true);
this.serialPort.addEventListener(this);
if (this.serialPort == null) {
throw new Exception("Serial port not found.");
}
return serialPort.isOpened();
}
Aggregations