OSDN Git Service

commit by fei
[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[:proj][:defocus] = @@tem.Projection.Defocus*1000000000
62                 #       @@params[:ccdCamera][:binning] = ccdCamerasAcqParams.Binning
63                 #       @@params[:ccdCamera][:expTime]  = ccdCamerasAcqParams.ExposureTime
64                 #       @@params[:ccdCamera][:imageSize] = ccdCamerasAcqParams.ImageSize
65
66                 return @@params.to_json
67         end
68
69         def set_stageA(x, y, z, a)
70                 puts "FEI setStageA"
71
72                 position = @@tem.Stage.Position
73                 position.X = x*1e-7
74                 position.Y = y*1e-7
75                 position.Z = z*1e-7
76                 position.A = a*(3.145159/180.0)
77
78                 @@tem.Stage.GoTo(position, 15)
79
80                 @@params[:stage][:x] = @@tem.Stage.Position.X
81                 @@params[:stage][:y] = @@tem.Stage.Position.Y
82                 @@params[:stage][:z] = @@tem.Stage.Position.Z
83                 @@params[:stage][:a] = @@tem.Stage.Position.A
84
85                 return @@params[:stage].to_json
86         end
87
88         def set_stageR(x, y, z, a)
89                 puts "FEI setStageR"
90
91
92                 position = @@tem.Stage.Position
93                 position.X = position.X + x*1e-7
94                 position.Y = position.Y + y*1e-7
95                 position.Z = position.Z + z*1e-7
96                 position.A = position.A + a*(3.145159/180.0)
97
98                 @@tem.Stage.GoTo(position, 15)
99
100                 @@params[:stage][:x] = @@tem.Stage.Position.X
101                 @@params[:stage][:y] = @@tem.Stage.Position.Y
102                 @@params[:stage][:z] = @@tem.Stage.Position.Z
103                 @@params[:stage][:a] = @@tem.Stage.Position.A
104
105                 return @@params[:stage].to_json
106         end
107
108         def set_spotsizeA(spsize)
109                 puts "FEI setSpotSizeA"
110
111                 ill    = @@tem.Illumination
112                 ill.SpotsizeIndex = spsize
113                 @@params[:ill][:spotSizeIndex] = ill.SpotsizeIndex
114                 return @@params[:ill].to_json
115         end
116
117         def set_spotsizeR(spsize)
118                 puts "FEI setSpotSizeR"
119
120                 ill    = @@tem.Illumination
121                 ill.SpotsizeIndex = ill.SpotsizeIndex + spsize
122                 @@params[:ill][:spotSizeIndex] = ill.SpotsizeIndex
123                 return @@params[:ill].to_json
124         end
125
126
127         def set_magnificationA(magsize)
128                 puts "FEI setMagnificationA"
129
130                 proj = @@tem.Projection
131                 proj.MagnificationIndex = magsize
132                 @@params[:proj][:magIndex] = proj.MagnificationIndex
133                 @@params[:proj][:mag] = proj.Magnification
134                 return @@params[:proj].to_json
135         end
136
137         def set_magnificationR(magsize)
138                 puts "FEI setMagnificationR"
139
140                 proj = @@tem.Projection
141                 proj.MagnificationIndex = proj.MagnificationIndex + magsize
142                 @@params[:proj][:magIndex] = proj.MagnificationIndex
143                 @@params[:proj][:mag] = proj.Magnification
144                 return @@params[:proj].to_json
145         end
146
147         def set_image_beam_shift(x, y)
148                 puts "FEI setImageShift"
149
150                 proj = @@tem.Projection
151                 proj.ImageBeamShift.X = proj.ImageBeamShift.X
152                 proj.ImageBeamShift.Y = proj.ImageBeamShift.Y
153
154                 puts proj.ImageBeamShift.X
155                 @@params[:proj][:imageShift][:x] = proj.ImageBeamShift.X
156                 @@params[:proj][:imageShift][:y] = proj.ImageBeamShift.Y
157
158         return @@params[:proj][:imageShift].to_json
159         end
160
161         def set_focus(params)
162                 puts "FEI setFocus"
163
164                 proj = @@tem.Projection
165                 #proj.Focus = proj.Focus
166                 @@params[:proj][:focus] = proj.Focus
167                 return @@params[:proj][:focus].to_json
168         end
169
170         def set_defocusR(params)
171                 puts "FEI setDefocusR"
172
173                 proj = @@tem.Projection
174                 proj.Defocus = proj.Defocus + params*1e-9
175                 @@params[:proj][:defocus] = proj.Defocus*1000000000
176                 return @@params[:proj][:defocus].to_json
177         end
178
179         def set_reset_defocus
180                 puts "FEI resetDefocus"
181
182                 proj = @@tem.Projection
183                 proj.ResetDefocus
184                 @@params[:proj][:defocus] = proj.Defocus*1000000000
185                 return @@params[:proj][:defocus].to_json
186         end
187
188         def set_condenser_stg(x, y)
189                 puts "FEI setCondenserStigmater"
190
191                 ill = @@tem.Illumination
192                 ill.CondenserStigmator.X = ill.CondenserStigmator.X + x
193                 ill.CondenserStigmator.Y = ill.CondenserStigmator.Y + y
194                 @@params[:ill][:condenserStg][:x] = ill.CondenserStigmator.X
195                 @@params[:ill][:condenserStg][:y] = ill.CondenserStigmator.Y
196                 return @@params[:ill][:condenserStg].to_json
197         end
198
199         def set_object_stg(x, y)
200                 puts "FEI setObjectStigmator"
201
202                 proj = @@tem.Projection
203                 proj.ObjectiveStigmator.X = proj.ObjectiveStigmator.X + x
204                 proj.ObjectiveStigmator.Y = proj.ObjectiveStigmator.Y + y
205                 @@params[:proj][:objStg][:x] = proj.ObjectiveStigmator.X
206                 @@params[:proj][:objStg][:y] = proj.ObjectiveStigmator.Y
207         return @@params[:proj][:objStg].to_json
208         end
209
210
211         def acquisition_init(binning, exp_time, image_size)
212                 puts "FEI acq_init"
213
214
215                 # get acquitision object
216                 @@acq = @@tem.Acquisition
217
218                 # acquire an image from "CCD" camera
219                 @@acq.AddAcqDeviceByName("CCD")
220
221                 ## settings for acquisition parameters
222                 # ccdCamerasAcqParams
223                 ccdCamerasAcqParams = @@acq.Cameras.Item(0).AcqParams
224                 # binning
225                 ccdCamerasAcqParams.Binning = binning
226                 # exposuretime
227                 ccdCamerasAcqParams.ExposureTime = exp_time
228                 # imagesize
229                 ccdCamerasAcqParams.ImageSize = image_size
230                 # image correction
231                 # ccdCamerasAcqParams.ImageCorrection = 1 
232
233                 @@params[:ccdCamera][:binning] = ccdCamerasAcqParams.Binning
234                 @@params[:ccdCamera][:expTime]  = ccdCamerasAcqParams.ExposureTime
235                 @@params[:ccdCamera][:imageSize] = ccdCamerasAcqParams.ImageSize
236
237                 return @@params[:ccdCamera].to_json
238         end
239
240         def acquisition
241                 @@acq = @@tem.Acquisition
242                 # acquisition Image
243                 imageCollection = @@acq.AcquireImages
244                 img     = imageCollection.Item(0)
245                 return img.AsSafeArray
246         end
247
248         def set_obj(params)
249                 puts "FEI setObj"
250         end
251
252         def set_beamtilt(params)
253                 puts "FEI setBeamTilt"
254         end
255
256         def get_vacuum_status
257                 puts "FEI getVacuumStatus"
258                 puts @@tem.Vacuum.Gauges.Item(5).Name
259                 puts @@tem.Vacuum.Gauges.Item(1).Pressure
260         end
261
262 end
263