scpi_contrib/ieee488/mod.rs
1//! Contains IEEE 488.2 parser and mandatory commands
2//!
3
4use scpi::error::Result;
5
6pub mod common;
7pub mod trg;
8
9pub mod prelude {
10 pub use super::{EventStatusBit, StatusBit, IEEE4882};
11}
12
13/// Event status/enable register bits
14#[derive(Debug, Clone, Copy)]
15pub enum EventStatusBit {
16 /// Operation complete
17 OperationComplete = 0,
18 /// Request control
19 RequestControl = 1,
20 /// Query error
21 QueryError = 2,
22 /// Device dependant error
23 DeviceDependantError = 3,
24 /// Execution error
25 ExecutionError = 4,
26 /// Command error
27 CommandError = 5,
28 /// User request
29 UserRequest = 6,
30 /// Power on
31 PowerOn = 7,
32}
33
34impl EventStatusBit {
35 pub fn mask(&self) -> u8 {
36 (0x01 << *self as usize) as u8
37 }
38}
39
40/// Status byte bits
41#[derive(Debug, Clone, Copy)]
42pub enum StatusBit {
43 /// Designer bit 0
44 Designer0 = 0,
45 /// Designer bit 1
46 Designer1 = 1,
47 /// Error/Event queue bit or designer bit 2
48 ErrorEventQueue = 2,
49 /// Questionable summary bit or designer bit 3
50 Questionable = 3,
51 /// Message available bit
52 Mav = 4,
53 /// Event status bit
54 Esb = 5,
55 /// RQS or MSS bit
56 RqsMss = 6,
57 /// Operation summary bit or designer bit 7
58 Operation = 7,
59}
60
61impl StatusBit {
62 pub fn mask(&self) -> u8 {
63 (0x01 << *self as usize) as u8
64 }
65}
66
67pub trait IEEE4882 {
68 /// Read Status byte register
69 fn stb(&self) -> u8 {
70 let mut stb = 0x00;
71 // ESB
72 if self.esr() & self.ese() != 0 {
73 stb |= StatusBit::Esb.mask();
74 }
75 // MSS
76 if stb & self.sre() != 0 {
77 stb |= StatusBit::RqsMss.mask();
78 }
79 stb
80 }
81
82 /// Service Request Enable register
83 fn sre(&self) -> u8;
84 /// Set the SRE register
85 fn set_sre(&mut self, value: u8);
86
87 /// Event Status Register
88 fn esr(&self) -> u8;
89 /// Set the ESR register
90 fn set_esr(&mut self, value: u8);
91
92 /// Event Status Enable Register
93 fn ese(&self) -> u8;
94 /// Set the ESE register
95 fn set_ese(&mut self, value: u8);
96
97 /// # *TST
98 /// Executed when a `*TST` command is issued.
99 /// See [crate::ieee488::common::TstCommand] for details.
100 ///
101 /// Return Ok(()) on successfull self-test or
102 /// some kind of standard or device-specific error on self-test fault
103 fn tst(&mut self) -> Result<()>;
104
105 /// # *RST
106 /// Executed when a `*RST` command is issued.
107 /// See [crate::ieee488::common::RstCommand] for details.
108 fn rst(&mut self) -> Result<()>;
109
110 /// # *CLS
111 /// Executed when a `*CLS` command is issued.
112 /// See [crate::ieee488::common::ClsCommand] for details.
113 fn cls(&mut self) -> Result<()>;
114
115 /// # *OPC
116 /// Executed when a `*OPC` command is issued.
117 /// See [crate::ieee488::common::OpcCommand] for details.
118 fn opc(&mut self) -> Result<()>;
119}