pub struct Dac { /* private fields */ }Expand description
A connected device that can start streaming sessions.
When starting a stream, the device is consumed and the backend ownership
transfers to the stream. The DacInfo is returned alongside the stream
so metadata remains accessible.
§Example
use laser_dac::{open_device, StreamConfig};
let device = open_device("my-device")?;
let config = StreamConfig::new(30_000);
let (stream, info) = device.start_stream(config)?;
println!("Streaming to: {}", info.name);Implementations§
Source§impl Dac
impl Dac
Sourcepub fn new(info: DacInfo, backend: BackendKind) -> Self
pub fn new(info: DacInfo, backend: BackendKind) -> Self
Create a new device from a backend.
Sourcepub fn with_discovery_factory<F>(self, factory: F) -> Self
pub fn with_discovery_factory<F>(self, factory: F) -> Self
Set a custom discovery factory for reconnection.
When reconnection is enabled (via crate::FrameSessionConfig::with_reconnect or
StreamConfig::with_reconnect), the factory is called to create a
DacDiscovery instance for each reconnection attempt. This is required
for custom backends registered via DacDiscovery::register — without it,
reconnection uses the default discovery which only finds built-in DAC types.
For ID-based opens, prefer open_device_with.
For worker-owned scan results, compose
DacDiscovery::open_discovered
with this method. Use this method directly when you construct a Dac
yourself around an application-owned backend.
§Example
use laser_dac::{Dac, DacDiscovery, EnabledDacTypes, FrameSessionConfig, ReconnectConfig};
// `info` and `backend` come from application-owned construction, not
// from DacDiscovery::open_discovered*.
let dac = Dac::new(info, backend).with_discovery_factory(|| {
let mut d = DacDiscovery::new(EnabledDacTypes::all());
d.register(Box::new(MyCustomDiscoverer::new()));
d
});
let config = FrameSessionConfig::new(30_000)
.with_reconnect(ReconnectConfig::new());
let (session, _info) = dac.start_frame_session(config)?;Sourcepub fn caps(&self) -> &DacCapabilities
pub fn caps(&self) -> &DacCapabilities
Returns the device capabilities.
Sourcepub fn has_backend(&self) -> bool
pub fn has_backend(&self) -> bool
Returns whether the device has a backend (not yet used for a stream).
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns whether the device is connected.
Sourcepub fn start_stream(self, cfg: StreamConfig) -> Result<(Stream, DacInfo)>
pub fn start_stream(self, cfg: StreamConfig) -> Result<(Stream, DacInfo)>
Starts a streaming session, consuming the device.
§Ownership
This method consumes the Dac because:
- Each device can only have one active stream at a time.
- The backend is moved into the
Streamto ensure exclusive access. - This prevents accidental reuse of a device that’s already streaming.
The method returns both the Stream and a copy of DacInfo, so you
retain access to device metadata (id, name, capabilities) after starting.
§Connection
If the device is not already connected, this method will establish the connection before creating the stream. Connection failures are returned as errors.
§Errors
Returns an error if:
- The device backend has already been used for a stream.
- The configuration is invalid (PPS out of range, invalid chunk size, etc.).
- The backend fails to connect.
Sourcepub fn start_frame_session(
self,
config: FrameSessionConfig,
) -> Result<(FrameSession, DacInfo)>
pub fn start_frame_session( self, config: FrameSessionConfig, ) -> Result<(FrameSession, DacInfo)>
Starts a frame-mode session, consuming the device.
Similar to start_stream but uses the frame-first
API where you submit complete crate::presentation::Frames instead of filling
point buffers via callback.
Returns a crate::presentation::FrameSession that owns the scheduler thread and a
DacInfo with device metadata.