OSDN Git Service

speed up serialCamera
authoriwasaki <iwaaya@yasunaga-lab.bio.kyutech.ac.jp>
Sun, 17 Jan 2016 06:09:04 +0000 (15:09 +0900)
committeriwasaki <iwaaya@yasunaga-lab.bio.kyutech.ac.jp>
Sun, 17 Jan 2016 06:09:04 +0000 (15:09 +0900)
15 files changed:
lib/.cameraSocket.rb.un~
lib/.serialCamera.rb.un~
lib/cameraSocket.rb
lib/cameraSocket.rb~
lib/serialCamera.rb
lib/serialCamera.rb~
vem/.feicontrol.rb.un~
vem/.test.rb.un~
vem/feicontrol.rb
vem/feicontrol.rb~
vem/test.rb
vem/test.rb~
vemserver/.config.rb.un~
vemserver/config.rb
vemserver/config.rb~

index ccb6643..0b248d4 100644 (file)
Binary files a/lib/.cameraSocket.rb.un~ and b/lib/.cameraSocket.rb.un~ differ
index f216c88..9edc75f 100644 (file)
Binary files a/lib/.serialCamera.rb.un~ and b/lib/.serialCamera.rb.un~ differ
index 14ddfd0..09bcefc 100644 (file)
@@ -33,13 +33,13 @@ class CameraSocket
                                if(rec_buf["type"]=="req")
                                        if(rec_buf["data"]=="img")
                                                @buf["type"] = "img"
+                                               @camera.unlock_acq
                                                @buf["data"] = @camera.get_image 
                                                @buf["count"] = @count
                                                ws.send(@buf.to_json)
                                                @count = @count + 1
                                        end
                                end
-
                        end
 
                        ws.onclose do
index fd375d4..09bcefc 100644 (file)
@@ -29,18 +29,17 @@ class CameraSocket
                        end
 
                        ws.onmessage do |msg|
-                               sleep(0.5)
                                rec_buf = JSON.parse(msg)
                                if(rec_buf["type"]=="req")
                                        if(rec_buf["data"]=="img")
                                                @buf["type"] = "img"
+                                               @camera.unlock_acq
                                                @buf["data"] = @camera.get_image 
                                                @buf["count"] = @count
                                                ws.send(@buf.to_json)
                                                @count = @count + 1
                                        end
                                end
-
                        end
 
                        ws.onclose do
index 4397e60..4b95e77 100644 (file)
@@ -14,7 +14,8 @@ class SerialCamera
                @mutex    = Mutex.new
                @cv       = ConditionVariable.new
                @image    = nil
-               @complete = false
+               @acq_lock = true
+               @acq_complete = false
                @flag     = false
                @count = 0
        end
@@ -31,27 +32,33 @@ class SerialCamera
                @flag = false
        end
 
+       def lock_acq
+               @acq_lock = true
+       end
+
+       def unlock_acq
+               @acq_lock = false
+               @cv.broadcast
+       end
+
        def execute
-               #puts "execute #{@count}"
-               sleep(1)
-               @origin_image = @vem.acquisition # 撮影
+               @mutex.synchronize do
+                       @cv.wait(@mutex) while (@acq_lock == true)
+                       @origin_image = @vem.acquisition # 撮
+               end
+               lock_acq
                converted_image = convert_256(@origin_image) # 256階調に変換
                @image = converted_image.to_json 
-               @complete = true
+               @acq_complete = true
                @cv.broadcast
                @count = @count+1
        end
 
        def get_image
-               if(@count==0) then
                @mutex.synchronize do
-                       @cv.wait(@mutex) while (@complete == false)
-                       @complete = false
+                       @cv.wait(@mutex) while (@acq_complete == false)
+                       @acq_complete = false
                        return @image
                end
-               else
-               return @image
-               end
-               
        end
 end
index 8596f09..fd092f3 100644 (file)
@@ -14,7 +14,8 @@ class SerialCamera
                @mutex    = Mutex.new
                @cv       = ConditionVariable.new
                @image    = nil
-               @complete = false
+               @acq_lock = true
+               @acq_complete = false
                @flag     = false
                @count = 0
        end
@@ -31,27 +32,34 @@ class SerialCamera
                @flag = false
        end
 
+       def lock_acq
+               @acq_lock = true
+       end
+
+       def unlock_acq
+               @acq_lock = false
+               @cv.broadcast
+       end
+
        def execute
-               #puts "execute #{@count}"
-               sleep(1.5)
-               @origin_image = @vem.acquisition # 撮影
+               @mutex.synchronize do
+                       @cv.wait(@mutex) while (@acq_lock == true)
+                       puts "acq #{@count}"
+                       @origin_image = @vem.acquisition # 撮
+               end
+               lock_acq
                converted_image = convert_256(@origin_image) # 256階調に変換
                @image = converted_image.to_json 
-               @complete = true
+               @acq_complete = true
                @cv.broadcast
                @count = @count+1
        end
 
        def get_image
-               if(@count==0) then
                @mutex.synchronize do
-                       @cv.wait(@mutex) while (@complete == false)
-                       @complete = false
+                       @cv.wait(@mutex) while (@acq_complete == false)
+                       @acq_complete = false
                        return @image
                end
-               else
-               return @image
-               end
-               
        end
 end
index d6a9ee5..55fcb70 100644 (file)
Binary files a/vem/.feicontrol.rb.un~ and b/vem/.feicontrol.rb.un~ differ
index 06d0f43..9d5afca 100644 (file)
Binary files a/vem/.test.rb.un~ and b/vem/.test.rb.un~ differ
index 4293f7b..3653041 100644 (file)
@@ -236,7 +236,6 @@ class FEIControl < VEM
 
        def acquisition
                @@acq = @@tem.Acquisition
-
                # acquisition Image
                imageCollection = @@acq.AcquireImages
                img     = imageCollection.Item(0)
index 94f488b..2364aed 100644 (file)
@@ -166,11 +166,11 @@ class FEIControl < VEM
                return @@params[:proj][:focus].to_json
        end
 
-       def set_defocusr(params)
-               puts "FEI setDefocus"
+       def set_defocusR(params)
+               puts "FEI setDefocusR"
 
                proj = @@tem.Projection
-               proj.Defocus = proj.Defocus
+               proj.Defocus = proj.Defocus + params*1e-9
                @@params[:proj][:defocus] = proj.Defocus
                return @@params[:proj][:defocus].to_json
        end
@@ -236,10 +236,10 @@ class FEIControl < VEM
 
        def acquisition
                @@acq = @@tem.Acquisition
-
                # acquisition Image
                imageCollection = @@acq.AcquireImages
                img     = imageCollection.Item(0)
+       puts img
                return img.AsSafeArray
        end
 
index 47f6ecc..9200700 100644 (file)
@@ -78,11 +78,13 @@ test.test_set_spotsizeR
 test.test_acq_init
 test.test_acq
 =end
+test.test_acq_init
+test.test_acq
 
 #test.test_set_magnificationR
 #test.test_set_image_beam_shift
 #test.test_set_focus
-test.test_set_defocusR
+#test.test_set_defocusR
 #test.test_set_reset_defocus
 #test.test_set_condenser_stg
 #test.test_set_object_stg
index 65e3d9c..264a75b 100644 (file)
@@ -42,8 +42,8 @@ class TEST
                puts @@vem.set_focus(0)
        end
 
-       def test_set_defocusr
-               puts @@vem.set_defocusr(1)
+       def test_set_defocusR
+               puts @@vem.set_defocusR(1)
        end
 
        def test_set_reset_defocus
@@ -79,10 +79,12 @@ test.test_acq_init
 test.test_acq
 =end
 
+test.test_acq
+
 #test.test_set_magnificationR
 #test.test_set_image_beam_shift
 #test.test_set_focus
-test.test_set_defocus
+#test.test_set_defocusR
 #test.test_set_reset_defocus
 #test.test_set_condenser_stg
 #test.test_set_object_stg
index 042165c..88876cb 100644 (file)
Binary files a/vemserver/.config.rb.un~ and b/vemserver/.config.rb.un~ differ
index 54eee5a..eb952bb 100644 (file)
@@ -1,8 +1,8 @@
 $:.unshift(File.dirname(__FILE__))
 
-$ip_address  = 'localhost'
-$cs_port     = '2000'
+$ip_address  = '192.168.4.146'
+$cs_port     = '3000'
 $vemapi_port = 9090
 $debug       = true
-$em_name     = 'mock'
+$em_name     = 'fei'
 
index 4c793b6..1ca54c5 100644 (file)
@@ -1,8 +1,8 @@
 $:.unshift(File.dirname(__FILE__))
 
-$ip_address  = '192.168.4.146'
-$cs_port     = '3000'
+$ip_address  = 'localhost'
+$cs_port     = '192.168.4.146'
 $vemapi_port = 9090
 $debug       = true
-$em_name     = 'mock'
+$em_name     = 'fei'