1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4#![allow(deref_nullptr)]
5include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6
7#[cfg(test)]
8mod tests {
9 use std::os::raw::c_char;
10 use std::ptr::null_mut;
11 use crate::*;
12 use serial_test::serial;
13 use std::mem::size_of;
14
15 macro_rules! assert_ok {
16 ($x:expr) => {
17 assert_eq!($x, XI_RET::XI_OK as XI_RETURN)
18 }
19 }
20
21 #[test]
22 #[serial]
23 fn open_close() {
24 unsafe {
25 let mut xiH: HANDLE = null_mut();
26 assert_ok!(xiOpenDevice(0, &mut xiH));
27 assert_ok!(xiCloseDevice(xiH));
28 }
29 }
30
31 #[test]
32 #[serial]
33 fn set_param() {
34 unsafe {
35 let mut xiH: HANDLE = null_mut();
36 assert_ok!(xiOpenDevice(0, &mut xiH));
37 assert_ok!(xiSetParamInt(xiH, XI_PRM_EXPOSURE.as_ptr() as *const c_char, 1000));
38 assert_ok!(xiCloseDevice(xiH));
39 }
40 }
41
42 #[test]
43 #[serial]
44 fn xi_sample() {
45 unsafe {
46 let mut image = XI_IMG::default();
47 image.size = size_of::<XI_IMG>() as DWORD;
48
49 let mut xiH: HANDLE = null_mut();
50
51 assert_ok!(xiOpenDevice(0, &mut xiH));
52
53 assert_ok!(xiSetParamInt(xiH, XI_PRM_EXPOSURE.as_ptr() as *const c_char, 10000));
54
55 assert_ok!(xiStartAcquisition(xiH));
56
57 for i in 0..100 {
58 assert_ok!(xiGetImage(xiH, 50000, &mut image));
59 let pixel = *(image.bp as *const u8);
60 println!("Image {} ({}x{}) received from camera. First pixel value: {}", i, image.width, image.height, pixel);
61 }
62
63 assert_ok!(xiStopAcquisition(xiH));
64
65 assert_ok!(xiCloseDevice(xiH));
66 }
67
68 }
69}