Send device reset command
This commit is contained in:
parent
da2e02b92e
commit
d4c9fa65be
17
src/main.rs
17
src/main.rs
|
@ -17,18 +17,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
if let Ok(repo) = get_prop(&mut port, b"repo") {
|
||||
println!("repo success: {}", String::from_utf8_lossy(&repo));
|
||||
}
|
||||
|
||||
if send_cmd(&mut port, b"reset").is_ok() {
|
||||
println!("Device reset");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send_cmd(
|
||||
port: &mut Box<dyn serialport::SerialPort>,
|
||||
cmd: &[u8],
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
port.write_all(cmd)?;
|
||||
port.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
port: &mut Box<dyn serialport::SerialPort>,
|
||||
prop: &[u8],
|
||||
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
port.write_all(prop)?;
|
||||
port.flush()?;
|
||||
send_cmd(port, prop)?;
|
||||
|
||||
let mut len_buf = [0u8; 1];
|
||||
port.read_exact(&mut len_buf)?;
|
||||
|
|
Loading…
Reference in a new issue