[−][src]Crate scpi
This crate attempts to implement the IEE488.2 / SCPI protocol commonly used by measurement instruments and tools. See IVI Foundation (SCPI-99 and IEE488.2).
It does not require the std library (ie it's no_std
compatible) or a system allocator (useful for embedded).
API is unstable (as of 0.2.*)
Scope
The crate does not support any transport layer, it only reads strings (&[u8]
/ascii-/byte-slice/<whatever they are called this week> to be precise) and writes responses.
It does not implement any higher level functions/error handling other than SCPI parsing and mandated registers/commands(optional).
Using this crate
Add scpi
to your dependencies. The precise version should be specified as the API is unstable for now:
[dependencies] scpi = "=0.x.y"
Getting started
TODO, look at example
(or example-cortexm
for embedded) directory for now
Character coding
SCPI is strictly ASCII and will throw a error InvalidCharacter if any non-ascii (>127)
characters are encountered (Exception: Arbitrary data blocks).
This library uses byte-slices for all strings and must be converted to UTF8 str type. The try_into<str> trait will do this automatically and throw an error if unsuccessful.
Error handling
The Context::exec(...)
function aborts execution and returns on the first error it encounters.
Execution may be resumed where it aborted by calling exec again with the same tokenizer.
User commands will often use functions which may return an error, these should mostly be propagated down to the parser by rusts ?
operator.
The documentation often uses the term 'throw' for returning an error, this should not be confused with exceptions etc which are not used.
Limitations and differences
These are the current limitations and differences from SCPI-99 specs (that I can remember) that needs to be addressed before version 1.0.0. They are listed in the rough order of which I care to fix them.
- Response data formatting, currently each command is responsible for formatting their response. In progress
- Better command data operators with automatic error checking. In progress. TryInto and TrayFrom traits are implemented for Integer, float and string types
- Automatic suffix/~~special number~~ handling.
- ~~Provide working implementation of all IEEE 488.2 and SCPI-99 mandated commands.~~ All IEEE488.2/SCPI-99 mandated commands (and a few extra for good measure) have default implementations.
- Quotation marks inside string data, the parser cannot handle escaping
'
and"
inside their respective block (eg "bla ""quoted"" bla"). - ~~Expression data, not handled at all.~~ Supports non-nested numeric-/channel-list expressions
- Provide a reference instrument class implementation
- Error codes returned by the parser does not follow SCPI-99 accurately (because there's a fucking lot of them!).
- Working test suite.
- To be continued...
Nice to have
Not necessary for a 1.0.0 version but would be nice to have in no particular order.
- Arbitrary data block struct serializer/deserializer integration with packed_struct
- Support for overlapped commands using futures
- Working test suite.
- Double-precision float
f64
support. SCPI
Extensions
The parser extends the SCPI-99 standard with some custom syntax:
- UTF8 arbitrary data block,
#s"Detta är en utf8 sträng med roliga bokstäver
. Checked by the parser and emits a InvalidBlockData if the UTF8 data is malformed.
Contribution
Contributions are welcome because I don't know what the fuck I'm doing.
Project organisation:
example
- A simple example application used for testingexample-cortexm
- A simple example application used for testing in a embedded environment (Note: Readexample-cortexm/README.md
for build instructions)scpi
- Main libraryscpi_derive
- Internal macro support library, used byscpi
to generate error messages and suffixes (enter at own risk)scpi_instrument
- Support library which provides higher level abstraction
Modules
command | Command trait and helper functions. |
error | This module contains standard SCPI errors in the form of the Error enum. |
expression | |
ieee488 | Contains IEEE 488.2 parser and mandatory commands |
prelude | Prelude containing the most useful stuff |
response | |
scpi | Contains SCPI modules and mandatory commands |
suffix | |
tokenizer | |
tree | Used to build a SCPI command tree |
Macros
ieee488_idn | |
ieee488_cls | |
ieee488_ese | |
ieee488_esr | |
ieee488_opc | |
ieee488_rst | |
ieee488_sre | |
ieee488_stb | |
ieee488_tst | |
ieee488_wai | |
nquery | Creates a stub for query() |
qonly | Creates a stub for event() |
scpi_status | Create a |
scpi_system | Create a |
Structs
Context | Context in which to execute a message. |
Traits
Device | A SCPI device |