diff --git a/ugs-core/src/com/willwinder/universalgcodesender/connection/JSerialCommConnection.java b/ugs-core/src/com/willwinder/universalgcodesender/connection/JSerialCommConnection.java index 643ec3089..aa3d6bd9c 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/connection/JSerialCommConnection.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/connection/JSerialCommConnection.java @@ -21,7 +21,9 @@ This file is part of Universal Gcode Sender (UGS). import com.fazecast.jSerialComm.SerialPort; import com.fazecast.jSerialComm.SerialPortDataListener; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; +import java.io.File; import java.util.Arrays; import java.util.List; @@ -48,6 +50,8 @@ public void setUri(String uri) { String portName = StringUtils.substringBetween(uri, ConnectionDriver.JSERIALCOMM.getProtocol(), ":"); int baudRate = Integer.parseInt(StringUtils.substringAfterLast(uri, ":")); initSerialPort(portName, baudRate); + } catch (ConnectionException e) { + throw e; } catch (Exception e) { throw new ConnectionException("Couldn't parse connection string " + uri, e); } @@ -72,6 +76,8 @@ private void initSerialPort(String name, int baud) throws Exception { } serialPort = SerialPort.getCommPort(name); + checkPermissions(); + serialPort.setParity(SerialPort.NO_PARITY); serialPort.setNumStopBits(SerialPort.ONE_STOP_BIT); serialPort.setNumDataBits(8); @@ -79,6 +85,17 @@ private void initSerialPort(String name, int baud) throws Exception { serialPort.setBaudRate(baud); } + private void checkPermissions() { + if (!SystemUtils.IS_OS_LINUX) { + return; + } + + File port = new File(serialPort.getSystemPortPath()); + if (!port.canWrite() || !port.canRead() ) { + throw new ConnectionException("Do not have required permissions to open the device on " + serialPort.getSystemPortPath()); + } + } + @Override public void closePort() throws Exception { if (serialPort != null) { diff --git a/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java b/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java index b3ab94f3b..738a57da0 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java @@ -617,7 +617,8 @@ public boolean canCancel() { @Override public boolean canSend() { return isIdle() && - this.gcodeFile != null; + this.gcodeFile != null && + (controller != null && !controller.isStreaming()); } @Override @@ -762,7 +763,7 @@ private boolean openCommConnection(String port, int baudRate) throws Exception { disconnect(); logger.log(Level.INFO, "Exception in openCommConnection.", e); throw new Exception(Localization.getString("mainWindow.error.connection") - + ": " + e.getMessage()); + + ": " + e.getMessage(), e); } return connected; }