Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #2567

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -72,13 +76,26 @@ 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);
serialPort.addDataListener(this);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ public boolean canCancel() {
@Override
public boolean canSend() {
return isIdle() &&
this.gcodeFile != null;
this.gcodeFile != null &&
(controller != null && !controller.isStreaming());
}

@Override
Expand Down Expand Up @@ -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;
}
Expand Down
Loading