Skip to content

Commit c9e27c0

Browse files
committed
Better error when port is inaccessible
1 parent a153433 commit c9e27c0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

inputmodule-control/src/inputmodule.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,17 @@ fn simple_cmd_multiple(serialdevs: &Vec<String>, command: Command, args: &[u8])
388388
}
389389

390390
fn simple_cmd(serialdev: &str, command: Command, args: &[u8]) {
391-
let mut port = serialport::new(serialdev, 115_200)
391+
let port_result = serialport::new(serialdev, 115_200)
392392
.timeout(SERIAL_TIMEOUT)
393-
.open()
394-
.expect("Failed to open port");
393+
.open();
395394

396-
simple_cmd_port(&mut port, command, args);
395+
match port_result {
396+
Ok(mut port) => simple_cmd_port(&mut port, command, args),
397+
Err(error) => match error.kind {
398+
serialport::ErrorKind::Io(std::io::ErrorKind::PermissionDenied) => panic!("Permission denied, couldn't access input module port. Ensure that udev rule is installed or the port the module is on is otherwise accessible."),
399+
other_error => panic!("Couldn't open port: {:?}", other_error)
400+
}
401+
};
397402
}
398403

399404
fn open_serialport(serialdev: &str) -> Box<dyn SerialPort> {

0 commit comments

Comments
 (0)