Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

经光口连接的一台 S100M4X。

打开后可以读写寄存器(实现了 RegIo)、查询状态、配置并启动采集。

use seekdas::{AcqConfig, Channel, ChannelMask, Device, Kernel};

let mut dev = Device::open("192.168.1.128".parse().unwrap())?;
println!("{:?}", dev.info()?);

// 内部发生器 1 MSPS,信号带宽 2.5 MHz,采 S0A 和 S0B 共 10 万点
let (r, kernel) = Kernel::for_bandwidth(2.5e6)?;
let cfg = AcqConfig::new()
    .decimation_log2(r)
    .kernel(kernel)
    .generator_rate(1.0e6)
    .group(0, |g| g.generator().channels(ChannelMask::from_iter([Channel::S0A, Channel::S0B])).timestamps(true))
    .points(100_000);
let cap = dev.acquire(&cfg)?;
let s0a = cap.group(0).channel(Channel::S0A).unwrap();
println!("{} points, first {}", s0a.len(), s0a[0]);

光口的激光上电时是关的,需要先经串口执行一次 AT+SFP=1 (AtClient::set_lasers),之后网络才通。

Implementations§

Source§

impl Device

Source

pub fn open(addr: Ipv4Addr) -> Result<Device>

用默认参数连接 addr 处的设备。

Source

pub fn open_with(cfg: DeviceConfig) -> Result<Device>

用给定参数连接设备:检查 ID 寄存器,绑定数据端口,并(DeviceConfig::set_host 为真时)把设备的数据目的地址指向本机。

Source

pub fn config(&self) -> &DeviceConfig

连接参数。

Source

pub fn host_port(&self) -> Result<u16>

本机接收数据的 UDP 端口(DeviceConfig::host_port 为 0 时是系统分配的端口)。

Source

pub fn info(&mut self) -> Result<DeviceInfo>

设备标识和固件版本。

Source

pub fn uptime(&mut self) -> Result<Duration>

自 PL 配置完成起的运行时间(49.7 天回绕)。

Source

pub fn sample_rate_hz(&mut self) -> Result<f64>

板上实测的采样时钟频率(Hz,分辨率 100 Hz,以 PS 时钟为基准;标称 100 MHz)。

把时间戳(T/64)换算成秒、或计算内部发生器的实际点速率时用这个值。

Source

pub fn board_status(&mut self) -> Result<BoardStatus>

板级状态:电源、ADC 对齐、自检结果、激光开关。

Source

pub fn net_status(&mut self) -> Result<NetStatus>

网络状态和计数器。

Source

pub fn configure(&mut self, cfg: &AcqConfig) -> Result<()>

把采集配置写入设备(不启动)。等价于 AcqConfig::apply;设备正在采集时返回 Error::Busy。

Source

pub fn acq_status(&mut self) -> Result<AcqStatus>

采集状态和计数器。

Source

pub fn start(&mut self) -> Result<Stream<'_>>

启动一次采集(按已写入的配置),返回接收数据的 Stream。

启动前会跳过设备里此前残留的数据包。配置了点数(AcqConfig::points)时采集自行结束; 否则持续到 Stream::stop。设备正在采集时返回 Error::Busy。

Source

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

停止正在进行的采集。已产生的点仍会发完,并以每组一个结束包收尾。

Source

pub fn acquire(&mut self, cfg: &AcqConfig) -> Result<Capture>

配置、启动并接收一次完整的采集(点数由 AcqConfig::points 给定,必须非 0)。

出现丢点、late 或序号不连续时返回错误。数据量很大或需要边收边处理时改用 start 和 Stream::recv。

Source

pub fn acquire_for( &mut self, cfg: &AcqConfig, duration: Duration, ) -> Result<Capture>

配置并启动一次不限点数的采集,duration 之后停止,返回期间收到的全部数据。

Source§

impl Device

Source

pub fn start_trigger(&mut self, trigger: &Trigger) -> Result<Stream<'_>>

写入触发设置并启动,返回接收数据的 Stream(用 Stream::collect 收完,或 Stream::recv 逐包处理)。

设备正在运行(本机或别的主机启动的)时返回 Error::Busy,什么也不改。

Source

pub fn trigger(&mut self, trigger: &Trigger) -> Result<Capture>

启动触发并收完整个运行(连续 10 s 没有数据时返回 Error::Timeout,例如 CONV 输入上没有信号)。

Source

pub fn trigger_state(&mut self) -> Result<TriggerState>

触发的运行状态。数据流存续期间经 Stream::device 调用。

Trait Implementations§

Source§

impl RegIo for Device

Source§

fn read_regs(&mut self, addr: u16, n: usize) -> Result<Vec<u32>>

从 addr 起连续读 n 个寄存器(地址每次加 4)。
Source§

fn write_regs(&mut self, pairs: &[(u16, u32)]) -> Result<Vec<u32>>

按顺序写一组 (地址, 值),返回每个寄存器写后读回的值。
Source§

fn read_reg(&mut self, addr: u16) -> Result<u32>

读一个寄存器。
Source§

fn write_reg(&mut self, addr: u16, value: u32) -> Result<u32>

写一个寄存器,返回写后读回的值。

Auto Trait Implementations§

§

impl Freeze for Device

§

impl RefUnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl UnwindSafe for Device

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.