OSDN Git Service

sync iwasaki mac
[vem/vem.git] / vem / feicontrol.rb
1 $:.unshift(File.dirname(__FILE__))
2
3 require 'win32ole'
4 require 'open3'
5 require 'json'
6
7 require 'vem'
8
9
10
11 class FEIControl < VEM
12
13         @@params = {
14                 "x" => 0,
15                 "y" => 0,
16                 "z" => 0,
17                 "a" => 0
18         }
19
20         @@acq = nil
21
22
23         def initialize
24                 puts "FEI initialize"
25
26                 @@tem    = WIN32OLE.new('TEMScripting.Instrument')
27         end
28
29         def get_params
30                 puts "FEI get params"
31
32                 @@params["x"] = @@tem.Stage.Position.X
33                 @@params["y"] = @@tem.Stage.Position.Y
34                 @@params["z"] = @@tem.Stage.Position.Z
35                 @@params["a"] = @@tem.Stage.Position.A
36                 return @@params
37         end
38
39         def set_stageA(x, y, z, a)
40                 puts "FEI setStageA"
41
42                 position = @@tem.Stage.Position
43                 position.X = x*1e-7
44                 position.Y = y*1e-7
45                 position.Z = z*1e-7
46                 position.A = a*(3.145159/180.0)
47
48                 @@tem.Stage.GoTo(position, 15)
49                 get_params
50                 return @@params
51         end
52
53         def set_stageR(x, y, z, a)
54                 puts "FEI setStageR"
55
56                 position = @@tem.Stage.Position
57                 position.X = position.X + x*1e-7
58                 position.Y = position.Y + y*1e-7
59                 position.Z = position.Z + z*1e-7
60                 position.A = position.A + a*(3.145159/180.0)
61
62                 @@tem.Stage.GoTo(position, 15)
63                 get_params
64                 return @@params
65         end
66
67         def set_spotsize(spsize)
68                 puts "FEI setSpotSize"
69
70                 ill    = @@tem.Illumination
71                 ill.SpotsizeIndex = ill.SpotsizeIndex + spsize
72                 return ill.SpotsizeIndex
73         end
74
75         def set_magnification(magsize)
76                 puts "FEI setMagnification"
77
78                 proj = @@tem.Projection
79                 proj.MagnificationIndex = proj.MagnificationIndex + magsize
80                 return proj.MagnificationIndex
81         end
82
83         def acquisition_init(binning, expTime, imageSize)
84                 # get acquitision object
85                 @@acq = @@tem.Acquisition
86                 # acquire an image from "CCD" camera
87                 @@acq.AddAcqDeviceByName("CCD")
88
89                 ## settings for acquisition parameters
90                 # ccdCamerasAcqParams
91                 ccdCamerasAcqParams = @@acq.Cameras.Item(0).AcqParams
92                 # binning
93                 ccdCamerasAcqParams.Binning = binning
94                 # exposuretime
95                 ccdCamerasAcqParams.ExposureTime = expTime
96                 # imagesize
97                 ccdCamerasAcqParams.ImageSize = imageSize
98         end
99
100         def acquisition
101                 # acquisition Image
102                 imageCollection = @@acq.AcquireImages
103
104                 img     = imageCollection.Item(0)
105                 imgData = img.AsSafeArray
106                 return imgData.to_json
107         end
108
109         def setObj(params)
110                 puts "FEI setObj"
111         end
112
113         def setBeamTilt(params)
114                 puts "FEI setBeamTilt"
115         end
116
117         def setSpeed(params)
118         end
119
120         def getCondition
121                 puts "FEI getCondition"
122         end
123 end
124