use simple_logger::SimpleLogger;
use zproto::binary::{command::*, Port};
fn main() -> Result<(), Box<dyn std::error::Error>> {
SimpleLogger::new().init().unwrap();
let port_path = "/dev/ttyUSB0";
let device = 1;
let mut port = Port::open_serial(port_path)?;
port.tx_recv_until_timeout((0, RENUMBER, 0))?;
port.set_message_ids(true)?;
port.tx_recv((device, HOME))?;
port.poll_until_idle(device)?;
port.tx_recv((device, MOVE_ABSOLUTE, 100_000))?;
port.poll_until((device, RETURN_CURRENT_POSITION), |reply| {
let pos = reply.data().unwrap();
println!("{pos}");
pos == 100_000
})?;
port.tx_recv((device, MOVE_ABSOLUTE, 25_000))?;
port.poll_until_idle(1)?;
let reply = port.tx_recv((device, RETURN_CURRENT_POSITION))?;
println!("{}", reply.data()?);
Ok(())
}