Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions microscpi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ pub fn interface(attr: TokenStream, item: TokenStream) -> TokenStream {
handler: CommandHandler::StandardFunction("ErrorCommands::system_error_count"),
future: false,
});

command_set.push(CommandDefinition {
id: None,
args: Vec::new(),
command: Command::try_from("SYSTem:ERRor:ALL?").unwrap(),
handler: CommandHandler::StandardFunction("ErrorCommands::system_error_all"),
future: false,
});
}

if config.status_commands {
Expand Down
13 changes: 8 additions & 5 deletions microscpi-macros/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl std::fmt::Display for Error {
type NodeId = usize;

/// Represents a tree of SCPI commands.
///
///
/// The tree is used to efficiently look up command handlers based on the parsed command string.
/// It maps each component of a command path to the appropriate handler function.
pub struct Tree {
Expand All @@ -37,7 +37,7 @@ pub struct Tree {
}

/// A node in the SCPI command tree.
///
///
/// Each node can have:
/// - Children nodes representing the next part of a command
/// - An optional command handler for when this node is a command endpoint
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Tree {
/// - "STATUS:EVENT?"
/// - "STAT:EVENT?"
/// - "EVENT?" (since STATUS is optional)
///
///
/// # Arguments
/// * `cmd` - The command definition to insert
///
Expand Down Expand Up @@ -128,8 +128,11 @@ impl Tree {
self.insert_at(node_id, &path[1..], cmd)?;
} else {
// We've reached the end of the path, register the command here
let node = self.items.get_mut(&id).expect("Node ID must exist in the tree");

let node = self
.items
.get_mut(&id)
.expect("Node ID must exist in the tree");

if cmd.command.is_query() {
// This is a query command (ends with '?')
if let Some(existing) = &node.query {
Expand Down
16 changes: 14 additions & 2 deletions microscpi/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ pub trait ErrorCommands {
Ok((0, ""))
}
}

fn system_error_all(&mut self) -> Result<Vec<(i16, &'static str)>, Error> {
let errors = self.error_queue().all();
if !errors.is_empty() {
Ok(errors
.iter()
.map(|error| (error.number(), (*error).into()))
.collect::<Vec<_>>())
} else {
Ok(vec![(0, "")])
}
}
}

impl<I> ErrorHandler for I
Expand Down Expand Up @@ -115,10 +127,10 @@ pub trait StatusCommands: ErrorCommands {
let value = self.status_registers().event_status;
let mask = self.status_registers().event_status_enable;
let result = value.intersection(mask).bits();

// Clear the event status register after reading (per SCPI standard)
self.status_registers().event_status = EventStatus::empty();

Ok(result)
}

Expand Down
6 changes: 6 additions & 0 deletions microscpi/src/error_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub trait ErrorQueue: Default {
/// Get and remove the error in the front of the error queue. If the queue
/// is empty, [None] is returned.
fn pop_error(&mut self) -> Option<Error>;
/// Get all errors list
fn all(&self) -> Vec<Error>;
/// Clear the error queue.
fn clear(&mut self);
}
Expand Down Expand Up @@ -51,6 +53,10 @@ impl<const N: usize> ErrorQueue for StaticErrorQueue<N> {
self.0.len()
}

fn all(&self) -> Vec<Error> {
self.0.iter().copied().collect()
}

fn clear(&mut self) {
self.0.clear();
}
Expand Down
4 changes: 2 additions & 2 deletions microscpi/src/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl Default for StatusRegisters {
Self {
event_status: EventStatus::POWER_ON,
event_status_enable: EventStatus::all(),
status_byte_enable: StatusByte::all()
& !StatusByte::IMPLEMENTOR_DEFINED_1
status_byte_enable: StatusByte::all()
& !StatusByte::IMPLEMENTOR_DEFINED_1
& !StatusByte::IMPLEMENTOR_DEFINED_0,
}
}
Expand Down
Loading