nanonis-rs 0.4.0

Rust client library for Nanonis SPM system control via TCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
use super::NanonisClient;
use crate::error::NanonisError;
use crate::types::NanonisValue;

/// PLL excitation output range.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PLLExcRange {
    /// 10V range
    #[default]
    V10 = 0,
    /// 1V range
    V1 = 1,
    /// 0.1V range
    V01 = 2,
    /// 0.01V range
    V001 = 3,
    /// 0.001V range
    V0001 = 4,
}

impl From<PLLExcRange> for u16 {
    fn from(r: PLLExcRange) -> Self {
        r as u16
    }
}

impl TryFrom<u16> for PLLExcRange {
    type Error = NanonisError;

    fn try_from(value: u16) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(PLLExcRange::V10),
            1 => Ok(PLLExcRange::V1),
            2 => Ok(PLLExcRange::V01),
            3 => Ok(PLLExcRange::V001),
            4 => Ok(PLLExcRange::V0001),
            _ => Err(NanonisError::Protocol(format!(
                "Invalid PLLExcRange value: {}",
                value
            ))),
        }
    }
}

/// PLL input properties.
#[derive(Debug, Clone, Copy, Default)]
pub struct PLLInputProps {
    /// Differential input enabled
    pub differential_input: bool,
    /// 1/10 divider enabled
    pub divider_1_10: bool,
}

/// PLL demodulator input configuration.
#[derive(Debug, Clone, Copy, Default)]
pub struct PLLDemodInput {
    /// Input selection
    pub input: u16,
    /// Frequency generator selection
    pub freq_generator: u16,
}

/// PLL frequency/excitation overwrite configuration.
#[derive(Debug, Clone, Copy, Default)]
pub struct PLLOverwrite {
    /// Excitation overwrite signal index (-1 for none)
    pub excitation_signal_index: i32,
    /// Frequency overwrite signal index (-1 for none)
    pub frequency_signal_index: i32,
}

/// PLL amplitude controller gain parameters.
#[derive(Debug, Clone, Copy, Default)]
pub struct PLLAmpCtrlGain {
    /// Proportional gain in V/m
    pub p_gain_v_per_m: f32,
    /// Time constant in seconds
    pub time_constant_s: f32,
    /// Integral gain in V/m/s (read-only, computed)
    pub integral_gain_v_per_m_s: f32,
}

/// PLL phase controller gain parameters.
#[derive(Debug, Clone, Copy, Default)]
pub struct PLLPhasCtrlGain {
    /// Proportional gain in Hz/deg
    pub p_gain_hz_per_deg: f32,
    /// Time constant in seconds
    pub time_constant_s: f32,
}

impl NanonisClient {
    // ==================== Input Configuration ====================

    /// Set the input calibration of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `calibration_m_per_v` - Input calibration in m/V
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_calibr_set(
        &mut self,
        modulator_index: i32,
        calibration_m_per_v: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.InpCalibrSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(calibration_m_per_v),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the input calibration of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Input calibration in m/V.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_calibr_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.InpCalibrGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the input range of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `input_range_m` - Input range in meters
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_range_set(
        &mut self,
        modulator_index: i32,
        input_range_m: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.InpRangeSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(input_range_m),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the input range of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Input range in meters.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_range_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.InpRangeGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the input properties of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `props` - Input properties
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_props_set(
        &mut self,
        modulator_index: i32,
        props: &PLLInputProps,
    ) -> Result<(), NanonisError> {
        let diff_flag = if props.differential_input { 1u16 } else { 0u16 };
        let div_flag = if props.divider_1_10 { 1u16 } else { 0u16 };
        self.quick_send(
            "PLL.InpPropsSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::U16(diff_flag),
                NanonisValue::U16(div_flag),
            ],
            vec!["i", "H", "H"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the input properties of the oscillation control module.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Input properties.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_inp_props_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<PLLInputProps, NanonisError> {
        let result = self.quick_send(
            "PLL.InpPropsGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["H", "H"],
        )?;

        if result.len() >= 2 {
            Ok(PLLInputProps {
                differential_input: result[0].as_u16()? != 0,
                divider_1_10: result[1].as_u16()? != 0,
            })
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Output Configuration ====================

    /// Set the add external signal status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `enabled` - True to add external signal to output
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_add_on_off_set(
        &mut self,
        modulator_index: i32,
        enabled: bool,
    ) -> Result<(), NanonisError> {
        let flag = if enabled { 1u32 } else { 0u32 };
        self.quick_send(
            "PLL.AddOnOffSet",
            vec![NanonisValue::I32(modulator_index), NanonisValue::U32(flag)],
            vec!["i", "I"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the add external signal status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// True if external signal is being added.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_add_on_off_get(&mut self, modulator_index: i32) -> Result<bool, NanonisError> {
        let result = self.quick_send(
            "PLL.AddOnOffGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["I"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_u32()? != 0)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the PLL output on/off status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `enabled` - True to enable PLL output
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_out_on_off_set(
        &mut self,
        modulator_index: i32,
        enabled: bool,
    ) -> Result<(), NanonisError> {
        let flag = if enabled { 1u32 } else { 0u32 };
        self.quick_send(
            "PLL.OutOnOffSet",
            vec![NanonisValue::I32(modulator_index), NanonisValue::U32(flag)],
            vec!["i", "I"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the PLL output on/off status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// True if PLL output is enabled.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_out_on_off_get(&mut self, modulator_index: i32) -> Result<bool, NanonisError> {
        let result = self.quick_send(
            "PLL.OutOnOffGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["I"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_u32()? != 0)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Excitation ====================

    /// Set the excitation range.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `range` - Excitation output range
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_exc_range_set(
        &mut self,
        modulator_index: i32,
        range: PLLExcRange,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.ExcRangeSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::U16(range.into()),
            ],
            vec!["i", "H"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the excitation range.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Excitation output range.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_exc_range_get(&mut self, modulator_index: i32) -> Result<PLLExcRange, NanonisError> {
        let result = self.quick_send(
            "PLL.ExcRangeGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["H"],
        )?;

        if !result.is_empty() {
            result[0].as_u16()?.try_into()
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the excitation value (drive amplitude).
    ///
    /// Only works when amplitude controller is off.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `excitation_v` - Excitation value in volts
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_excitation_set(
        &mut self,
        modulator_index: i32,
        excitation_v: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.ExcitationSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(excitation_v),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the excitation value (drive amplitude).
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Excitation value in volts.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_excitation_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.ExcitationGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Amplitude Controller ====================
    /// Set the amplitude controller setpoint for a PLL modulator.
    ///
    /// Sets the amplitude controller setpoint value for the specified PLL modulator.
    /// This controls the target oscillation amplitude for the phase-locked loop.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `setpoint_m` - Amplitude setpoint in meters
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Set amplitude setpoint for first PLL to 1 nanometer
    /// client.pll_amp_ctrl_setpnt_set(1, 1e-9)?;
    ///
    /// // Set amplitude setpoint for second PLL to 500 picometers
    /// client.pll_amp_ctrl_setpnt_set(2, 500e-12)?;
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_setpnt_set(
        &mut self,
        modulator_index: i32,
        setpoint_m: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.AmpCtrlSetpntSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(setpoint_m),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the amplitude controller setpoint for a PLL modulator.
    ///
    /// Returns the current amplitude controller setpoint value for the specified
    /// PLL modulator.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// * `f32` - Current amplitude setpoint in meters
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Get current amplitude setpoint for first PLL
    /// let setpoint = client.pll_amp_ctrl_setpnt_get(1)?;
    /// println!("Current amplitude setpoint: {:.2e} m", setpoint);
    ///
    /// // Check if setpoint is within expected range
    /// if setpoint > 1e-9 {
    ///     println!("Amplitude setpoint is greater than 1 nm");
    /// }
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_setpnt_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let response = self.quick_send(
            "PLL.AmpCtrlSetpntGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        match response.first() {
            Some(NanonisValue::F32(setpoint)) => Ok(*setpoint),
            _ => Err(NanonisError::Protocol(
                "Expected f32 amplitude setpoint".to_string(),
            )),
        }
    }

    /// Set the amplitude controller on/off status for a PLL modulator.
    ///
    /// Switches the amplitude controller for the specified PLL modulator on or off.
    /// When enabled, the amplitude controller actively maintains the oscillation
    /// amplitude at the setpoint value.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `status` - true to turn on, false to turn off
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Turn on amplitude controller for first PLL
    /// client.pll_amp_ctrl_on_off_set(1, true)?;
    ///
    /// // Turn off amplitude controller for second PLL
    /// client.pll_amp_ctrl_on_off_set(2, false)?;
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_on_off_set(
        &mut self,
        modulator_index: i32,
        status: bool,
    ) -> Result<(), NanonisError> {
        let status_u32 = if status { 1u32 } else { 0u32 };

        self.quick_send(
            "PLL.AmpCtrlOnOffSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::U32(status_u32),
            ],
            vec!["i", "I"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the amplitude controller on/off status for a PLL modulator.
    ///
    /// Returns the current on/off status of the amplitude controller for the
    /// specified PLL modulator.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// * `bool` - true if controller is on, false if off
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Check amplitude controller status for first PLL
    /// let is_on = client.pll_amp_ctrl_on_off_get(1)?;
    /// if is_on {
    ///     println!("Amplitude controller is active");
    /// } else {
    ///     println!("Amplitude controller is inactive");
    /// }
    ///
    /// // Enable controller if it's off
    /// if !is_on {
    ///     client.pll_amp_ctrl_on_off_set(1, true)?;
    /// }
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_on_off_get(&mut self, modulator_index: i32) -> Result<bool, NanonisError> {
        let response = self.quick_send(
            "PLL.AmpCtrlOnOffGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["I"],
        )?;

        match response.first() {
            Some(NanonisValue::U32(status)) => Ok(*status != 0),
            _ => Err(NanonisError::Protocol(
                "Expected u32 amplitude controller status".to_string(),
            )),
        }
    }

    /// Set the amplitude controller gain parameters for a PLL modulator.
    ///
    /// Sets the proportional gain and time constant for the amplitude controller
    /// of the specified PLL modulator. These parameters control the response
    /// characteristics of the amplitude control loop.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `p_gain_v_div_m` - Proportional gain in V/m
    /// * `time_constant_s` - Time constant in seconds
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Set moderate gain and fast response for first PLL
    /// client.pll_amp_ctrl_gain_set(1, 1e6, 0.01)?;
    ///
    /// // Set higher gain and slower response for second PLL
    /// client.pll_amp_ctrl_gain_set(2, 5e6, 0.1)?;
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_gain_set(
        &mut self,
        modulator_index: i32,
        p_gain_v_div_m: f32,
        time_constant_s: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.AmpCtrlGainSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(p_gain_v_div_m),
                NanonisValue::F32(time_constant_s),
            ],
            vec!["i", "f", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the amplitude controller gain parameters for a PLL modulator.
    ///
    /// Returns the current proportional gain and time constant settings for the
    /// amplitude controller of the specified PLL modulator.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// * `(f32, f32)` - Tuple of (proportional gain in V/m, time constant in seconds)
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails or invalid modulator index.
    ///
    /// # Examples
    /// ```no_run
    /// use nanonis_rs::NanonisClient;
    ///
    /// let mut client = NanonisClient::new("127.0.0.1", 6501)?;
    ///
    /// // Get current gain parameters for first PLL
    /// let (p_gain, time_const) = client.pll_amp_ctrl_gain_get(1)?;
    /// println!("P gain: {:.2e} V/m, Time constant: {:.3} s", p_gain, time_const);
    ///
    /// // Check if parameters are within acceptable range
    /// if p_gain < 1e5 {
    ///     println!("Warning: Low proportional gain");
    /// }
    /// if time_const > 1.0 {
    ///     println!("Warning: Slow time constant");
    /// }
    /// # Ok::<(), Box<dyn std::error::Error>>(())
    /// ```
    pub fn pll_amp_ctrl_gain_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<(f32, f32), NanonisError> {
        let response = self.quick_send(
            "PLL.AmpCtrlGainGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f", "f"],
        )?;

        match (response.first(), response.get(1)) {
            (Some(NanonisValue::F32(p_gain)), Some(NanonisValue::F32(time_const))) => {
                Ok((*p_gain, *time_const))
            }
            _ => Err(NanonisError::Protocol(
                "Expected f32 gain parameters (p_gain, time_constant)".to_string(),
            )),
        }
    }

    /// Set the amplitude controller bandwidth.
    ///
    /// Uses current Q factor and amplitude to excitation ratio.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `bandwidth_hz` - Bandwidth in Hz
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_amp_ctrl_bandwidth_set(
        &mut self,
        modulator_index: i32,
        bandwidth_hz: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.AmpCtrlBandwidthSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(bandwidth_hz),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the amplitude controller bandwidth.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Bandwidth in Hz.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_amp_ctrl_bandwidth_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.AmpCtrlBandwidthGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Phase Controller ====================

    /// Set the phase controller on/off status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `enabled` - True to enable phase controller
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_on_off_set(
        &mut self,
        modulator_index: i32,
        enabled: bool,
    ) -> Result<(), NanonisError> {
        let flag = if enabled { 1u32 } else { 0u32 };
        self.quick_send(
            "PLL.PhasCtrlOnOffSet",
            vec![NanonisValue::I32(modulator_index), NanonisValue::U32(flag)],
            vec!["i", "I"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the phase controller on/off status.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// True if phase controller is enabled.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_on_off_get(&mut self, modulator_index: i32) -> Result<bool, NanonisError> {
        let result = self.quick_send(
            "PLL.PhasCtrlOnOffGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["I"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_u32()? != 0)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the phase controller gain parameters.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `p_gain_hz_per_deg` - Proportional gain in Hz/deg
    /// * `time_constant_s` - Time constant in seconds
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_gain_set(
        &mut self,
        modulator_index: i32,
        p_gain_hz_per_deg: f32,
        time_constant_s: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.PhasCtrlGainSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(p_gain_hz_per_deg),
                NanonisValue::F32(time_constant_s),
            ],
            vec!["i", "f", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the phase controller gain parameters.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Phase controller gain parameters.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_gain_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<PLLPhasCtrlGain, NanonisError> {
        let result = self.quick_send(
            "PLL.PhasCtrlGainGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f", "f"],
        )?;

        if result.len() >= 2 {
            Ok(PLLPhasCtrlGain {
                p_gain_hz_per_deg: result[0].as_f32()?,
                time_constant_s: result[1].as_f32()?,
            })
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the phase controller bandwidth.
    ///
    /// Uses current Q factor.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `bandwidth_hz` - Bandwidth in Hz
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_bandwidth_set(
        &mut self,
        modulator_index: i32,
        bandwidth_hz: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.PhasCtrlBandwidthSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(bandwidth_hz),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the phase controller bandwidth.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Bandwidth in Hz.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_phas_ctrl_bandwidth_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.PhasCtrlBandwidthGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Frequency ====================

    /// Set the frequency range.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `freq_range_hz` - Frequency range in Hz
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_range_set(
        &mut self,
        modulator_index: i32,
        freq_range_hz: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.FreqRangeSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(freq_range_hz),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the frequency range.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Frequency range in Hz.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_range_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.FreqRangeGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the center frequency.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `center_freq_hz` - Center frequency in Hz
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_center_freq_set(
        &mut self,
        modulator_index: i32,
        center_freq_hz: f64,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.CenterFreqSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F64(center_freq_hz),
            ],
            vec!["i", "d"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the center frequency.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Center frequency in Hz.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_center_freq_get(&mut self, modulator_index: i32) -> Result<f64, NanonisError> {
        let result = self.quick_send(
            "PLL.CenterFreqGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["d"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f64()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the frequency shift.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `freq_shift_hz` - Frequency shift in Hz
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_shift_set(
        &mut self,
        modulator_index: i32,
        freq_shift_hz: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.FreqShiftSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::F32(freq_shift_hz),
            ],
            vec!["i", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the frequency shift.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Frequency shift in Hz.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_shift_get(&mut self, modulator_index: i32) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.FreqShiftGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Auto-center frequency shift.
    ///
    /// Adds current frequency shift to center frequency and sets frequency shift to zero.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_shift_auto_center(&mut self, modulator_index: i32) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.FreqShiftAutoCenter",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec![],
        )?;
        Ok(())
    }

    /// Set the frequency/excitation overwrite signals.
    ///
    /// Works when corresponding controller is not active.
    /// Use -2 for no change.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    /// * `overwrite` - Overwrite configuration
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_exc_overwrite_set(
        &mut self,
        modulator_index: i32,
        overwrite: &PLLOverwrite,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.FreqExcOverwriteSet",
            vec![
                NanonisValue::I32(modulator_index),
                NanonisValue::I32(overwrite.excitation_signal_index),
                NanonisValue::I32(overwrite.frequency_signal_index),
            ],
            vec!["i", "i", "i"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the frequency/excitation overwrite signals.
    ///
    /// # Arguments
    /// * `modulator_index` - PLL modulator index (starts from 1)
    ///
    /// # Returns
    /// Overwrite configuration.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_freq_exc_overwrite_get(
        &mut self,
        modulator_index: i32,
    ) -> Result<PLLOverwrite, NanonisError> {
        let result = self.quick_send(
            "PLL.FreqExcOverwriteGet",
            vec![NanonisValue::I32(modulator_index)],
            vec!["i"],
            vec!["i", "i"],
        )?;

        if result.len() >= 2 {
            Ok(PLLOverwrite {
                excitation_signal_index: result[0].as_i32()?,
                frequency_signal_index: result[1].as_i32()?,
            })
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    // ==================== Demodulator ====================

    /// Set the demodulator input and frequency generator.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    /// * `input` - Demodulator input configuration
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_input_set(
        &mut self,
        demodulator_index: u16,
        input: &PLLDemodInput,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.DemodInputSet",
            vec![
                NanonisValue::U16(demodulator_index),
                NanonisValue::U16(input.input),
                NanonisValue::U16(input.freq_generator),
            ],
            vec!["H", "H", "H"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the demodulator input and frequency generator.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    ///
    /// # Returns
    /// Demodulator input configuration.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_input_get(
        &mut self,
        demodulator_index: u16,
    ) -> Result<PLLDemodInput, NanonisError> {
        let result = self.quick_send(
            "PLL.DemodInputGet",
            vec![NanonisValue::U16(demodulator_index)],
            vec!["H"],
            vec!["H", "H"],
        )?;

        if result.len() >= 2 {
            Ok(PLLDemodInput {
                input: result[0].as_u16()?,
                freq_generator: result[1].as_u16()?,
            })
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the demodulator harmonic.
    ///
    /// Harmonic 1 corresponds to modulation frequency.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    /// * `harmonic` - Harmonic number
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_harmonic_set(
        &mut self,
        demodulator_index: u16,
        harmonic: u16,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.DemodHarmonicSet",
            vec![
                NanonisValue::U16(demodulator_index),
                NanonisValue::U16(harmonic),
            ],
            vec!["H", "H"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the demodulator harmonic.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    ///
    /// # Returns
    /// Harmonic number.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_harmonic_get(&mut self, demodulator_index: u16) -> Result<u16, NanonisError> {
        let result = self.quick_send(
            "PLL.DemodHarmonicGet",
            vec![NanonisValue::U16(demodulator_index)],
            vec!["H"],
            vec!["H"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_u16()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the demodulator phase reference.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    /// * `phase_deg` - Phase reference in degrees
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_phas_ref_set(
        &mut self,
        demodulator_index: u16,
        phase_deg: f32,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.DemodPhasRefSet",
            vec![
                NanonisValue::U16(demodulator_index),
                NanonisValue::F32(phase_deg),
            ],
            vec!["H", "f"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the demodulator phase reference.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    ///
    /// # Returns
    /// Phase reference in degrees.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_phas_ref_get(&mut self, demodulator_index: u16) -> Result<f32, NanonisError> {
        let result = self.quick_send(
            "PLL.DemodPhasRefGet",
            vec![NanonisValue::U16(demodulator_index)],
            vec!["H"],
            vec!["f"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_f32()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }

    /// Set the demodulator filter order.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    /// * `filter_order` - Low-pass filter order
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_filter_set(
        &mut self,
        demodulator_index: u16,
        filter_order: u16,
    ) -> Result<(), NanonisError> {
        self.quick_send(
            "PLL.DemodFilterSet",
            vec![
                NanonisValue::U16(demodulator_index),
                NanonisValue::U16(filter_order),
            ],
            vec!["H", "H"],
            vec![],
        )?;
        Ok(())
    }

    /// Get the demodulator filter order.
    ///
    /// # Arguments
    /// * `demodulator_index` - Demodulator index (starts from 1)
    ///
    /// # Returns
    /// Low-pass filter order.
    ///
    /// # Errors
    /// Returns `NanonisError` if communication fails.
    pub fn pll_demod_filter_get(&mut self, demodulator_index: u16) -> Result<u16, NanonisError> {
        let result = self.quick_send(
            "PLL.DemodFilterGet",
            vec![NanonisValue::U16(demodulator_index)],
            vec!["H"],
            vec!["H"],
        )?;

        if !result.is_empty() {
            Ok(result[0].as_u16()?)
        } else {
            Err(NanonisError::Protocol("Invalid response".to_string()))
        }
    }
}