From 61bb67d78784c817d87a3e221b8048d5285218ce Mon Sep 17 00:00:00 2001 From: sfop Date: Thu, 11 Aug 2016 17:17:47 +0200 Subject: [PATCH] Closedown --- script/camtool.py | 60 ++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/script/camtool.py b/script/camtool.py index beaf7c6..5285256 100644 --- a/script/camtool.py +++ b/script/camtool.py @@ -28,31 +28,25 @@ class CamToolImage(ReadableMatrix): class CamTool(DeviceBase): def __init__(self, name, prefix = "cam:", latch = False, camera = "~/Simulation.json"): DeviceBase.__init__(self, name) - run_channel = prefix + "camera.run" + run_channel = prefix + "camera.run" try: caget(run_channel) except: - cmd = "camtool --casprefix " + prefix + " " + camera #--nogui --run -1 + cmd = "camtool --casprefix " + prefix + " --run -1 " + camera #--nogui fork( (exec_cmd,(cmd,)),) - start = time.time() - while(True): - try: - caget(run_channel) - time.sleep(5.0) - break - except: - if time.time() - start > 20.0: - raise Exception("Camtool application not started") - time.sleep(0.5) - + self.waitForChannel(run_channel, 20) + time.sleep(5.0) + print "Started", self.prefix = prefix self.latch = latch self.mode = "latch" if latch else "pipeline" self.data_prefix = prefix + self.mode + "." self.cam_run = Channel(prefix + "camera.run", alias = name + " run") - self.cam_latch = Channel(prefix + "latch.capture", alias = name + " latch") - self.timestamp = Channel(self.data_prefix + "timestamp", alias = name + " timestamp") #[D1, D2, ...] - + self.cam_latch = Channel(prefix + "latch.capture", 'l', alias = name + " latch") + if self.mode == "latch": + self.cam_latch.write(1) + self.waitForChannel(self.data_prefix + "timestamp",20) + self.timestamp = Channel(self.data_prefix + "timestamp", alias = name + " timestamp") #[D1, D2, ...] self.com_x = Channel(self.data_prefix + "x_stats.com", alias = name + " com x") self.com_y = Channel(self.data_prefix + "y_stats.com", alias = name + " com y") self.profile_x = Channel(self.data_prefix + "profile.x", alias = name + " profile x") @@ -60,7 +54,6 @@ class CamTool(DeviceBase): self.data = Channel(self.data_prefix + "image", alias = name + " data") self.shape = Channel(self.data_prefix + "image.shape", alias = name + " shape") #[D1, D2, ...] self.bg_image = Channel(self.data_prefix + "bg_image", alias = name + "bg image") #[D1, D2, ...] - self.bg_en = Channel(self.prefix + "bg.enabled", type = 'l', alias = name + " bg enabled") self.bg_capture = Channel(self.prefix + "bg.capture", type = 'l', alias = name + " bg capture") self.bg_capture_remain = Channel(self.prefix + "bg.capture_remain", alias = name + " capture remain") @@ -68,7 +61,6 @@ class CamTool(DeviceBase): self.grab_timeout = 1.0 self.image = CamToolImage(self) set_device_alias(self.image, name + " image") - self.com_x_samples, self.com_y_samples = [], [] class CamToolComX(Readable): def read(self): @@ -86,15 +78,27 @@ class CamTool(DeviceBase): def read(self): return stdev(self.camtool.com_y_samples) self.com_y_stdev = CamToolComXVar(); self.com_y_stdev.camtool = self - set_device_alias(self.com_x_mean, name + " com x mean") set_device_alias(self.com_y_mean, name + " com y mean") set_device_alias(self.com_x_stdev, name + " com x stdev") set_device_alias(self.com_y_stdev, name + " com y stdev") + def waitForChannel(self, channel, timeout): + print "Waiting for chanel: " + channel + start = time.time() + while(True): + try: + caget(channel) + break + except: + if time.time() - start > timeout: + raise Exception("Timeout waiting for channel: " + channel) + time.sleep(0.5) + + def doInitialize(self): if self.latch: - self.start() + self.start() else: self.stop() @@ -162,20 +166,18 @@ class CamTool(DeviceBase): self.bg_en.close() self.bg_capture.close() self.bg_capture_remain.close() - self.image.close() - - + self.image.close() if __name__ == "__builtin__": - camera_tool = CamTool("camtool") - #print camera_tool.com_x_mean.read() + camera_tool = CamTool("camtool", latch = True) + add_device(camera_tool, True) camera_tool.enableBackground(False) + """ camera_tool.enableBackground(False) camera_tool.captureBackground(5) + """ for i in range (100): camera_tool.capture() - print camera_tool.take() - print camera_tool.com_x.read(), camera_tool.com_y.read() - - add_device(camera_tool, True) \ No newline at end of file + print camera_tool.take(), camera_tool.com_x.read(), camera_tool.com_y.read() + \ No newline at end of file