Crates.io | microscpi |
lib.rs | microscpi |
version | 0.3.0 |
source | src |
created_at | 2024-09-14 23:19:45.055248 |
updated_at | 2024-11-26 21:40:04.009983 |
description | A Rust library for creating SCPI interfaces. |
homepage | https://github.com/7h0ma5/microscpi |
repository | https://github.com/7h0ma5/microscpi |
max_upload_size | |
id | 1375115 |
size | 108,094 |
microscpi
CrateThis 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.
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");
}
To use this crate in your project, add the following line to your Cargo.toml
file:
[dependencies]
microscpi = "0.3.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"] }
This project is licensed under the MIT License.