Skip to content

Commit 0b0a93e

Browse files
committed
better scan
1 parent 4ddee26 commit 0b0a93e

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/bin/dxl_scan.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ fn main() -> Result<(), Box<dyn Error>> {
5454
match io.ping(serial_port.as_mut(), id) {
5555
Ok(present) => {
5656
if present {
57-
let model = io.read(serial_port.as_mut(), id, 0, 2).unwrap();
58-
59-
found.insert(id, u16::from_le_bytes([model[0], model[1]]));
57+
match io.read(serial_port.as_mut(), id, 0, 2) {
58+
Ok(model) => {
59+
found.insert(id, u16::from_le_bytes([model[0], model[1]]));
60+
}
61+
Err(e) => {
62+
found.insert(id, u16::from_le_bytes([0, 0]));
63+
eprintln!("Error: Cannot read model \"{e}\" but id {id} detected");
64+
}
65+
}
6066
}
6167
}
6268
Err(e) => eprintln!("Error: {e}"),
@@ -65,11 +71,14 @@ fn main() -> Result<(), Box<dyn Error>> {
6571

6672
println!("found {} motors", found.len());
6773
for (key, value) in found {
68-
println!(
69-
"id: {} model: {:?}",
70-
key,
71-
DxlModel::try_from(value).unwrap()
72-
);
74+
match DxlModel::try_from(value) {
75+
Ok(model) => {
76+
println!("id: {} model: {:?}", key, model);
77+
}
78+
Err(_e) => {
79+
println!("id: {} model: UNKNOWN", key);
80+
}
81+
}
7382
}
7483

7584
Ok(())

src/device/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{reg_read_only, reg_read_write, DynamixelSerialIO, Result};
1111
#[derive(Debug, IntoPrimitive, TryFromPrimitive)]
1212
#[repr(u16)]
1313
pub enum DxlModel {
14+
NODATA = 0,
1415
AX12A = 12,
1516
AX12W = 300,
1617
AX18A = 18,

0 commit comments

Comments
 (0)