rusty_tip/nanonis/client/
osci_hr.rs

1use super::NanonisClient;
2use crate::error::NanonisError;
3use crate::types::{
4    NanonisValue, OscilloscopeIndex, SampleCount, SignalIndex, TriggerLevel,
5    TriggerMode,
6};
7
8impl NanonisClient {
9    /// Set the measured signal index of the selected channel from the Oscilloscope High Resolution
10    pub fn osci_hr_ch_set(
11        &mut self,
12        osci_index: impl Into<OscilloscopeIndex>,
13        signal_index: impl Into<SignalIndex>,
14    ) -> Result<(), NanonisError> {
15        self.quick_send(
16            "OsciHR.ChSet",
17            vec![
18                NanonisValue::I32(osci_index.into().into()),
19                NanonisValue::I32(signal_index.into().into()),
20            ],
21            vec!["i", "i"],
22            vec![],
23        )?;
24        Ok(())
25    }
26
27    /// Get the measured signal index of the selected channel from the Oscilloscope High Resolution
28    pub fn osci_hr_ch_get(
29        &mut self,
30        osci_index: impl Into<OscilloscopeIndex>,
31    ) -> Result<SignalIndex, NanonisError> {
32        let result = self.quick_send(
33            "OsciHR.ChGet",
34            vec![NanonisValue::I32(osci_index.into().into())],
35            vec!["i"],
36            vec!["i"],
37        )?;
38        match result.first() {
39            Some(value) => Ok(SignalIndex(value.as_i32()?)),
40            None => Err(NanonisError::Protocol(
41                "No signal index returned".to_string(),
42            )),
43        }
44    }
45
46    /// Set the oversampling index of the Oscilloscope High Resolution
47    pub fn osci_hr_oversampl_set(
48        &mut self,
49        oversampling_index: i32,
50    ) -> Result<(), NanonisError> {
51        self.quick_send(
52            "OsciHR.OversamplSet",
53            vec![NanonisValue::I32(oversampling_index)],
54            vec!["i"],
55            vec![],
56        )?;
57        Ok(())
58    }
59
60    /// Get the oversampling index of the Oscilloscope High Resolution
61    pub fn osci_hr_oversampl_get(&mut self) -> Result<i32, NanonisError> {
62        let result =
63            self.quick_send("OsciHR.OversamplGet", vec![], vec![], vec!["i"])?;
64        match result.first() {
65            Some(value) => Ok(value.as_i32()?),
66            None => Err(NanonisError::Protocol(
67                "No oversampling index returned".to_string(),
68            )),
69        }
70    }
71
72    /// Set the calibration mode of the selected channel from the Oscilloscope High Resolution
73    /// calibration_mode: 0 = Raw values, 1 = Calibrated values
74    pub fn osci_hr_calibr_mode_set(
75        &mut self,
76        osci_index: i32,
77        calibration_mode: u16,
78    ) -> Result<(), NanonisError> {
79        self.quick_send(
80            "OsciHR.CalibrModeSet",
81            vec![
82                NanonisValue::I32(osci_index),
83                NanonisValue::U16(calibration_mode),
84            ],
85            vec!["i", "H"],
86            vec![],
87        )?;
88        Ok(())
89    }
90
91    /// Get the calibration mode of the selected channel from the Oscilloscope High Resolution
92    /// Returns: 0 = Raw values, 1 = Calibrated values
93    pub fn osci_hr_calibr_mode_get(
94        &mut self,
95        osci_index: i32,
96    ) -> Result<u16, NanonisError> {
97        let result = self.quick_send(
98            "OsciHR.CalibrModeGet",
99            vec![NanonisValue::I32(osci_index)],
100            vec!["i"],
101            vec!["H"],
102        )?;
103        match result.first() {
104            Some(value) => Ok(value.as_u16()?),
105            None => Err(NanonisError::Protocol(
106                "No calibration mode returned".to_string(),
107            )),
108        }
109    }
110
111    /// Set the number of samples to acquire in the Oscilloscope High Resolution
112    pub fn osci_hr_samples_set(
113        &mut self,
114        number_of_samples: impl Into<SampleCount>,
115    ) -> Result<(), NanonisError> {
116        self.quick_send(
117            "OsciHR.SamplesSet",
118            vec![NanonisValue::I32(number_of_samples.into().into())],
119            vec!["i"],
120            vec![],
121        )?;
122        Ok(())
123    }
124
125    /// Get the number of samples to acquire in the Oscilloscope High Resolution
126    pub fn osci_hr_samples_get(&mut self) -> Result<SampleCount, NanonisError> {
127        let result =
128            self.quick_send("OsciHR.SamplesGet", vec![], vec![], vec!["i"])?;
129        match result.first() {
130            Some(value) => Ok(SampleCount::new(value.as_i32()?)),
131            None => Err(NanonisError::Protocol(
132                "No sample count returned".to_string(),
133            )),
134        }
135    }
136
137    /// Set the Pre-Trigger Samples or Seconds in the Oscilloscope High Resolution
138    pub fn osci_hr_pre_trig_set(
139        &mut self,
140        pre_trigger_samples: u32,
141        pre_trigger_s: f64,
142    ) -> Result<(), NanonisError> {
143        self.quick_send(
144            "OsciHR.PreTrigSet",
145            vec![
146                NanonisValue::U32(pre_trigger_samples),
147                NanonisValue::F64(pre_trigger_s),
148            ],
149            vec!["I", "d"],
150            vec![],
151        )?;
152        Ok(())
153    }
154
155    /// Get the Pre-Trigger Samples in the Oscilloscope High Resolution
156    pub fn osci_hr_pre_trig_get(&mut self) -> Result<i32, NanonisError> {
157        let result =
158            self.quick_send("OsciHR.PreTrigGet", vec![], vec![], vec!["i"])?;
159        match result.first() {
160            Some(value) => Ok(value.as_i32()?),
161            None => Err(NanonisError::Protocol(
162                "No pre-trigger samples returned".to_string(),
163            )),
164        }
165    }
166
167    /// Start the Oscilloscope High Resolution module
168    pub fn osci_hr_run(&mut self) -> Result<(), NanonisError> {
169        self.quick_send("OsciHR.Run", vec![], vec![], vec![])?;
170        Ok(())
171    }
172
173    /// Get the graph data of the selected channel from the Oscilloscope High Resolution
174    /// data_to_get: 0 = Current returns the currently displayed data, 1 = Next trigger waits for the next trigger
175    /// Returns: (timestamp, time_delta, data_values, timeout_occurred)
176    pub fn osci_hr_osci_data_get(
177        &mut self,
178        osci_index: i32,
179        data_to_get: u16,
180        timeout_s: f64,
181    ) -> Result<(String, f64, Vec<f32>, bool), NanonisError> {
182        let result = self.quick_send(
183            "OsciHR.OsciDataGet",
184            vec![
185                NanonisValue::I32(osci_index),
186                NanonisValue::U16(data_to_get),
187                NanonisValue::F64(timeout_s),
188            ],
189            vec!["i", "H", "d"],
190            vec!["i", "*-c", "d", "i", "*f", "I"],
191        )?;
192
193        if result.len() >= 6 {
194            let timestamp = result[1].as_string()?.to_string();
195            let time_delta = result[2].as_f64()?;
196            let data_values = result[4].as_f32_array()?.to_vec();
197            let timeout_occurred = result[5].as_u32()? == 1;
198            Ok((timestamp, time_delta, data_values, timeout_occurred))
199        } else {
200            Err(NanonisError::Protocol(
201                "Invalid oscilloscope data response".to_string(),
202            ))
203        }
204    }
205
206    /// Set the trigger mode in the Oscilloscope High Resolution
207    pub fn osci_hr_trig_mode_set(
208        &mut self,
209        trigger_mode: impl Into<TriggerMode>,
210    ) -> Result<(), NanonisError> {
211        self.quick_send(
212            "OsciHR.TrigModeSet",
213            vec![NanonisValue::U16(trigger_mode.into().into())],
214            vec!["H"],
215            vec![],
216        )?;
217        Ok(())
218    }
219
220    /// Get the trigger mode in the Oscilloscope High Resolution
221    pub fn osci_hr_trig_mode_get(&mut self) -> Result<TriggerMode, NanonisError> {
222        let result =
223            self.quick_send("OsciHR.TrigModeGet", vec![], vec![], vec!["H"])?;
224        match result.first() {
225            Some(value) => {
226                let mode_val = value.as_u16()?;
227                match mode_val {
228                    0 => Ok(TriggerMode::Immediate),
229                    1 => Ok(TriggerMode::Level),
230                    2 => Ok(TriggerMode::Digital),
231                    _ => Err(NanonisError::Protocol(format!(
232                        "Unknown trigger mode: {}",
233                        mode_val
234                    ))),
235                }
236            }
237            None => Err(NanonisError::Protocol(
238                "No trigger mode returned".to_string(),
239            )),
240        }
241    }
242
243    /// Set the Level Trigger Channel index in the Oscilloscope High Resolution
244    pub fn osci_hr_trig_lev_ch_set(
245        &mut self,
246        level_trigger_channel_index: i32,
247    ) -> Result<(), NanonisError> {
248        self.quick_send(
249            "OsciHR.TrigLevChSet",
250            vec![NanonisValue::I32(level_trigger_channel_index)],
251            vec!["i"],
252            vec![],
253        )?;
254        Ok(())
255    }
256
257    /// Get the Level Trigger Channel index in the Oscilloscope High Resolution
258    pub fn osci_hr_trig_lev_ch_get(&mut self) -> Result<i32, NanonisError> {
259        let result =
260            self.quick_send("OsciHR.TrigLevChGet", vec![], vec![], vec!["i"])?;
261        match result.first() {
262            Some(value) => Ok(value.as_i32()?),
263            None => Err(NanonisError::Protocol(
264                "No level trigger channel returned".to_string(),
265            )),
266        }
267    }
268
269    /// Set the Level Trigger value in the Oscilloscope High Resolution
270    pub fn osci_hr_trig_lev_val_set(
271        &mut self,
272        level_trigger_value: impl Into<TriggerLevel>,
273    ) -> Result<(), NanonisError> {
274        self.quick_send(
275            "OsciHR.TrigLevValSet",
276            vec![NanonisValue::F64(level_trigger_value.into().into())],
277            vec!["d"],
278            vec![],
279        )?;
280        Ok(())
281    }
282
283    /// Get the Level Trigger value in the Oscilloscope High Resolution
284    pub fn osci_hr_trig_lev_val_get(
285        &mut self,
286    ) -> Result<TriggerLevel, NanonisError> {
287        let result =
288            self.quick_send("OsciHR.TrigLevValGet", vec![], vec![], vec!["d"])?;
289        match result.first() {
290            Some(value) => Ok(TriggerLevel(value.as_f64()?)),
291            None => Err(NanonisError::Protocol(
292                "No level trigger value returned".to_string(),
293            )),
294        }
295    }
296
297    /// Set the Trigger Arming Mode in the Oscilloscope High Resolution
298    pub fn osci_hr_trig_arm_mode_set(
299        &mut self,
300        trigger_arming_mode: u16,
301    ) -> Result<(), NanonisError> {
302        self.quick_send(
303            "OsciHR.TrigArmModeSet",
304            vec![NanonisValue::U16(trigger_arming_mode)],
305            vec!["H"],
306            vec![],
307        )?;
308        Ok(())
309    }
310
311    /// Get the Trigger Arming Mode in the Oscilloscope High Resolution
312    pub fn osci_hr_trig_arm_mode_get(&mut self) -> Result<u16, NanonisError> {
313        let result =
314            self.quick_send("OsciHR.TrigArmModeGet", vec![], vec![], vec!["H"])?;
315        match result.first() {
316            Some(value) => Ok(value.as_u16()?),
317            None => Err(NanonisError::Protocol(
318                "No trigger arming mode returned".to_string(),
319            )),
320        }
321    }
322
323    /// Set the Level Trigger Hysteresis in the Oscilloscope High Resolution
324    pub fn osci_hr_trig_lev_hyst_set(
325        &mut self,
326        hysteresis: f64,
327    ) -> Result<(), NanonisError> {
328        self.quick_send(
329            "OsciHR.TrigLevHystSet",
330            vec![NanonisValue::F64(hysteresis)],
331            vec!["d"],
332            vec![],
333        )?;
334        Ok(())
335    }
336
337    /// Get the Level Trigger Hysteresis in the Oscilloscope High Resolution
338    pub fn osci_hr_trig_lev_hyst_get(&mut self) -> Result<f64, NanonisError> {
339        let result =
340            self.quick_send("OsciHR.TrigLevHystGet", vec![], vec![], vec!["d"])?;
341        match result.first() {
342            Some(value) => Ok(value.as_f64()?),
343            None => Err(NanonisError::Protocol(
344                "No trigger hysteresis returned".to_string(),
345            )),
346        }
347    }
348
349    /// Set the Level Trigger Slope in the Oscilloscope High Resolution
350    pub fn osci_hr_trig_lev_slope_set(
351        &mut self,
352        slope: u16,
353    ) -> Result<(), NanonisError> {
354        self.quick_send(
355            "OsciHR.TrigLevSlopeSet",
356            vec![NanonisValue::U16(slope)],
357            vec!["H"],
358            vec![],
359        )?;
360        Ok(())
361    }
362
363    /// Get the Level Trigger Slope in the Oscilloscope High Resolution
364    pub fn osci_hr_trig_lev_slope_get(&mut self) -> Result<u16, NanonisError> {
365        let result =
366            self.quick_send("OsciHR.TrigLevSlopeGet", vec![], vec![], vec!["H"])?;
367        match result.first() {
368            Some(value) => Ok(value.as_u16()?),
369            None => Err(NanonisError::Protocol(
370                "No trigger slope returned".to_string(),
371            )),
372        }
373    }
374}