test_wrapper_flipro.py
3.87 KB
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
#!/usr/bin/python3
# ====================================================
# First, compile: python setup.py build_ext --inplace
# Second, exucute: python test_wrapper_flipro.py
# ====================================================
# ====================================================
# ====================================================
# === Import the extension and manage errors
# ====================================================
# ====================================================
try:
import wrapper_flipro
except Exception as e:
print(f"Error import wrapper_flipropro: {e}")
print("\nI try to help you to find the solution:")
import os, glob
import subprocess
cwd = os.getcwd()
fics = glob.glob("wrapper_flipro*.so")
for fic in fics:
cmd = f"ldd {fic}"
print(f"\nExecute: {cmd}")
argus = []
argus.append("ldd")
argus.append(fic)
res = subprocess.run(argus, capture_output=True)
outb = res.stdout
outs = outb.decode().split("\n")
comment = ""
for out in outs:
print(out)
words = out.split()
if len(words) > 2:
lib = words[0]
path = words[2]
if path == "not":
comment = f"The path of the library {lib} is not found. Try:"
if comment != "":
print(f"{comment}")
cmd = f"export LD_LIBRARY_PATH={cwd}:$LD_LIBRARY_PATH"
print(f"$ {cmd}")
print("\nIf it a success you have to record the LD_LIBRARY_PATH permanently:")
print("$ sudo vi /etc/ld.so.conf")
print("$ sudo ldconfig")
print("")
exit()
# ====================================================
# ====================================================
# === List of tests to execute
# ====================================================
# ====================================================
tests = []
#tests.append("matrix")
tests.append("date")
tests.append("one_shot")
# ====================================================
# ====================================================
# === Code of tests
# ====================================================
# ====================================================
import time
for test in tests:
print("="*40+"\n"+"="*10+f" Test: {test} \n"+"="*40)
if test == "matrix":
res = wrapper_flipro.matrix(4096,4096,8.99)
print(f"{res=}")
res = wrapper_flipro.matrix(10,5,4.56)
print(f"{res=}")
if test == "date":
res = wrapper_flipro.date()
print(f"{res=}")
if test == "one_shot":
try:
print("== init")
wrapper_flipro.init()
print("== flicapabilities")
res = wrapper_flipro.flicapabilities()
for key, val in res.items():
print(f"{key} = {val}")
print("== deviceinfo")
res = wrapper_flipro.deviceinfo()
for key, val in res.items():
print(f"{key} = {val}")
print("== start_exp")
wrapper_flipro.exptime(15)
wrapper_flipro.bin((1,1))
wrapper_flipro.start_exp()
import time
timer = wrapper_flipro.timer()
print(f"{timer=}")
while timer >= 0:
time.sleep(1)
timer = wrapper_flipro.timer()
print(f"{timer=:.2f}")
print("== read_ccd")
matrix, header = wrapper_flipro.read_ccd()
print(f"{matrix=}")
for re in header:
print(f"{re=}")
print("== close")
wrapper_flipro.close()
except BaseException as e:
print("Error:", str(e))
time.sleep(1)
print("== END")