rusty_tip/nanonis/client/
folme.rs

1use super::NanonisClient;
2use crate::error::NanonisError;
3use crate::types::{NanonisValue, Position};
4
5impl NanonisClient {
6    /// Get the current x-y position
7    pub fn folme_xy_pos_get(
8        &mut self,
9        wait_for_newest_data: bool,
10    ) -> Result<Position, NanonisError> {
11        let wait_flag = if wait_for_newest_data { 1u32 } else { 0u32 };
12        let result = self.quick_send(
13            "FolMe.XYPosGet",
14            vec![NanonisValue::U32(wait_flag)],
15            vec!["I"],
16            vec!["d", "d"],
17        )?;
18
19        if result.len() >= 2 {
20            Ok(Position {
21                x: result[0].as_f64()?,
22                y: result[1].as_f64()?,
23            })
24        } else {
25            Err(NanonisError::Protocol(
26                "Invalid position response".to_string(),
27            ))
28        }
29    }
30
31    /// Set the x-y position
32    pub fn folme_xy_pos_set(
33        &mut self,
34        position: Position,
35        wait_until_finished: bool,
36    ) -> Result<(), NanonisError> {
37        let wait_flag = if wait_until_finished { 1u32 } else { 0u32 };
38        self.quick_send(
39            "FolMe.XYPosSet",
40            vec![
41                NanonisValue::F64(position.x),
42                NanonisValue::F64(position.y),
43                NanonisValue::U32(wait_flag),
44            ],
45            vec!["d", "d", "I"],
46            vec![],
47        )?;
48        Ok(())
49    }
50    pub fn folme_speed_set(
51        &mut self,
52        speed: f32,
53        custom_speed: bool,
54    ) -> Result<(), NanonisError> {
55        let custom_speed_flag = if custom_speed { 1u32 } else { 0u32 };
56        self.quick_send(
57            "FolMe.Speed",
58            vec![
59                NanonisValue::F32(speed),
60                NanonisValue::U32(custom_speed_flag),
61            ],
62            vec!["f", "I"],
63            vec![],
64        )?;
65        Ok(())
66    }
67}