Skip to content

Commit 41b4673

Browse files
authored
Attempt to warn user if permissions to device is missing. And prevent the user from starting a stream twice when the machine is waiting for G4 dwell command (#2567)
1 parent 72f96f1 commit 41b4673

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ugs-core/src/com/willwinder/universalgcodesender/connection/JSerialCommConnection.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ This file is part of Universal Gcode Sender (UGS).
2121
import com.fazecast.jSerialComm.SerialPort;
2222
import com.fazecast.jSerialComm.SerialPortDataListener;
2323
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.SystemUtils;
2425

26+
import java.io.File;
2527
import java.util.Arrays;
2628
import java.util.List;
2729

@@ -48,6 +50,8 @@ public void setUri(String uri) {
4850
String portName = StringUtils.substringBetween(uri, ConnectionDriver.JSERIALCOMM.getProtocol(), ":");
4951
int baudRate = Integer.parseInt(StringUtils.substringAfterLast(uri, ":"));
5052
initSerialPort(portName, baudRate);
53+
} catch (ConnectionException e) {
54+
throw e;
5155
} catch (Exception e) {
5256
throw new ConnectionException("Couldn't parse connection string " + uri, e);
5357
}
@@ -72,13 +76,26 @@ private void initSerialPort(String name, int baud) throws Exception {
7276
}
7377

7478
serialPort = SerialPort.getCommPort(name);
79+
checkPermissions();
80+
7581
serialPort.setParity(SerialPort.NO_PARITY);
7682
serialPort.setNumStopBits(SerialPort.ONE_STOP_BIT);
7783
serialPort.setNumDataBits(8);
7884
serialPort.addDataListener(this);
7985
serialPort.setBaudRate(baud);
8086
}
8187

88+
private void checkPermissions() {
89+
if (!SystemUtils.IS_OS_LINUX) {
90+
return;
91+
}
92+
93+
File port = new File(serialPort.getSystemPortPath());
94+
if (!port.canWrite() || !port.canRead() ) {
95+
throw new ConnectionException("Do not have required permissions to open the device on " + serialPort.getSystemPortPath());
96+
}
97+
}
98+
8299
@Override
83100
public void closePort() throws Exception {
84101
if (serialPort != null) {

ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ public boolean canCancel() {
617617
@Override
618618
public boolean canSend() {
619619
return isIdle() &&
620-
this.gcodeFile != null;
620+
this.gcodeFile != null &&
621+
(controller != null && !controller.isStreaming());
621622
}
622623

623624
@Override
@@ -762,7 +763,7 @@ private boolean openCommConnection(String port, int baudRate) throws Exception {
762763
disconnect();
763764
logger.log(Level.INFO, "Exception in openCommConnection.", e);
764765
throw new Exception(Localization.getString("mainWindow.error.connection")
765-
+ ": " + e.getMessage());
766+
+ ": " + e.getMessage(), e);
766767
}
767768
return connected;
768769
}

0 commit comments

Comments
 (0)