Stream

Struct Stream 

Source
pub struct Stream<'d> { /* private fields */ }
Expand description

一次采集的数据流。由 Device::start 创建,借用设备直到被丢弃。

dev.configure(&cfg)?;
let mut stream = dev.start()?;
while !stream.is_finished() {
    if let Some(packet) = stream.recv(Duration::from_millis(100))? {
        for point in packet.points() {
            // point.values: 该组各通道在这个 CONV 时刻的值
        }
    }
}
let summary = stream.finish()?;
assert_eq!(summary.device.lost, 0);

Implementations§

Source§

impl<'d> Stream<'d>

Source

pub fn recv_into( &mut self, cap: &mut Capture, timeout: Duration, ) -> Result<bool>

接收数据包并加入 cap,直到本次运行的数据全部交付(返回 true),或 timeout 用完(返回 false,可再次调用)。

Source

pub fn collect(self, idle_timeout: Duration) -> Result<Capture>

收完本次运行的全部数据,汇集成 Capture(含 finish 和 Capture::finish 的检查)。 连续 idle_timeout 没有收到数据时返回 Error::Timeout。

Source

pub fn attach(dev: &'d mut Device) -> Result<Stream<'d>>

接上数据流但不启动采集:从设备当前的“下一个包序号“开始接收,更早的包直接确认掉。

用于采集由别处启动的情况(例如另一条通路写了 START)。一般用 Device::start。

Source

pub fn recv(&mut self, timeout: Duration) -> Result<Option<PointPacket>>

取下一个点包(严格按包序号,每个包只交付一次)。timeout 内没有可交付的包时返回 Ok(None)。

调用期间同时处理 ACK、NACK 和心跳。要保持数据流畅通,应持续调用它。

Source

pub fn is_finished(&self) -> bool

两组的结束包是否都已收到(本次运行的数据全部交付)。

Source

pub fn group_finished(&self, g: usize) -> bool

组 g 的结束包是否已收到。

Source

pub fn stop(&mut self) -> Result<()>

停止采集(写 STOP)。之后继续调用 recv 直到 is_finished。

Source

pub fn device(&mut self) -> &mut Device

读写寄存器等操作在数据流存续期间通过它进行。

Source

pub fn stats(&self) -> StreamStats

主机侧的接收统计。

Source

pub fn finish(self) -> Result<RunSummary>

结束数据流:确认已收到的全部数据包,读出设备侧的计数器。

Trait Implementations§

Source§

impl Drop for Stream<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d> Freeze for Stream<'d>

§

impl<'d> RefUnwindSafe for Stream<'d>

§

impl<'d> Send for Stream<'d>

§

impl<'d> Sync for Stream<'d>

§

impl<'d> Unpin for Stream<'d>

§

impl<'d> !UnwindSafe for Stream<'d>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.