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
use crate::enums::{AnalogRoute, DigIoPinMode, FanMode, FanTempSource, TlpmAttribute};
use crate::error::TlpmError;
use crate::{PowerMeter, VI_FALSE, VI_TRUE, sys};
use std::ffi::CStr;
impl PowerMeter {
/// Set the fan control mode.
///
/// # Arguments
///
/// * `mode` - The `FanMode` to configure.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_fan_mode(&self, mode: FanMode, channel: u16) -> Result<(), TlpmError> {
tracing::debug!("setting fan mode to {:?} on channel {}", mode, channel);
self.check_status(
unsafe { sys::TLPMX_setFanMode(self.session, mode as u16, channel) },
"set_fan_mode",
)
}
/// Read the currently configured fan control mode.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// The currently configured `FanMode`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code,
/// or `TlpmError::InvalidEnumValue` if an unrecognized mode code is returned.
pub fn get_fan_mode(&self, channel: u16) -> Result<FanMode, TlpmError> {
tracing::debug!("getting fan mode on channel {}", channel);
let mut mode_code: u16 = 0;
self.check_status(
unsafe { sys::TLPMX_getFanMode(self.session, &mut mode_code, channel) },
"get_fan_mode",
)?;
FanMode::try_from(mode_code)
}
/// Set the fan temperature control source.
///
/// # Arguments
///
/// * `source` - The `FanTempSource` to configure.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_fan_temperature_source(
&self,
source: FanTempSource,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting fan temperature source to {:?} on channel {}",
source,
channel
);
self.check_status(
unsafe { sys::TLPMX_setFanTemperatureSource(self.session, source as u16, channel) },
"set_fan_temperature_source",
)
}
/// Read the currently configured fan temperature control source.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// The currently configured `FanTempSource`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code,
/// or `TlpmError::InvalidEnumValue` if an unrecognized source code is returned.
pub fn get_fan_temperature_source(&self, channel: u16) -> Result<FanTempSource, TlpmError> {
tracing::debug!("getting fan temperature source on channel {}", channel);
let mut source_code: u16 = 0;
self.check_status(
unsafe { sys::TLPMX_getFanTemperatureSource(self.session, &mut source_code, channel) },
"get_fan_temperature_source",
)?;
FanTempSource::try_from(source_code)
}
/// Retrieve the current running state of the fan.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// `true` if the fan is running, `false` otherwise.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_fan_state(&self, channel: u16) -> Result<bool, TlpmError> {
tracing::debug!("getting fan state on channel {}", channel);
let mut is_running: sys::ViBoolean = 0;
self.check_status(
unsafe { sys::TLPMX_getFanState(self.session, &mut is_running, channel) },
"get_fan_state",
)?;
Ok(is_running == VI_TRUE)
}
/// Set the fan voltage.
///
/// # Arguments
///
/// * `voltage` - The voltage to apply.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_fan_voltage(&self, voltage: f64, channel: u16) -> Result<(), TlpmError> {
tracing::debug!("setting fan voltage to {} on channel {}", voltage, channel);
self.check_status(
unsafe { sys::TLPMX_setFanVoltage(self.session, voltage, channel) },
"set_fan_voltage",
)
}
/// Retrieve the currently configured fan voltage.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// The currently configured fan voltage.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_fan_voltage(&self, channel: u16) -> Result<f64, TlpmError> {
tracing::debug!("getting fan voltage on channel {}", channel);
let mut voltage: f64 = 0.0;
self.check_status(
unsafe { sys::TLPMX_getFanVoltage(self.session, &mut voltage, channel) },
"get_fan_voltage",
)?;
Ok(voltage)
}
/// Set the maximum and target RPM for the fan.
///
/// # Arguments
///
/// * `max_rpm` - The maximum RPM value.
/// * `target_rpm` - The target RPM value.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_fan_rpm(
&self,
max_rpm: f64,
target_rpm: f64,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!("setting fan rpm on channel {}", channel);
self.check_status(
unsafe { sys::TLPMX_setFanRpm(self.session, max_rpm, target_rpm, channel) },
"set_fan_rpm",
)
}
/// Retrieve the maximum and target RPM for the fan.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(max_rpm, target_rpm)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_fan_rpm(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting fan rpm on channel {}", channel);
let mut max_rpm: f64 = 0.0;
let mut target_rpm: f64 = 0.0;
self.check_status(
unsafe { sys::TLPMX_getFanRpm(self.session, &mut max_rpm, &mut target_rpm, channel) },
"get_fan_rpm",
)?;
Ok((max_rpm, target_rpm))
}
/// Retrieve the actual current RPM of the fan.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// The actual measured RPM of the fan.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_act_fan_rpm(&self, channel: u16) -> Result<f64, TlpmError> {
tracing::debug!("getting actual fan rpm on channel {}", channel);
let mut rpm: f64 = 0.0;
self.check_status(
unsafe { sys::TLPMX_getActFanRpm(self.session, &mut rpm, channel) },
"get_act_fan_rpm",
)?;
Ok(rpm)
}
/// Set the fan temperature adjustment parameters.
///
/// # Arguments
///
/// * `voltage_min` - The minimum voltage.
/// * `voltage_max` - The maximum voltage.
/// * `temperature_min` - The minimum temperature.
/// * `temperature_max` - The maximum temperature.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_fan_adjust_parameters(
&self,
voltage_min: f64,
voltage_max: f64,
temperature_min: f64,
temperature_max: f64,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!("setting fan adjust parameters on channel {}", channel);
self.check_status(
unsafe {
sys::TLPMX_setFanAdjustParameters(
self.session,
voltage_min,
voltage_max,
temperature_min,
temperature_max,
channel,
)
},
"set_fan_adjust_parameters",
)
}
/// Retrieve the fan temperature adjustment parameters.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(voltage_min, voltage_max, temperature_min, temperature_max)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_fan_adjust_parameters(
&self,
channel: u16,
) -> Result<(f64, f64, f64, f64), TlpmError> {
tracing::debug!("getting fan adjust parameters on channel {}", channel);
let mut v_min: f64 = 0.0;
let mut v_max: f64 = 0.0;
let mut t_min: f64 = 0.0;
let mut t_max: f64 = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getFanAdjustParameters(
self.session,
&mut v_min,
&mut v_max,
&mut t_min,
&mut t_max,
channel,
)
},
"get_fan_adjust_parameters",
)?;
Ok((v_min, v_max, t_min, t_max))
}
/// Set the analog output routing strategy.
///
/// # Arguments
///
/// * `route` - The `AnalogRoute` to configure.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_analog_output_route(
&self,
route: AnalogRoute,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting analog output route to {:?} on channel {}",
route,
channel
);
self.check_status(
unsafe { sys::TLPMX_setAnalogOutputRoute(self.session, route as u16, channel) },
"set_analog_output_route",
)
}
/// Read the currently configured analog output route.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A string representation of the active analog route.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_analog_output_route(&self, channel: u16) -> Result<String, TlpmError> {
tracing::debug!("getting analog output route on channel {}", channel);
let mut route_name = [0i8; sys::TLPM_BUFFER_SIZE as usize];
self.check_status(
unsafe {
sys::TLPMX_getAnalogOutputRoute(self.session, route_name.as_mut_ptr(), channel)
},
"get_analog_output_route",
)?;
let c_str = unsafe { CStr::from_ptr(route_name.as_ptr()) };
Ok(c_str.to_string_lossy().into_owned())
}
/// Set the digital I/O pin mode.
///
/// # Arguments
///
/// * `pin_number` - The pin number to configure.
/// * `mode` - The `DigIoPinMode` to apply.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_dig_io_pin_mode(
&self,
pin_number: i16,
mode: DigIoPinMode,
) -> Result<(), TlpmError> {
tracing::debug!("setting digital io pin {} to mode {:?}", pin_number, mode);
self.check_status(
unsafe { sys::TLPMX_setDigIoPinMode(self.session, pin_number, mode as u16) },
"set_dig_io_pin_mode",
)
}
/// Read the currently configured digital I/O pin mode.
///
/// # Arguments
///
/// * `pin_number` - The pin number to query.
///
/// # Returns
///
/// The currently configured `DigIoPinMode`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code,
/// or `TlpmError::InvalidEnumValue` if an unrecognized mode code is returned.
pub fn get_dig_io_pin_mode(&self, pin_number: i16) -> Result<DigIoPinMode, TlpmError> {
tracing::debug!("getting digital io mode for pin {}", pin_number);
let mut mode_code: u16 = 0;
self.check_status(
unsafe { sys::TLPMX_getDigIoPinMode(self.session, pin_number, &mut mode_code) },
"get_dig_io_pin_mode",
)?;
DigIoPinMode::try_from(mode_code)
}
impl_property!(
bool,
global,
set_shutter_position,
get_shutter_position,
TLPMX_setShutterPosition,
TLPMX_getShutterPosition,
"shutter position"
);
/// Set the laser state, including frequency and duration.
///
/// # Arguments
///
/// * `state` - `true` to enable the laser, `false` to disable.
/// * `frequency` - The laser frequency in Hz.
/// * `duration` - The duration to output.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_laser_state(
&self,
state: bool,
frequency: u32,
duration: u32,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting laser state to {} (freq: {}, dur: {})",
state,
frequency,
duration
);
let c_state = if state { VI_TRUE } else { VI_FALSE };
self.check_status(
unsafe { sys::TLPMX_setLaserState(self.session, c_state, frequency, duration) },
"set_laser_state",
)
}
/// Retrieve the current boolean state of the laser.
///
/// # Returns
///
/// `true` if the laser is active, `false` otherwise.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_laser_state(&self) -> Result<bool, TlpmError> {
tracing::debug!("getting laser state");
let mut state: sys::ViBoolean = 0;
self.check_status(
unsafe { sys::TLPMX_getLaserState(self.session, &mut state) },
"get_laser_state",
)?;
Ok(state == VI_TRUE)
}
impl_property!(
numeric,
attr_channel,
set_analog_output_slope,
get_analog_output_slope,
TLPMX_setAnalogOutputSlope,
TLPMX_getAnalogOutputSlope,
f64,
"analog output slope"
);
impl_property!(
numeric,
attr_channel,
set_position_analog_output_slope,
get_position_analog_output_slope,
TLPMX_setPositionAnalogOutputSlope,
TLPMX_getPositionAnalogOutputSlope,
f64,
"position analog output slope"
);
/// Set the analog logarithmic output configuration.
///
/// # Arguments
///
/// * `log_slope` - The slope of the logarithmic output.
/// * `log_offset` - The offset of the logarithmic output.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_analog_log_conf(
&self,
log_slope: f64,
log_offset: f64,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting analog log config (slope: {}, offset: {}) on channel {}",
log_slope,
log_offset,
channel
);
self.check_status(
unsafe { sys::TLPMX_setAnalogLogConf(self.session, log_slope, log_offset, channel) },
"set_analog_log_conf",
)
}
/// Read the currently configured analog logarithmic output settings.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(log_slope, log_offset)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_analog_log_conf(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting analog log config on channel {}", channel);
let mut log_slope: f64 = 0.0;
let mut log_offset: f64 = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getAnalogLogConf(self.session, &mut log_slope, &mut log_offset, channel)
},
"get_analog_log_conf",
)?;
Ok((log_slope, log_offset))
}
/// Set the Pass/Fail power window limits.
///
/// # Arguments
///
/// * `min` - The minimum power limit.
/// * `max` - The maximum power limit.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_pass_fail_power_window(
&self,
min: f64,
max: f64,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!("setting pass/fail power window on channel {}", channel);
self.check_status(
unsafe { sys::TLPMX_setPassFailPowerWindow(self.session, min, max, channel) },
"set_pass_fail_power_window",
)
}
/// Retrieve the Pass/Fail power window limits.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_power, max_power)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_pass_fail_power_window(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting pass/fail power window on channel {}", channel);
let mut min: f64 = 0.0;
let mut max: f64 = 0.0;
self.check_status(
unsafe { sys::TLPMX_getPassFailPowerWindow(self.session, &mut min, &mut max, channel) },
"get_pass_fail_power_window",
)?;
Ok((min, max))
}
/// Set the Pass/Fail energy window limits.
///
/// # Arguments
///
/// * `min` - The minimum energy limit.
/// * `max` - The maximum energy limit.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_pass_fail_energy_window(
&self,
min: f64,
max: f64,
channel: u16,
) -> Result<(), TlpmError> {
tracing::debug!("setting pass/fail energy window on channel {}", channel);
self.check_status(
unsafe { sys::TLPMX_setPassFailEnergyWindow(self.session, min, max, channel) },
"set_pass_fail_energy_window",
)
}
/// Retrieve the Pass/Fail energy window limits.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_energy, max_energy)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_pass_fail_energy_window(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting pass/fail energy window on channel {}", channel);
let mut min: f64 = 0.0;
let mut max: f64 = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getPassFailEnergyWindow(self.session, &mut min, &mut max, channel)
},
"get_pass_fail_energy_window",
)?;
Ok((min, max))
}
/// Read the overall Pass/Fail state.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// `true` if the state is Pass, `false` if Fail.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_pass_fail_state(&self, channel: u16) -> Result<bool, TlpmError> {
tracing::debug!("getting pass/fail state on channel {}", channel);
let mut state: sys::ViUInt16 = 0;
self.check_status(
unsafe { sys::TLPMX_getPassFailState(self.session, &mut state, channel) },
"get_pass_fail_state",
)?;
Ok(state != 0)
}
impl_property!(
numeric,
channel,
set_analog_output_config,
get_analog_output_config,
TLPMX_setAnalogOutputConfig,
TLPMX_getAnalogOutputConfig,
i16,
"analog output config"
);
// impl_property!(
// numeric,
// channel,
// set_analog_output_gain_range,
// get_analog_output_gain_range,
// TLPMX_setAnalogOutputGainRange,
// TLPMX_getAnalogOutputGainRange,
// i16,
// "analog output gain range"
// );
/// Set the direction (Input/Output) for all 4 Digital IO pins simultaneously.
///
/// # Arguments
///
/// * `io0` - `true` for Output, `false` for Input.
/// * `io1` - `true` for Output, `false` for Input.
/// * `io2` - `true` for Output, `false` for Input.
/// * `io3` - `true` for Output, `false` for Input.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_dig_io_direction(
&self,
io0: bool,
io1: bool,
io2: bool,
io3: bool,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting digital io direction: 0={}, 1={}, 2={}, 3={}",
io0,
io1,
io2,
io3
);
let c0 = if io0 { VI_TRUE } else { VI_FALSE };
let c1 = if io1 { VI_TRUE } else { VI_FALSE };
let c2 = if io2 { VI_TRUE } else { VI_FALSE };
let c3 = if io3 { VI_TRUE } else { VI_FALSE };
self.check_status(
unsafe { sys::TLPMX_setDigIoDirection(self.session, c0, c1, c2, c3) },
"set_dig_io_direction",
)
}
/// Get the direction (Input/Output) for all 4 Digital IO pins.
///
/// # Returns
///
/// A tuple: `(io0, io1, io2, io3)` where `true` = Output, `false` = Input.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_dig_io_direction(&self) -> Result<(bool, bool, bool, bool), TlpmError> {
tracing::debug!("getting digital io direction");
let mut io0: sys::ViBoolean = 0;
let mut io1: sys::ViBoolean = 0;
let mut io2: sys::ViBoolean = 0;
let mut io3: sys::ViBoolean = 0;
self.check_status(
unsafe {
sys::TLPMX_getDigIoDirection(self.session, &mut io0, &mut io1, &mut io2, &mut io3)
},
"get_dig_io_direction",
)?;
Ok((
io0 == VI_TRUE,
io1 == VI_TRUE,
io2 == VI_TRUE,
io3 == VI_TRUE,
))
}
/// Set the output logic state for all 4 Digital IO pins simultaneously.
///
/// # Arguments
///
/// * `io0` - `true` for High, `false` for Low.
/// * `io1` - `true` for High, `false` for Low.
/// * `io2` - `true` for High, `false` for Low.
/// * `io3` - `true` for High, `false` for Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_dig_io_output(
&self,
io0: bool,
io1: bool,
io2: bool,
io3: bool,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting digital io output: 0={}, 1={}, 2={}, 3={}",
io0,
io1,
io2,
io3
);
let c0 = if io0 { VI_TRUE } else { VI_FALSE };
let c1 = if io1 { VI_TRUE } else { VI_FALSE };
let c2 = if io2 { VI_TRUE } else { VI_FALSE };
let c3 = if io3 { VI_TRUE } else { VI_FALSE };
self.check_status(
unsafe { sys::TLPMX_setDigIoOutput(self.session, c0, c1, c2, c3) },
"set_dig_io_output",
)
}
/// Get the actual physical logic state of all 4 Digital IO port pins.
///
/// # Returns
///
/// A tuple: `(io0, io1, io2, io3)` where `true` = High, `false` = Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_dig_io_port(&self) -> Result<(bool, bool, bool, bool), TlpmError> {
tracing::debug!("getting digital io port states");
let mut io0: sys::ViBoolean = 0;
let mut io1: sys::ViBoolean = 0;
let mut io2: sys::ViBoolean = 0;
let mut io3: sys::ViBoolean = 0;
self.check_status(
unsafe {
sys::TLPMX_getDigIoPort(self.session, &mut io0, &mut io1, &mut io2, &mut io3)
},
"get_dig_io_port",
)?;
Ok((
io0 == VI_TRUE,
io1 == VI_TRUE,
io2 == VI_TRUE,
io3 == VI_TRUE,
))
}
/// Set the output logic state for all 4 Digital IO pins (Alternative function).
///
/// # Arguments
///
/// * `io0` - `true` for High, `false` for Low.
/// * `io1` - `true` for High, `false` for Low.
/// * `io2` - `true` for High, `false` for Low.
/// * `io3` - `true` for High, `false` for Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn set_dig_io_pin_output(
&self,
io0: bool,
io1: bool,
io2: bool,
io3: bool,
) -> Result<(), TlpmError> {
tracing::debug!(
"setting digital io pin output: 0={}, 1={}, 2={}, 3={}",
io0,
io1,
io2,
io3
);
let c0 = if io0 { VI_TRUE } else { VI_FALSE };
let c1 = if io1 { VI_TRUE } else { VI_FALSE };
let c2 = if io2 { VI_TRUE } else { VI_FALSE };
let c3 = if io3 { VI_TRUE } else { VI_FALSE };
self.check_status(
unsafe { sys::TLPMX_setDigIoPinOutput(self.session, c0, c1, c2, c3) },
"set_dig_io_pin_output",
)
}
/// Get the configured output logic state of all 4 Digital IO pins.
///
/// # Returns
///
/// A tuple: `(io0, io1, io2, io3)` where `true` = High, `false` = Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_dig_io_pin_output(&self) -> Result<(bool, bool, bool, bool), TlpmError> {
tracing::debug!("getting digital io pin outputs");
let mut io0: sys::ViBoolean = 0;
let mut io1: sys::ViBoolean = 0;
let mut io2: sys::ViBoolean = 0;
let mut io3: sys::ViBoolean = 0;
self.check_status(
unsafe {
sys::TLPMX_getDigIoPinOutput(self.session, &mut io0, &mut io1, &mut io2, &mut io3)
},
"get_dig_io_pin_output",
)?;
Ok((
io0 == VI_TRUE,
io1 == VI_TRUE,
io2 == VI_TRUE,
io3 == VI_TRUE,
))
}
/// Get the logic state of all 4 Digital IO input pins.
///
/// # Returns
///
/// A tuple: `(io0, io1, io2, io3)` where `true` = High, `false` = Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_dig_io_pin_input(&self) -> Result<(bool, bool, bool, bool), TlpmError> {
tracing::debug!("getting digital io pin inputs");
let mut io0: sys::ViBoolean = 0;
let mut io1: sys::ViBoolean = 0;
let mut io2: sys::ViBoolean = 0;
let mut io3: sys::ViBoolean = 0;
self.check_status(
unsafe {
sys::TLPMX_getDigIoPinInput(self.session, &mut io0, &mut io1, &mut io2, &mut io3)
},
"get_dig_io_pin_input",
)?;
Ok((
io0 == VI_TRUE,
io1 == VI_TRUE,
io2 == VI_TRUE,
io3 == VI_TRUE,
))
}
/// Read the analog output slope range.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_slope, max_slope)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_analog_output_slope_range(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting analog output slope range on channel {}", channel);
let mut min_slope = 0.0;
let mut max_slope = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getAnalogOutputSlopeRange(
self.session,
&mut min_slope,
&mut max_slope,
channel,
)
},
"get_analog_output_slope_range",
)?;
Ok((min_slope, max_slope))
}
/// Read the analog output voltage.
///
/// # Arguments
///
/// * `attribute` - The `TlpmAttribute` to query (e.g., Set, Min, Max).
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// The analog output voltage.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_analog_output_voltage(
&self,
attribute: TlpmAttribute,
channel: u16,
) -> Result<f64, TlpmError> {
tracing::debug!("getting analog output voltage on channel {}", channel);
let mut voltage = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getAnalogOutputVoltage(
self.session,
attribute as i16,
&mut voltage,
channel,
)
},
"get_analog_output_voltage",
)?;
Ok(voltage)
}
/// Read the analog output voltage range.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_voltage, max_voltage)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_analog_output_voltage_range(&self, channel: u16) -> Result<(f64, f64), TlpmError> {
tracing::debug!("getting analog output voltage range on channel {}", channel);
let mut min_volt = 0.0;
let mut max_volt = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getAnalogOutputVoltageRange(
self.session,
&mut min_volt,
&mut max_volt,
channel,
)
},
"get_analog_output_voltage_range",
)?;
Ok((min_volt, max_volt))
}
/// Read the position analog output slope range.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_slope, max_slope)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_position_analog_output_slope_range(
&self,
channel: u16,
) -> Result<(f64, f64), TlpmError> {
tracing::debug!(
"getting position analog output slope range on channel {}",
channel
);
let mut min_slope = 0.0;
let mut max_slope = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getPositionAnalogOutputSlopeRange(
self.session,
&mut min_slope,
&mut max_slope,
channel,
)
},
"get_position_analog_output_slope_range",
)?;
Ok((min_slope, max_slope))
}
/// Read the position analog output voltage for X and Y axes.
///
/// # Arguments
///
/// * `attribute` - The `TlpmAttribute` to query.
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(voltage_x, voltage_y)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_position_analog_output_voltage(
&self,
attribute: TlpmAttribute,
channel: u16,
) -> Result<(f64, f64), TlpmError> {
tracing::debug!(
"getting position analog output voltage on channel {}",
channel
);
let mut voltage_x = 0.0;
let mut voltage_y = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getPositionAnalogOutputVoltage(
self.session,
attribute as i16,
&mut voltage_x,
&mut voltage_y,
channel,
)
},
"get_position_analog_output_voltage",
)?;
Ok((voltage_x, voltage_y))
}
/// Read the position analog output voltage range.
///
/// # Arguments
///
/// * `channel` - The sensor channel (typically `1`).
///
/// # Returns
///
/// A tuple containing `(min_voltage, max_voltage)`.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_position_analog_output_voltage_range(
&self,
channel: u16,
) -> Result<(f64, f64), TlpmError> {
tracing::debug!(
"getting position analog output voltage range on channel {}",
channel
);
let mut min_volt = 0.0;
let mut max_volt = 0.0;
self.check_status(
unsafe {
sys::TLPMX_getPositionAnalogOutputVoltageRange(
self.session,
&mut min_volt,
&mut max_volt,
channel,
)
},
"get_position_analog_output_voltage_range",
)?;
Ok((min_volt, max_volt))
}
/// Get the output logic state of all 4 Digital IO pins.
///
/// # Returns
///
/// A tuple: `(io0, io1, io2, io3)` where `true` = High, `false` = Low.
///
/// # Errors
///
/// Returns a `TlpmError::VisaError` if the device responds with an error code.
pub fn get_dig_io_output(&self) -> Result<(bool, bool, bool, bool), TlpmError> {
tracing::debug!("getting digital io outputs");
let mut io0: sys::ViBoolean = 0;
let mut io1: sys::ViBoolean = 0;
let mut io2: sys::ViBoolean = 0;
let mut io3: sys::ViBoolean = 0;
self.check_status(
unsafe {
sys::TLPMX_getDigIoOutput(self.session, &mut io0, &mut io1, &mut io2, &mut io3)
},
"get_dig_io_output",
)?;
Ok((
io0 == VI_TRUE,
io1 == VI_TRUE,
io2 == VI_TRUE,
io3 == VI_TRUE,
))
}
}