6 releases

0.2.0 Nov 12, 2024
0.1.0 Oct 27, 2024
0.1.0-alpha.3 Sep 29, 2024

#1446 in Embedded development

Download history 163/week @ 2024-09-09 60/week @ 2024-09-16 260/week @ 2024-09-23 248/week @ 2024-09-30 16/week @ 2024-10-07 1/week @ 2024-10-14 69/week @ 2024-10-21 51/week @ 2024-10-28 6/week @ 2024-11-04 114/week @ 2024-11-11

240 downloads per month

MIT license

97KB
2K SLoC

build Latest version Documentation Codecov

microscpi Crate

This crate provides a simple interface to create an async SCPI (Standard Commands for Programmable Instruments) command interpreter, particularly well-suited for embedded devices. It aims to offer a lightweight, efficient, and easily extensible solution for parsing and handling SCPI commands without requiring heap memory allocations.

Features

  • No heap memory allocation required: The crate is designed to function without the need for dynamic memory allocation, making it ideal for constrained embedded systems.
  • Compile-time SCPI command tree creation: Commands are defined at compile-time, ensuring efficiency and reducing runtime overhead.
  • Support for async command handler functions: Asynchronous command handling is fully supported, allowing non-blocking operations in embedded or other concurrent environments.

Example

The following is a minimal example demonstrating how to use the microscpi crate to create an SCPI command interface that handles the SYSTem:VALue? command asynchronously.

use microscpi::{self as scpi, Interface, ErrorHandler};

pub struct ExampleInterface {
    value: u64
}

impl ErrorHandler for ExampleInterface {
    fn handle_error(&mut self, error: scpi::Error) {
        println!("Error: {error}");
    }
}

#[microscpi::interface]
impl ExampleInterface {
    #[scpi(cmd = "SYSTem:VALue?")]
    async fn system_value(&mut self) -> Result<u64, scpi::Error> {
        Ok(self.value)
    }
}

#[tokio::main]
pub async fn main() {
    let mut output = Vec::new();
    let mut interface = ExampleInterface { value: 42 };

    interface.run(b"SYSTEM:VAL?\n", &mut output).await;

    assert_eq!(output, b"42\n");
}

Crate Usage

To use this crate in your project, add the following line to your Cargo.toml file:

[dependencies]
microscpi = "0.2.0"

Make sure to include the async runtime such as tokio or another suitable runtime for executing async functions.

Example for adding tokio:

[dependencies]
tokio = { version = "1", features = ["full"] }

License

This project is licensed under the MIT License.

Dependencies

~0.7–1.2MB
~26K SLoC