1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! This crate provides a simple interface to create an async SCPI command
//! interpreter. It is especially suited for embedded devices The SCPI command
//! tree is created at compile time using a procedural macro.
//!
//! Notable features are:
//! * No dynamic memory allocation used and *no_std* support.
//! * Compile time creation of the SCPI command tree.
//! * Support for `async` commmand handler functions.
//!
//! # Usage
//!
//! To build an SCPI interface, create a struct that implements the
//! SCPI handler commands. The `#[interface]` attribute macro attached to the
//! `impl` of the interface will generate the command tree and implement the
//! functions required by the [Interface] trait. The [Interface::run] method
//! will parse the command string, execute the corresponding command handler
//! function and fill the output buffer with the response of the command
//! handler function.
//!
//! ## Minimal Example
//!
//! The following example demonstrates how to create a simple SCPI interface
//! with a single command that returns a value.
//!
//! ```
//! use microscpi::{self as scpi, Interface};
//!
//! pub struct ExampleInterface {
//! value: u64
//! }
//!
//! impl scpi::ErrorHandler for ExampleInterface {
//! fn handle_error(&mut self, error: scpi::Error) {
//! println!("Error: {error}");
//! }
//! }
//!
//! #[scpi::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");
//! }
//! ```
//!
//! ## Using standard command handlers
//!
//! This crate provides a set of standard command handlers that can be used to
//! implement the SCPI standard commands. The `StandardCommands` trait provides
//! a set of default implementations for generic SCPI commands required by the
//! IEEE 488.2 standard. The `ErrorCommands` trait provides the default error
//! handling commands. These traits can be implemented for the interface struct
//! to provide a default implementations for these commands.
//!
//! The following example demonstrates how to use the `StandardCommands` and
//! `ErrorCommands` traits to add the SCPI standard commands.
//!
//! ```
//! use microscpi::{self as scpi, Interface};
//!
//! pub struct ExampleInterface {
//! value: u64,
//! errors: scpi::StaticErrorQueue<10>,
//! }
//!
//! impl scpi::ErrorCommands for ExampleInterface {
//! fn error_queue(&mut self) -> &mut impl scpi::ErrorQueue {
//! &mut self.errors
//! }
//! }
//!
//! impl scpi::StandardCommands for ExampleInterface {}
//!
//! #[scpi::interface(StandardCommands, ErrorCommands)]
//! 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, errors: scpi::StaticErrorQueue::new() };
//!
//! interface.run(b"UNKNOWN:COMMAND?\n", &mut output).await;
//! interface.run(b"SYST:ERROR:NEXT?\n", &mut output).await;
//!
//! assert_eq!(output, b"-113,\"Undefined header\"\n");
//! }
//! ```
extern crate std as core;
pub use StatusCommands;
pub use ;
pub use Error;
pub use ;
pub use ;
pub use interface;
pub use StatusRegisters;
pub use ;
pub use Node;
pub use Value;
/// Reference identifier of a command or query
///
/// Due to current limitations with async function pointers, the references to
/// the command handler functions are stored as integers.
pub type CommandId = usize;
pub type Result<T> = Result;
/// The version of the SCPI standard this crate implements.
pub const SCPI_STD_VERSION: &str = "1999.0";
/// The maximum number of arguments that can be passed to a command.
pub const MAX_ARGS: usize = 10;
;