Skip to main content

Module blocking

Module blocking 

Source
Available on crate feature blocking only.
Expand description

Synchronous adapter — drives the sans-I/O core over a Read + Write transport.

use std::io::{Read, Write};
use marlin_binary_transfer::adapters::blocking::{upload, UploadOptions};
use marlin_binary_transfer::file_transfer::Compression;

let opts = UploadOptions {
    dest_filename: "model.gco".into(),
    compression: Compression::Auto,
    ..UploadOptions::default()
};
let stats = upload(&mut port, std::fs::File::open("model.gco")?, opts)?;
println!("Uploaded {} bytes in {} chunks", stats.bytes_sent, stats.chunks_sent);

Any Read + Write works. With the serial feature enabled, serialport::SerialPort satisfies both traits directly; see adapters::serialport for an open helper.

§Transport requirements

transport.read(..) must return std::io::ErrorKind::TimedOut within a bounded interval when no data is available, so tick() can fire retransmits. A blocking read with no timeout would deadlock the loop under packet loss. The adapters::serialport::open helper configures a 100 ms read timeout out of the box; if you’re plugging in a different transport (TCP-to-serial bridge, USB CDC via rusb, in-memory pipe) make sure it has the equivalent behaviour.

§Lifecycle handled for you

  1. Send M28 B1 to enter binary mode.
  2. SYNC handshake.
  3. QUERY → compression negotiation.
  4. OPEN, WRITE × N, CLOSE.
  5. Control CLOSE (proto=0, type=2) so the device exits binary mode and the same serial session can accept ASCII g-code again afterwards.

Re-exports§

pub use crate::adapters::common::Progress;
pub use crate::adapters::common::ProgressCallback;
pub use crate::adapters::common::UploadError;
pub use crate::adapters::common::UploadOptions;
pub use crate::adapters::common::UploadStats;

Functions§

upload
Perform a complete upload: SYNC, QUERY, OPEN, WRITE×N, CLOSE.