Skip to main content

nanonis_rs/client/
interf.rs

1use super::NanonisClient;
2use crate::error::NanonisError;
3use crate::types::NanonisValue;
4
5/// Interferometer controller properties.
6#[derive(Debug, Clone, Copy, Default)]
7pub struct InterfCtrlProps {
8    /// Integral gain
9    pub integral: f32,
10    /// Proportional gain
11    pub proportional: f32,
12    /// Sign (true = positive, false = negative)
13    pub positive_sign: bool,
14}
15
16impl NanonisClient {
17    // ==================== Interferometer ====================
18
19    /// Switch the interferometer controller on or off.
20    ///
21    /// # Arguments
22    /// * `on` - True to enable, false to disable
23    ///
24    /// # Errors
25    /// Returns `NanonisError` if communication fails.
26    pub fn interf_ctrl_on_off_set(&mut self, on: bool) -> Result<(), NanonisError> {
27        self.quick_send(
28            "Interf.CtrlOnOffSet",
29            vec![NanonisValue::U32(if on { 1 } else { 0 })],
30            vec!["I"],
31            vec![],
32        )?;
33        Ok(())
34    }
35
36    /// Get the status of the interferometer controller.
37    ///
38    /// # Returns
39    /// True if controller is on.
40    ///
41    /// # Errors
42    /// Returns `NanonisError` if communication fails.
43    pub fn interf_ctrl_on_off_get(&mut self) -> Result<bool, NanonisError> {
44        let result = self.quick_send("Interf.CtrlOnOffGet", vec![], vec![], vec!["I"])?;
45
46        Ok(result[0].as_u32()? != 0)
47    }
48
49    /// Set the interferometer controller properties.
50    ///
51    /// # Arguments
52    /// * `props` - Controller properties
53    ///
54    /// # Errors
55    /// Returns `NanonisError` if communication fails.
56    pub fn interf_ctrl_props_set(&mut self, props: &InterfCtrlProps) -> Result<(), NanonisError> {
57        self.quick_send(
58            "Interf.CtrlPropsSet",
59            vec![
60                NanonisValue::F32(props.integral),
61                NanonisValue::F32(props.proportional),
62                NanonisValue::U32(if props.positive_sign { 1 } else { 0 }),
63            ],
64            vec!["f", "f", "I"],
65            vec![],
66        )?;
67        Ok(())
68    }
69
70    /// Get the interferometer controller properties.
71    ///
72    /// # Returns
73    /// Controller properties.
74    ///
75    /// # Errors
76    /// Returns `NanonisError` if communication fails.
77    pub fn interf_ctrl_props_get(&mut self) -> Result<InterfCtrlProps, NanonisError> {
78        let result = self.quick_send("Interf.CtrlPropsGet", vec![], vec![], vec!["f", "f", "I"])?;
79
80        Ok(InterfCtrlProps {
81            integral: result[0].as_f32()?,
82            proportional: result[1].as_f32()?,
83            positive_sign: result[2].as_u32()? != 0,
84        })
85    }
86
87    /// Set the W-piezo position.
88    ///
89    /// The interferometer controller must be off to change this.
90    ///
91    /// # Arguments
92    /// * `w_piezo` - W-piezo position value
93    ///
94    /// # Errors
95    /// Returns `NanonisError` if communication fails.
96    pub fn interf_w_piezo_set(&mut self, w_piezo: f32) -> Result<(), NanonisError> {
97        self.quick_send(
98            "Interf.WPiezoSet",
99            vec![NanonisValue::F32(w_piezo)],
100            vec!["f"],
101            vec![],
102        )?;
103        Ok(())
104    }
105
106    /// Get the W-piezo position.
107    ///
108    /// # Returns
109    /// W-piezo position value.
110    ///
111    /// # Errors
112    /// Returns `NanonisError` if communication fails.
113    pub fn interf_w_piezo_get(&mut self) -> Result<f32, NanonisError> {
114        let result = self.quick_send("Interf.WPiezoGet", vec![], vec![], vec!["f"])?;
115
116        result[0].as_f32()
117    }
118
119    /// Get the interferometer value.
120    ///
121    /// # Returns
122    /// Interferometer value.
123    ///
124    /// # Errors
125    /// Returns `NanonisError` if communication fails.
126    pub fn interf_val_get(&mut self) -> Result<f32, NanonisError> {
127        let result = self.quick_send("Interf.ValGet", vec![], vec![], vec!["f"])?;
128
129        result[0].as_f32()
130    }
131
132    /// Open the calibration panel for the interferometer controller.
133    ///
134    /// # Errors
135    /// Returns `NanonisError` if communication fails.
136    pub fn interf_ctrl_calibr_open(&mut self) -> Result<(), NanonisError> {
137        self.quick_send("Interf.CtrlCalibrOpen", vec![], vec![], vec![])?;
138        Ok(())
139    }
140
141    /// Reset the interferometer controller.
142    ///
143    /// # Errors
144    /// Returns `NanonisError` if communication fails.
145    pub fn interf_ctrl_reset(&mut self) -> Result<(), NanonisError> {
146        self.quick_send("Interf.CtrlReset", vec![], vec![], vec![])?;
147        Ok(())
148    }
149
150    /// Apply null deflection to the interferometer controller.
151    ///
152    /// # Errors
153    /// Returns `NanonisError` if communication fails.
154    pub fn interf_ctrl_null_defl(&mut self) -> Result<(), NanonisError> {
155        self.quick_send("Interf.CtrlNullDefl", vec![], vec![], vec![])?;
156        Ok(())
157    }
158}