1#![allow(non_upper_case_globals)]
12#![allow(non_camel_case_types)]
13#![allow(non_snake_case)]
14
15#[cfg(feature = "bindgen")]
16include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
17
18#[cfg(all(not(feature = "bindgen"), feature = "dynamic_load"))]
19include!("./prebind/bindings_dynamic.rs");
20
21#[cfg(all(not(feature = "bindgen"), not(feature = "dynamic_load")))]
22include!("./prebind/bindings.rs");
23
24#[cfg(feature = "dynamic_load")]
25mod dynamic_loading;
26
27#[cfg(feature = "dynamic_load")]
28pub use dynamic_loading::*;
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33 #[test]
34 fn open_default_RM() {
35 let mut session: ViSession = 0;
36 unsafe {
37 assert_eq!(viOpenDefaultRM(&mut session as ViPSession), VI_SUCCESS as _,);
38 }
39 }
40 #[test]
41 fn find_resource() {
42 let mut defaultRM: ViSession = 0;
43 let mut find_list: ViFindList = 0;
44 let mut ret_cnt: ViUInt32 = 0;
45 let mut instr_desc: [ViChar; VI_FIND_BUFLEN as usize] = [0; VI_FIND_BUFLEN as usize];
46 unsafe {
47 assert_eq!(
48 viOpenDefaultRM(&mut defaultRM as ViPSession),
49 VI_SUCCESS as _,
50 "Could not open a session to the VISA Resource Manager!\n"
51 );
52 let expr = std::ffi::CString::new(*b"?*INSTR").unwrap();
53 assert_eq!(
54 viFindRsrc(
55 defaultRM,
56 expr.as_ptr(),
57 &mut find_list,
58 &mut ret_cnt,
59 &mut instr_desc as _
60 ),
61 VI_SUCCESS as _,
62 "An error occurred while finding resources.\n"
63 );
64 eprintln!(
65 "{} instruments, serial ports, and other resources found:",
66 ret_cnt,
67 );
68 let mut instr: ViSession = 0;
69
70 loop {
71 eprintln!("{} targets to connect", ret_cnt);
72 let resource = instr_desc
73 .into_iter()
74 .map(|x| x as u8 as char)
75 .collect::<String>();
76 eprintln!("connecting to '{}'", resource);
77 let open_status = viOpen(
78 defaultRM,
79 &instr_desc as _,
80 VI_NULL as _,
81 VI_NULL as _,
82 &mut instr as _,
83 );
84 if open_status != VI_SUCCESS as _ {
85 eprintln!(
86 "An error '{}' occurred opening a session to '{}'\n",
87 open_status,
88 instr_desc
89 .into_iter()
90 .map(|x| x as u8 as char)
91 .collect::<String>()
92 );
93 } else {
94 eprintln!("connected to '{}'", resource);
95 viClose(instr);
96 }
97 ret_cnt -= 1;
98 if ret_cnt > 0 {
99 let find_status = viFindNext(find_list, &mut instr_desc as _);
100 if find_status != VI_SUCCESS as _ {
101 eprintln!(
102 "An error '{}' occurred finding the next resource\n.",
103 find_status
104 );
105 break;
106 }
107 } else {
108 break;
109 }
110 }
111 viClose(defaultRM);
112 }
113 }
114}