Commit c44831cf9b9bfbb0596fea32d53cabab4eee0fae

Authored by Alain Klotz
1 parent 1464cf57
Exists in master

correction char *

src/guitastro_device_flipro/component_sensor_detector_flipro.py
... ... @@ -4,11 +4,12 @@ import sys
4 4 from threading import Thread, Event
5 5 import traceback
6 6 import time
7   -import shlex
  7 +#import shlex
8 8  
9 9 try:
10 10 # guitastro is installed with setup.py
11   - from guitastro import ComponentSensorDetector, ComponentException
  11 + #from guitastro import ComponentSensorDetector, ComponentException
  12 + from guitastro import ComponentSensorDetector
12 13 except:
13 14 # guitastro is installed with only requirements.in
14 15 # guitastro_camera_* folders must be copied at the same root folder than guitastro
... ... @@ -18,7 +19,7 @@ except:
18 19 path = os.path.abspath(os.path.join(pwd, short_path))
19 20 if path not in sys.path:
20 21 sys.path.insert(0, path)
21   - from guitastro.component import ComponentException
  22 + #from guitastro.component import ComponentException
22 23 from guitastro.component_sensor_detector import ComponentSensorDetector
23 24  
24 25 # #####################################################################
... ... @@ -128,16 +129,11 @@ class ComponentSensorDetectorFlipro(ComponentSensorDetector):
128 129 if self._thread_doacq != None:
129 130 self._thread_doacq.stop()
130 131 self._thread_doacq = None
  132 + # - do not forget to stop the database. Else the program remains blocked
  133 + self.database.stop()
131 134  
132 135 # ------------ prop
133 136  
134   - def _my_prop(self, prop:dict)-> dict:
135   - """Component property concrete method
136   - """
137   - # TODO UPDATE for Status
138   - prop['DO']['HOMING'] = "Search the homing to initialize coders"
139   - return prop
140   -
141 137 # ------------ do
142 138  
143 139 def _my_do_acq(self, *args, **kwargs):
... ... @@ -248,18 +244,11 @@ if __name__ == "__main__":
248 244 Basic example. Only simulation
249 245 """
250 246 comp = ComponentSensorDetectorFlipro("Z", name="test")
251   - inc_per_motor_rev = 1000000
252   - mm_per_motor_rev = 34.38
253   - lim_inf = 0
254   - lim_sup = 1000000
255 247 comp.init("Z", name="Camera", manufacturer="FLI")
256 248 param = {}
257   - param["speed_slew"] = 1000000/68 # inc/s
258   - param["speed_drift"] = 0 # inc/s
  249 + param["exptime"] = 1.0 # inc/s
  250 + param["binning"] = (1,1)
259 251 comp.database.query(param)
260 252  
261 253 comp.verbose = 1
262   - res = comp.command("DO", "STOP")
263   - res = comp.command("DO", "COORD")
264   - comp.command("SET", "target", 300000) # unit
265   - res = comp.command("DO", "GOTO")
  254 + res = comp.command("DO", "ACQ")
... ...
src/guitastro_device_flipro/device_flipro.py
... ... @@ -9,6 +9,11 @@ except:
9 9 from component_sensor_detector_flipro import ComponentSensorDetectorFlipro
10 10  
11 11 try:
  12 + from .component_detector_shutter_flipro import ComponentDetectorShutterFlipro
  13 +except:
  14 + from component_detector_shutter_flipro import ComponentDetectorShutterFlipro
  15 +
  16 +try:
12 17 import wrapper_flipro
13 18 except:
14 19 pass
... ... @@ -75,7 +80,7 @@ class Device_Flipro(Device):
75 80 # =====================================================================
76 81  
77 82 def _my_init_params(self, params_optional: dict, unit_types: dict):
78   - params_optional["MANUFACTURER"] = (str, "FLI")
  83 + params_optional["MANUFACTURER"] = (str, "Finger Lakes Instruments")
79 84 # --- Dico of unit_types and their parameters
80 85 unit_types = {}
81 86 # --- unit choice
... ... @@ -92,32 +97,49 @@ class Device_Flipro(Device):
92 97 # This is a composition of Component classes
93 98 self._comp = {}
94 99 # --- init component detector camera
95   - self._comp["camera"] = ComponentSensorDetectorFlipro("CMOS", name=name, model="Flipro Kepler 4040", manufacturer="Finger Lakes Instruments", description="Imager", wrapper_flipro=wrapper_flipro)
96   - time.sleep(0.1) # time to let the loop of param init
  100 + self._comp["camera"] = ComponentSensorDetectorFlipro("CMOS", name=name+" imager", model="Flipro Kepler 4040", manufacturer="Finger Lakes Instruments", description="Imager", wrapper_flipro=wrapper_flipro)
97 101 param = {}
98 102 self._comp["camera"].database.query(param)
  103 + # --- init component detector camera
  104 + self._comp["shutter"] = ComponentDetectorShutterFlipro("IRIS", name=name+" shutter", model="Flipro Kepler 4040", manufacturer="Finger Lakes Instruments", description="Integrated shutter", wrapper_flipro=wrapper_flipro)
  105 + # ---
  106 + time.sleep(0.1) # time to let the loop of param init
99 107  
100 108 def _my_open(self):
101 109 transport = self._unit_params["TRANSPORT"].upper()
102   - wrapper_flipro.init()
  110 + # - open communication
  111 + if self._real:
  112 + wrapper_flipro.init()
103 113 # - set the channel to all components
104 114 for component_name in self.component_names:
105 115 self._comp[component_name].channel = transport
106 116 self._comp[component_name].real = self._real
107   - param = {}
108   - res = wrapper_flipro.flicapabilities()
109   - for key, val in res.items():
110   - param[key] = val
111   - #print(f"{key} = {val}")
112   - res = wrapper_flipro.deviceinfo()
113   - for key, val in res.items():
114   - param[key] = val
115   - #print(f"{key} = {val}")
116   - self._comp["camera"].database.query(param)
  117 + # - fill params from the real device
  118 + if self._real:
  119 + param = {}
  120 + res = wrapper_flipro.flicapabilities()
  121 + for key, val in res.items():
  122 + param[key] = val
  123 + #print(f"{key} = {val}")
  124 + res = wrapper_flipro.deviceinfo()
  125 + for key, val in res.items():
  126 + param[key] = val
  127 + #print(f"{key} = {val}")
  128 + self._comp["camera"].database.query(param)
117 129  
118 130  
119 131 def _my_close(self):
120   - wrapper_flipro.close()
  132 + #print("Device_Flipro _my_close")
  133 + if self._real:
  134 + wrapper_flipro.close()
  135 +
  136 + def __del__(self):
  137 + #print("Device_Flipro __del__ shutter")
  138 + self._comp["shutter"].__del__()
  139 + #print("Device_Flipro __del__ camera")
  140 + self._comp["camera"].__del__()
  141 + if self._real:
  142 + wrapper_flipro.close()
121 143  
122 144  
123 145 # #####################################################################
... ... @@ -129,8 +151,8 @@ class Device_Flipro(Device):
129 151 # #####################################################################
130 152  
131 153 if __name__ == "__main__":
132   - default = 0
133   - example = input(f"Select the example (0 to 0) ({default}) ")
  154 + default = 1
  155 + example = input(f"Select the example (0 to 1) ({default}) ")
134 156 try:
135 157 example = int(example)
136 158 except:
... ... @@ -145,7 +167,11 @@ if __name__ == "__main__":
145 167 """
146 168 Example of ACQ
147 169 """
148   - dev = Device_Flipro("FLIPRO", transport="USB", name="Flipro", description="Test", model='Flipro', manufacturer="Finger Lakes Instruments")
  170 + name = "TNC4"
  171 + model = "Kepler 4040"
  172 + serial_number = "KL3044521"
  173 + description = "Test"
  174 + dev = Device_Flipro("FLIPRO", transport="USB", name=name, description=description, model=model, serial_number=serial_number)
149 175 # ------------------------
150 176 print("*"*20,"\nDevice parameters:")
151 177 for key, val in dev.param.items():
... ... @@ -157,12 +183,17 @@ if __name__ == "__main__":
157 183 # ------------------------
158 184 dev.open(True)
159 185 # ------------------------
160   - comp = dev.components['camera'][1]
161   - db = comp.database.query()
  186 + cam = dev.components['camera'][1]
  187 + shutter = dev.components['shutter'][1]
162 188 # ------------------------
163   - for k in range(9):
  189 + for k in range(2):
164 190 try:
165 191 # ------------------------
  192 + cmd = "shutter DO OPEN"
  193 + print("*"*20,f"\ncmd => \"{cmd}\"")
  194 + dev.commandstring(cmd)
  195 + time.sleep(3)
  196 + # ------------------------
166 197 exptime = 0.1
167 198 cmd = f"camera SET exptime {exptime}"
168 199 print("*"*20,f"\ncmd => \"{cmd}\"")
... ... @@ -179,11 +210,50 @@ if __name__ == "__main__":
179 210 timer = dev.commandstring(cmd)
180 211 if timer == -1:
181 212 break
  213 + print(f" {k+1} GPS {cam.ima.getkwd('DATE-OBS')}")
  214 + print(f" {k+1} NTP {cam.ima.getkwd('DATE-PC')}")
  215 + time.sleep(3)
182 216 except:
183 217 traceback.print_exc(file=sys.stdout)
184   - print(f" {k+1} GPS {comp.ima.getkwd('DATE-OBS')}")
185   - print(f" {k+1} NTP {comp.ima.getkwd('DATE-PC')}")
186   - time.sleep(3)
187 218 # ------------------------
188 219 print("*"*20,"\nClose")
189 220 dev.close()
  221 +
  222 + if example == 1:
  223 + """
  224 + Example of shutter
  225 + """
  226 + name = "TNC4"
  227 + model = "Kepler 4040"
  228 + serial_number = "KL3044521"
  229 + description = "Test"
  230 + dev = Device_Flipro("FLIPRO", transport="USB", name=name, description=description, model=model, serial_number=serial_number)
  231 + # ------------------------
  232 + print("*"*20,"\nDevice parameters:")
  233 + for key, val in dev.param.items():
  234 + print(f" * {key} = {val}")
  235 + # ------------------------
  236 + print("*"*20,"\nComponents are:")
  237 + for key, val in dev.components.items():
  238 + print(f" * {key} of type {val[0]}")
  239 + # ------------------------
  240 + dev.open(True)
  241 + # ------------------------
  242 + try:
  243 + # ------------------------
  244 + cam = dev.components['camera'][1]
  245 + shutter = dev.components['shutter'][1]
  246 + # ------------------------
  247 + cmd = "shutter DO OPEN"
  248 + print("*"*20,f"\ncmd => \"{cmd}\"")
  249 + dev.commandstring(cmd)
  250 + time.sleep(5)
  251 + # ------------------------
  252 + cmd = "shutter DO SYNCHRO"
  253 + print("*"*20,f"\ncmd => \"{cmd}\"")
  254 + dev.commandstring(cmd)
  255 + except:
  256 + traceback.print_exc(file=sys.stdout)
  257 + # ------------------------
  258 + print("*"*20,"\nClose device")
  259 + del dev
... ...
src/wrapper_flipro/wrapper_flipro.cpp
... ... @@ -397,8 +397,8 @@ static PyObject* read_ccd(PyObject* self, PyObject* args) {
397 397  
398 398 static PyObject* shutter(PyObject* self, PyObject* args) {
399 399 if (PyTuple_GET_SIZE(args) >= 1) {
400   - char state[1024];
401   - if ( ! PyArg_ParseTuple(args, "s", state) ) return NULL;
  400 + const char *state;
  401 + if ( ! PyArg_ParseTuple(args, "s", &state) ) return NULL;
402 402 if (strcmp(state, cam_shutters[0])==0) {
403 403 cam_shutter_off(&cam);
404 404 cam.shutterindex = 0;
... ... @@ -421,9 +421,9 @@ static PyObject* measure_temperature(PyObject* self, PyObject* args) {
421 421 }
422 422  
423 423 static PyObject* cooler(PyObject* self, PyObject* args) {
424   - char state[1024];
  424 + const char *state;
425 425 if (PyTuple_GET_SIZE(args) == 1) {
426   - if ( ! PyArg_ParseTuple(args, "s", state) ) return NULL;
  426 + if ( ! PyArg_ParseTuple(args, "s", &state) ) return NULL;
427 427 if (strcmp(state, cam_coolers[0])==0) {
428 428 cam_cooler_off(&cam);
429 429 }
... ... @@ -437,7 +437,7 @@ static PyObject* cooler(PyObject* self, PyObject* args) {
437 437 }
438 438 else if (PyTuple_GET_SIZE(args) == 2) {
439 439 double check_temperature;
440   - if ( ! PyArg_ParseTuple(args, "sd", state, &check_temperature) ) return NULL;
  440 + if ( ! PyArg_ParseTuple(args, "sd", &state, &check_temperature) ) return NULL;
441 441 if (strcmp(state, cam_coolers[2])==0) {
442 442 cam.check_temperature = check_temperature;
443 443 cam_cooler_check(&cam);
... ... @@ -694,9 +694,9 @@ static PyObject* FingerlakesProSetMode(PyObject* self, PyObject* args) {
694 694  
695 695 static PyObject* SelectImage(PyObject* self, PyObject* args) {
696 696 char ligne[DIM_S];
697   - char select[DIM_S];
  697 + const char *select;
698 698 if (PyTuple_GET_SIZE(args) >= 1) {
699   - if ( ! PyArg_ParseTuple(args, "s", select) ) return NULL;
  699 + if ( ! PyArg_ParseTuple(args, "s", &select) ) return NULL;
700 700 if (strcmp(select, "low") == 0) {
701 701 io_buffer_change_mode(&cam, 0);
702 702 }
... ... @@ -756,18 +756,19 @@ static PyObject* measure_temperatures(PyObject* self, PyObject* args) {
756 756 }
757 757  
758 758 static PyObject* DewPower(PyObject* self, PyObject* args) {
  759 + const char *select;
759 760 char ligne[DIM_S];
760 761 int32_t iResult;
761 762 if (PyTuple_GET_SIZE(args) >= 1) {
762   - if ( ! PyArg_ParseTuple(args, "i", ligne) ) return NULL;
763   - if (strcmp(ligne, "?") == 0) {
  763 + if ( ! PyArg_ParseTuple(args, "i", &select) ) return NULL;
  764 + if (strcmp(select, "?") == 0) {
764 765 iResult = dev_get_dewpower(&cam);
765 766 cam.antidew_power = iResult;
766 767 } else {
767   - if (strcmp(ligne, "off") == 0) cam.antidew_power = 0;
768   - if (strcmp(ligne, "low") == 0) cam.antidew_power = 33;
769   - if (strcmp(ligne, "high") == 0) cam.antidew_power = 66;
770   - if (strcmp(ligne, "full") == 0) cam.antidew_power = 100;
  768 + if (strcmp(select, "off") == 0) cam.antidew_power = 0;
  769 + if (strcmp(select, "low") == 0) cam.antidew_power = 33;
  770 + if (strcmp(select, "high") == 0) cam.antidew_power = 66;
  771 + if (strcmp(select, "full") == 0) cam.antidew_power = 100;
771 772 iResult = dev_set_dewpower(&cam);
772 773 }
773 774 snprintf(ligne, DIM_S, "FLIDewPower return %d", iResult);
... ... @@ -865,7 +866,7 @@ static PyObject* Merge(PyObject* self, PyObject* args) {
865 866 }
866 867  
867 868 */
868   - char algo[DIM_S];
  869 + const char *algo;
869 870 char path[DIM_S];
870 871 char method[DIM_S];
871 872 char ligne[DIM_S];
... ... @@ -889,7 +890,7 @@ static PyObject* Merge(PyObject* self, PyObject* args) {
889 890 return NULL;
890 891 }
891 892 if (PyTuple_GET_SIZE(args) >= 1) {
892   - if ( ! PyArg_ParseTuple(args, "s|OO", algo, obj1, obj2) ) return NULL;
  893 + if ( ! PyArg_ParseTuple(args, "s|OO", &algo, obj1, obj2) ) return NULL;
893 894 // algo
894 895 if (strcmp(algo, "fli") == 0) {
895 896 cam.merge_algo = MERGE_ALGO_FLI;
... ... @@ -1080,17 +1081,18 @@ static PyObject* Led(PyObject* self, PyObject* args) {
1080 1081  
1081 1082 static PyObject* LedDuration(PyObject* self, PyObject* args) {
1082 1083 // milliseconds
  1084 + const char *duration;
1083 1085 char ligne[DIM_S];
1084 1086 uint32_t led_duration;
1085 1087 //int32_t s_iDeviceHandle;
1086 1088 //s_iDeviceHandle = cam.s_iDeviceHandle;
1087 1089 if (PyTuple_GET_SIZE(args) >= 1) {
1088   - if ( ! PyArg_ParseTuple(args, "s", ligne) ) return NULL;
1089   - if (strcmp(ligne, "infinite") == 0) {
  1090 + if ( ! PyArg_ParseTuple(args, "s", &duration) ) return NULL;
  1091 + if (strcmp(duration, "infinite") == 0) {
1090 1092 led_duration = 0xFFFFFFFF;
1091 1093 }
1092 1094 else {
1093   - led_duration = atoi(ligne);
  1095 + led_duration = atoi(duration);
1094 1096 }
1095 1097 led_duration = (int32_t)dev_set_led_duration(&cam, led_duration);
1096 1098 }
... ...