microscpi

Crates.iomicroscpi
lib.rsmicroscpi
version0.1.0
sourcesrc
created_at2024-09-14 23:19:45.055248
updated_at2024-10-27 15:28:23.598234
descriptionA Rust library for creating SCPI interfaces.
homepagehttps://github.com/7h0ma5/microscpi
repositoryhttps://github.com/7h0ma5/microscpi
max_upload_size
id1375115
size94,461
Thomas Gatzweiler (7h0ma5)

documentation

README

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 = String::new();
    let mut interface = ExampleInterface { value: 42 };

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

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

Crate Usage

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

[dependencies]
microscpi = "0.1.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.

Commit count: 45

cargo fmt