Skip to Content
SeekDAS S100M4X

Rust 快速上手

在 Cargo 工程里使用 seekdas crate

seekdas crate 是 SDK 的实现本体。它没有发布到 crates.io,用路径依赖引入:

Cargo.toml
[dependencies]
seekdas = { path = "path/to/host/seekdas-rs" }       # 默认带特性 serial(串口 AT 指令)

第一个程序

src/main.rs
use seekdas::at::AtClient;
use seekdas::{Channel, ChannelMask, Device, Edge, Range, Target, Trigger};

fn main() -> seekdas::Result<()> {
    // 1. 串口:确认自检通过,打开激光,设置量程
    let mut at = AtClient::open("/dev/ttyACM0")?;            // Windows 上如 "COM5"
    assert!(at.selftest_result()?.passed);
    at.set_lasers(true, false)?;
    at.set_range(Target::All, Range::V10)?;

    // 2. 光口:连接设备
    let mut dev = Device::open("192.168.1.128".parse().unwrap())?;
    println!("{:?}", dev.info()?);

    // 3. 触发:S0A、S0B 各 1 万点,CONV = S2A 上升沿、阈值 1400 码
    let trig = Trigger::new()
        .target(ChannelMask::from_iter([Channel::S0A, Channel::S0B]), 10_000)?
        .conv_channel(Channel::S2A, Edge::Rising, 1400)?;
    let cap = dev.trigger(&trig)?;                            // 启动并收完;运行中启动返回 Error::Busy

    let s0a = cap.group(0).channel(Channel::S0A).unwrap();
    println!("{} points, first {:.4} V", s0a.len(), Range::V10.code_to_volts(s0a[0] as f64));
    Ok(())
}

仓库自带的示例

cd host/seekdas-rs
cargo run --example at_console -- /dev/ttyACM0                       # 版本、自检、状态、量程、各路读数
cargo run --example at_console -- /dev/ttyACM0 "AT+SFP=1"            # 原样发一条指令
cargo run --example info                                             # 光口:标识、状态、计数器
cargo run --example monitor                                          # 统计窗口读数 + 原始采集
cargo run --release --example acquire -- rate=1e6 band=2.5e6 n=1000000 ch=S0A,S0B out=cap.csv

本机数据端口被占用时加 port=15500(info / monitor 为第二个参数)。

测试

cargo test                     # 单元测试、文档测试、回环上的设备模拟器
SEEKDAS_SERIAL=/dev/ttyACM0 SEEKDAS_IP=192.168.1.128 \
    cargo test --release --test hardware -- --ignored --test-threads=1      # 实板

接口说明全部在 Rust API 参考(rustdoc)里。

On this page