OSDN Git Service

speed up serialCamera
[vem/vem.git] / vem / feicontrol.rb
1 $:.unshift(File.dirname(__FILE__))
2
3 require 'singleton'
4 require 'win32ole'
5 require 'json'
6 require 'vem'
7
8 module FEIObject
9         @instance = nil
10         def FEIObject.instance
11                 unless @instance then
12                         @instance = WIN32OLE.new('TEMScripting.Instrument')
13                 end
14                 return @instance
15         end
16 end
17
18 class FEIControl < VEM
19         include FEIObject
20
21         def initialize
22                 @@tem = FEIObject.instance
23                 @@acq = nil
24                 @@params = {
25                         :stage => {
26                                 :x => 0,
27                                 :y => 0,
28                                 :z => 0,
29                                 :a => 0,
30                         },
31                         :ccdCamera => {
32                                 :binning    => 4,
33                                 :expTime    => 0.07,
34                                 :imageSize  => 0
35                         },
36                         :proj => {
37                                 :magIndex => 0,
38                                 :mag => 0,
39                                 :imageShift => {:x => 0, :y => 0},
40                                 :focus => 0,
41                                 :defocus => 0,
42                                 :objStg => {:x => 0, :y => 0}
43                         },
44                         :ill => {
45                                 :spotSizeIndex => 0,
46                                 :condenserStg => {:x => 0, :y => 0}
47
48                         }
49                 }
50         end
51
52         def get_params
53                 puts "FEI get params"
54
55                 @@params[:stage][:x] = @@tem.Stage.Position.X
56                 @@params[:stage][:y] = @@tem.Stage.Position.Y
57                 @@params[:stage][:z] = @@tem.Stage.Position.Z
58                 @@params[:stage][:a] = @@tem.Stage.Position.A
59                 @@params[:ill][:spotSizeIndex] = @@tem.Illumination.SpotsizeIndex
60                 @@params[:proj][:magIndex] = @@tem.Projection.MagnificationIndex
61                 #       @@params[:ccdCamera][:binning] = ccdCamerasAcqParams.Binning
62                 #       @@params[:ccdCamera][:expTime]  = ccdCamerasAcqParams.ExposureTime
63                 #       @@params[:ccdCamera][:imageSize] = ccdCamerasAcqParams.ImageSize
64
65                 return @@params.to_json
66         end
67
68         def set_stageA(x, y, z, a)
69                 puts "FEI setStageA"
70
71                 position = @@tem.Stage.Position
72                 position.X = x*1e-7
73                 position.Y = y*1e-7
74                 position.Z = z*1e-7
75                 position.A = a*(3.145159/180.0)
76
77                 @@tem.Stage.GoTo(position, 15)
78
79                 @@params[:stage][:x] = @@tem.Stage.Position.X
80                 @@params[:stage][:y] = @@tem.Stage.Position.Y
81                 @@params[:stage][:z] = @@tem.Stage.Position.Z
82                 @@params[:stage][:a] = @@tem.Stage.Position.A
83
84                 return @@params[:stage].to_json
85         end
86
87         def set_stageR(x, y, z, a)
88                 puts "FEI setStageR"
89
90
91                 position = @@tem.Stage.Position
92                 position.X = position.X + x*1e-7
93                 position.Y = position.Y + y*1e-7
94                 position.Z = position.Z + z*1e-7
95                 position.A = position.A + a*(3.145159/180.0)
96
97                 @@tem.Stage.GoTo(position, 15)
98
99                 @@params[:stage][:x] = @@tem.Stage.Position.X
100                 @@params[:stage][:y] = @@tem.Stage.Position.Y
101                 @@params[:stage][:z] = @@tem.Stage.Position.Z
102                 @@params[:stage][:a] = @@tem.Stage.Position.A
103
104                 return @@params[:stage].to_json
105         end
106
107         def set_spotsizeA(spsize)
108                 puts "FEI setSpotSizeA"
109
110                 ill    = @@tem.Illumination
111                 ill.SpotsizeIndex = spsize
112                 @@params[:ill][:spotSizeIndex] = ill.SpotsizeIndex
113                 return @@params[:ill].to_json
114         end
115
116         def set_spotsizeR(spsize)
117                 puts "FEI setSpotSizeR"
118
119                 ill    = @@tem.Illumination
120                 ill.SpotsizeIndex = ill.SpotsizeIndex + spsize
121                 @@params[:ill][:spotSizeIndex] = ill.SpotsizeIndex
122                 return @@params[:ill].to_json
123         end
124
125
126         def set_magnificationA(magsize)
127                 puts "FEI setMagnificationA"
128
129                 proj = @@tem.Projection
130                 proj.MagnificationIndex = magsize
131                 @@params[:proj][:magIndex] = proj.MagnificationIndex
132                 @@params[:proj][:mag] = proj.Magnification
133                 return @@params[:proj].to_json
134         end
135
136         def set_magnificationR(magsize)
137                 puts "FEI setMagnificationR"
138
139                 proj = @@tem.Projection
140                 proj.MagnificationIndex = proj.MagnificationIndex + magsize
141                 @@params[:proj][:magIndex] = proj.MagnificationIndex
142                 @@params[:proj][:mag] = proj.Magnification
143                 return @@params[:proj].to_json
144         end
145
146         def set_image_beam_shift(x, y)
147                 puts "FEI setImageShift"
148
149                 proj = @@tem.Projection
150                 proj.ImageBeamShift.X = proj.ImageBeamShift.X
151                 proj.ImageBeamShift.Y = proj.ImageBeamShift.Y
152
153                 puts proj.ImageBeamShift.X
154                 @@params[:proj][:imageShift][:x] = proj.ImageBeamShift.X
155                 @@params[:proj][:imageShift][:y] = proj.ImageBeamShift.Y
156
157         return @@params[:proj][:imageShift].to_json
158         end
159
160         def set_focus(params)
161                 puts "FEI setFocus"
162
163                 proj = @@tem.Projection
164                 #proj.Focus = proj.Focus
165                 @@params[:proj][:focus] = proj.Focus
166                 return @@params[:proj][:focus].to_json
167         end
168
169         def set_defocusR(params)
170                 puts "FEI setDefocusR"
171
172                 proj = @@tem.Projection
173                 proj.Defocus = proj.Defocus + params*1e-9
174                 @@params[:proj][:defocus] = proj.Defocus
175                 return @@params[:proj][:defocus].to_json
176         end
177
178         def set_reset_defocus
179                 puts "FEI resetDefocus"
180
181                 proj = @@tem.Projection
182                 proj.ResetDefocus
183                 @@params[:proj][:defocus] = proj.Defocus
184                 return @@params[:proj][:defocus].to_json
185         end
186
187         def set_condenser_stg(x, y)
188                 puts "FEI setCondenserStigmater"
189
190                 ill = @@tem.Illumination
191                 ill.CondenserStigmator.X = ill.CondenserStigmator.X + x
192                 ill.CondenserStigmator.Y = ill.CondenserStigmator.Y + y
193                 @@params[:ill][:condenserStg][:x] = ill.CondenserStigmator.X
194                 @@params[:ill][:condenserStg][:y] = ill.CondenserStigmator.Y
195                 return @@params[:ill][:condenserStg].to_json
196         end
197
198         def set_object_stg(x, y)
199                 puts "FEI setObjectStigmator"
200
201                 proj = @@tem.Projection
202                 proj.ObjectiveStigmator.X = proj.ObjectiveStigmator.X + x
203                 proj.ObjectiveStigmator.Y = proj.ObjectiveStigmator.Y + y
204                 @@params[:proj][:objStg][:x] = proj.ObjectiveStigmator.X
205                 @@params[:proj][:objStg][:y] = proj.ObjectiveStigmator.Y
206         return @@params[:proj][:objStg].to_json
207         end
208
209
210         def acquisition_init(binning, exp_time, image_size)
211                 puts "FEI acq_init"
212
213
214                 # get acquitision object
215                 @@acq = @@tem.Acquisition
216
217                 # acquire an image from "CCD" camera
218                 @@acq.AddAcqDeviceByName("CCD")
219
220                 ## settings for acquisition parameters
221                 # ccdCamerasAcqParams
222                 ccdCamerasAcqParams = @@acq.Cameras.Item(0).AcqParams
223                 # binning
224                 ccdCamerasAcqParams.Binning = binning
225                 # exposuretime
226                 ccdCamerasAcqParams.ExposureTime = exp_time
227                 # imagesize
228                 ccdCamerasAcqParams.ImageSize = image_size
229
230                 @@params[:ccdCamera][:binning] = ccdCamerasAcqParams.Binning
231                 @@params[:ccdCamera][:expTime]  = ccdCamerasAcqParams.ExposureTime
232                 @@params[:ccdCamera][:imageSize] = ccdCamerasAcqParams.ImageSize
233
234                 return @@params[:ccdCamera].to_json
235         end
236
237         def acquisition
238                 @@acq = @@tem.Acquisition
239                 # acquisition Image
240                 imageCollection = @@acq.AcquireImages
241                 img     = imageCollection.Item(0)
242                 return img.AsSafeArray
243         end
244
245         def set_obj(params)
246                 puts "FEI setObj"
247         end
248
249         def set_beamtilt(params)
250                 puts "FEI setBeamTilt"
251         end
252
253 end
254