--- /dev/null
+require 'drb/drb'
+require './vem'
+require './feicontrol'
+require 'win32ole'
+
+URI = "druby://192.168.4.145:8787"
+DRb.start_service(URI, VEM.create("fei"))
+puts DRb.uri
+sleep
--- /dev/null
+require 'win32ole'
+require 'open3'
+require 'json'
+
+require '../vem/vem'
+
+
+
+class FEIControl < VEM
+ def initialize
+ puts "FEI initialize"
+
+ #@@tem = WIN32OLE.new('TEMScripting.Instrument')
+ end
+
+ def setStageA(x, y, z, a)
+ puts "FEI setStageA"
+
+ o,s = Open3.capture2("cscript vem/tool/setStageA.js " + x.to_s + " " + y.to_s + " " + z.to_s + " " + a.to_s)
+ position = o.lines.to_a[3]
+ puts position
+ return position
+ end
+
+ def setStageR(x, y, z, a)
+
+ puts "FEI setStageR"
+ o,s = Open3.capture2("cscript vem/tool/setStageR.js " + x.to_s + " "+ y.to_s + " " + z.to_s + " " + a.to_s)
+ position = o.lines.to_a[3]
+ puts position
+ return position
+ end
+
+ def setSpotSize(spsize)
+ puts "FEI setSpotSize"
+
+ ill = @@tem.Illumination
+ ill.SpotsizeIndex = ill.SpotsizeIndex + spsize
+ return ill.SpotsizeIndex
+ end
+
+ def setMagnification(magsize)
+ puts "FEI setMagnification"
+
+ proj = @@tem.Projection
+ proj.MagnificationIndex = proj.MagnificationIndex + magsize
+ return proj.MagnificationIndex
+ end
+
+ def acquisition
+ puts "FEI acquisition"
+
+ WIN32OLE.ole_initialize
+ @@tem = WIN32OLE.new('TEMScripting.Instrument')
+
+ # get acquitision object
+ acq = @@tem.Acquisition
+ # acquire an image from "CCD" camera
+ acq.AddAcqDeviceByName("CCD")
+
+ ## settings for acquisition parameters
+ # ccdCamerasAcqParams
+ ccdCamerasAcqParams = acq.Cameras.Item(0).AcqParams
+ # binning
+ ccdCamerasAcqParams.Binning = 4
+ # exposuretime
+ ccdCamerasAcqParams.ExposureTime = 0.07
+ # imagesize
+ ccdCamerasAcqParams.ImageSize = 2
+
+ # acquisition Image
+ imageCollection = acq.AcquireImages
+
+ img = imageCollection.Item(0)
+ imgData = img.AsSafeArray
+ return imgData.to_json
+ end
+
+ def acquisitiona255
+ puts "FEI acquisition"
+
+ WIN32OLE.ole_initialize
+ @@tem = WIN32OLE.new('TEMScripting.Instrument')
+
+ # get acquitision object
+ acq = @@tem.Acquisition
+ # acquire an image from "CCD" camera
+ acq.AddAcqDeviceByName("CCD")
+
+ # ---settings for acquisition parameters
+
+ # ccdCamerasAcqParams
+ ccdCamerasAcqParams = acq.Cameras.Item(0).AcqParams
+ # binning
+ ccdCamerasAcqParams.Binning = 4
+ # exposuretime
+ ccdCamerasAcqParams.ExposureTime = 0.07
+ # imagesize
+ ccdCamerasAcqParams.ImageSize = 2
+
+ # ---end
+
+ # acquisition Image
+ imageCollection = acq.AcquireImages
+
+ img = imageCollection.Item(0)
+ imgData = img.AsSafeArray
+
+ imgLength = imgData.length
+
+ # ---conversion
+
+ #max, min
+ imgMax = imgData.flatten.max
+ imgMin = imgData.flatten.min
+
+ #conversion factor for 255 scale
+ conversion = 255/(imgMax.to_f - imgMin.to_f)
+
+ img255 = Array.new(imgLength){ Array.new(imgLength) }
+
+ imgLength.times do |y|
+ imgLength.times do |x|
+ img255[y][x] = ((imgData[y][x]-imgMin.to_f)*conversion).to_i
+ end
+ end
+
+ # ---end
+
+ return img255.to_json
+ end
+
+ def setObj(params)
+ puts "FEI setObj"
+ end
+
+ def setBeamTilt(params)
+ puts "FEI setBeamTilt"
+ end
+
+ def setSpeed(params)
+ end
+
+ def getCondition
+ puts "FEI getCondition"
+ end
+end
+
--- /dev/null
+require 'win32ole'
+require 'open3'
+require 'json'
+
+require '../vem/vem'
+
+
+
+class FEIControl < VEM
+ def initialize
+ puts "FEI initialize"
+
+ #@@tem = WIN32OLE.new('TEMScripting.Instrument')
+ end
+
+ def setStageA(x, y, z, a)
+ puts "FEI setStageA"
+
+ o,s = Open3.capture2("cscript vem/tool/setStageA.js " + x.to_s + " " + y.to_s + " " + z.to_s + " " + a.to_s)
+ position = o.lines.to_a[3]
+ puts position
+ return position
+ end
+
+ def setStageR(x, y, z, a)
+
+ puts "FEI setStageR"
+ o,s = Open3.capture2("cscript vem/tool/setStageR.js " + x.to_s + " "+ y.to_s + " " + z.to_s + " " + a.to_s)
+ position = o.lines.to_a[3]
+ puts position
+ return position
+ end
+
+ def setSpotSize(spsize)
+ puts "FEI setSpotSize"
+
+ ill = @@tem.Illumination
+ ill.SpotsizeIndex = ill.SpotsizeIndex + spsize
+ return ill.SpotsizeIndex
+ end
+
+ def setMagnification(magsize)
+ puts "FEI setMagnification"
+
+ proj = @@tem.Projection
+ proj.MagnificationIndex = proj.MagnificationIndex + magsize
+ return proj.MagnificationIndex
+ end
+
+ def acquisition
+ puts "FEI acquition"
+
+ WIN32OLE.ole_initialize
+ @@tem = WIN32OLE.new('TEMScripting.Instrument')
+ # get acquitision object
+ acq = @@tem.Acquisition
+ # acquire an image from "CCD" camera
+ acq.AddAcqDeviceByName("CCD")
+ # ccdCamerasAcqParams
+ ccdCamerasAcqParams = acq.Cameras.Item(0).AcqParams
+ # binning
+ ccdCamerasAcqParams.Binning = 4
+ # exposuretime
+ ccdCamerasAcqParams.ExposureTime = 0.07
+ # imagesize
+ ccdCamerasAcqParams.ImageSize = 2
+
+ imageCollection = acq.AcquireImages
+
+ img = imageCollection.Item(0)
+ imgData = img.AsSafeArray
+ sendImgData = imgData
+
+ imgMax = sendImgData.max.max
+ imgMin = sendImgData.min.min
+
+ conversion = 255/(imgMax.to_f - imgMin.to_f)
+
+ array = Array.new
+
+ sendImgData.length.times do |i|
+ array[i] = sendImgData[i].map{|item| item*conversion}
+ end
+
+ puts sendImgData.length
+
+ return array.to_json
+ end
+
+ def setObj(params)
+ puts "FEI setObj"
+ end
+
+ def setBeamTilt(params)
+ puts "FEI setBeamTilt"
+ end
+
+ def setSpeed(params)
+ end
+
+ def getCondition
+ puts "FEI getCondition"
+ end
+end
+
--- /dev/null
+require "./vem"
+
+class HITACHIControl < VEM
+ @@condition = {
+ "TEM" => "HITACHI",
+ "GonioX" => 0,
+ "GonioY" => 0,
+ "GonioZ" => 0,
+ "GonioA" => 0,
+ "SpotSizeIndex" => 0,
+ "MagIndex" => 0,
+ "Obj" => 0,
+ "BeamTiltX" => 0,
+ "BeamTiltY" => 0,
+ "Speed" => 0
+ }
+
+ def initialize
+ end
+
+ def setStageA(params)
+ @@condition["GonioX"] = params["x"]
+ @@condition["GonioY"] = params["y"]
+ @@condition["GonioZ"] = params["z"]
+ @@condition["GonioA"] = params["a"]
+ return @@condition.to_json
+ end
+
+ def setStageR(params)
+ end
+
+ def setSpotSize(params)
+ @@condition["SpotSizeIndex"] = params["sps"]
+ return @@condition.to_json
+ end
+
+ def setMagnification(params)
+ @@condition["MagIndex"] = params["mag"]
+ return @@condition.to_json
+ end
+
+ def setObj(params)
+ @@condition["Obj"] = params["obj"]
+ return @@condition.to_json
+ end
+
+ def setBeamTilt(params)
+ @@condition["BeamTiltX"] = params["btx"]
+ @@condition["BeamTiltY"] = params["bty"]
+ return @@condition.to_json
+ end
+
+ def setSpeed(params)
+ @@condition["Speed"] = params["sp"]
+ return @@condition.to_json
+ end
+
+ def getCondition
+ return @@condition.to_json
+ end
+end
+
--- /dev/null
+require "./vem"
+
+class JEOLControl < VEM
+ @@condition = {
+ "TEM" => "JEOL",
+ "GonioX" => 0,
+ "GonioY" => 0,
+ "GonioZ" => 0,
+ "GonioA" => 0,
+ "SpotSizeIndex" => 0,
+ "MagIndex" => 0,
+ "Obj" => 0,
+ "BeamTiltX" => 0,
+ "BeamTiltY" => 0,
+ "Speed" => 0
+ }
+
+ def initialize
+ end
+
+ def setStageA(params)
+ @@condition["GonioX"] = params["x"]
+ @@condition["GonioY"] = params["y"]
+ @@condition["GonioZ"] = params["z"]
+ @@condition["GonioA"] = params["a"]
+ return @@condition.to_json
+ end
+
+ def setStageR(params)
+ end
+
+ def setSpotSize(params)
+ @@condition["SpotSizeIndex"] = params["sps"]
+ return @@condition.to_json
+ end
+
+ def setMagnification(params)
+ @@condition["MagIndex"] = params["mag"]
+ return @@condition.to_json
+ end
+
+ def setObj(params)
+ @@condition["Obj"] = params["obj"]
+ return @@condition.to_json
+ end
+
+ def setBeamTilt(params)
+ @@condition["BeamTiltX"] = params["btx"]
+ @@condition["BeamTiltY"] = params["bty"]
+ return @@condition.to_json
+ end
+
+ def setSpeed(params)
+ @@condition["Speed"] = params["sp"]
+ return @@condition.to_json
+ end
+
+ def getCondition
+ return @@condition.to_json
+ end
+end
+
--- /dev/null
+require "../../vem/vem"
+require "../../vem/feicontrol"
+
+class TEST
+ def initialize
+ @@vem = VEM.create("fei")
+ end
+
+ def test_setStageA
+ @@vem.setStageA(2, 0, 0, 0)
+ end
+
+ def test_setStageR
+ @@vem.setStageR(1, 0, 0, 0)
+ end
+
+ def test_setSpotSize
+ @@vem.setSpotSize(1)
+ end
+
+ def test_acquisition
+ @@vem.acquisition
+ end
+end
+
+
--- /dev/null
+require "./vem/vem"
+require "./vem/feicontrol"
+
+class TEST
+ def initialize
+ @@vem = VEM.create("fei")
+ end
+
+ def test_setStageA
+ @@vem.setStageA(2, 0, 0, 0)
+ end
+
+ def test_setStageR
+ @@vem.setStageR(1, 0, 0, 0)
+ end
+
+ def test_setSpotSize
+ @@vem.setSpotSize(1)
+ end
+
+ def test_acquisition
+ @@vem.acquisition
+ end
+end
+
+
--- /dev/null
+var m;
+var Proj;
+var Ill;
+
+m = new ActiveXObject("TEMScripting.Instrument");
+
+Proj = m.Projection;
+Ill = m.Illumination;
+
+var data = {
+X:m.Stage.Position.X*1000000,
+Y:m.Stage.Position.Y*1000000,
+Z:m.Stage.Position.Z*1000000,
+A:m.Stage.Position.A*3.14159/180.0,
+SpotSizeIndex:Ill.SpotsizeIndex,
+Mag:Proj.Magnification
+//Obj:,
+//BeamTiltX:,
+//BeamTiltY:
+};
+
+WScript.echo('{"X":'+data["X"]+', "Y":'+data["Y"]+', "Z":'+data["Z"]+', "A":'+data["A"]+', "SpotSizeIndex":'+data["SpotSizeIndex"]+', "Mag":'+data["Mag"]+'}');
+
--- /dev/null
+var m;
+var proj;
+var magIndex;
+
+var objParm = WScript.arguments;
+
+magIndex = objParm(0);
+
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create Projection object
+proj = m.Projection;
+
+
+
+WScript.echo(proj.Magnification, proj.MagnificationIndex);
+
+//proj.MagnificationIndex = 30;
+
+//WScript.echo(proj.Magnification, proj.MagnificationIndex);
+
--- /dev/null
+var m;
+var proj;
+var magIndex;
+
+var objParm = WScript.arguments;
+
+magIndex = objParm(0);
+
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create Projection object
+proj = m.Projection;
+proj.MagnificationIndex = magIndex;
+
+
+WScript.echo('{"Mag":'+proj.Magnification+', "MagIndex":'+proj.MagnificationIndex+'}');
+
+
--- /dev/null
+var m;
+var proj;
+var magIndex;
+
+var objParm = WScript.arguments;
+
+magIndex = objParm(0);
+
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create Projection object
+proj = m.Projection;
+
+
+
+WScript.echo(proj.Magnification, proj.MagnificationIndex);
+
+//proj.MagnificationIndex = 30;
+
+//WScript.echo(proj.Magnification, proj.MagnificationIndex);
+
--- /dev/null
+var m;
+var ill;
+var spsize;
+
+var objParm = WScript.arguments;
+
+m = new ActiveXObject("TEMScripting.Instrument");
+
+ill = m.Illumination;
+
+spsize = objParm(0);
+
+ill.SpotsizeIndex = spsize;
+
+WScript.echo('{"SpotSizeIndex":'+ill.SpotsizeIndex+'}');
--- /dev/null
+var m;
+var Position;
+var x;
+var y;
+var z;
+var a;
+var b;
+
+var objParm = WScript.arguments;
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create StagePosition object
+Position = new m.StagePosition(0,0,0,0,0);
+
+x = objParm(0)*1e-7;
+y = objParm(1)*1e-7;
+z = objParm(2)*1e-7;
+a = objParm(3) * 3.14159/180.0;
+
+Position.X = x;
+Position.Y = y;
+Position.Z = z;
+Position.A = a;
+
+
+//move stage
+m.Stage.GoTo(Position, 15);
+
+var data = {
+x:m.Stage.Position.X * 1000000,
+y:m.Stage.Position.Y * 1000000,
+z:m.Stage.Position.Z * 1000000,
+a:m.Stage.Position.A * 180.0/3.14159
+};
+
+
+WScript.echo('{"X":'+data["x"]+', "Y":'+data["y"]+', "Z":'+data["z"]+', "A":'+data["a"]+'}');
--- /dev/null
+var m;
+var Position;
+var x;
+var y;
+var z;
+var a;
+var b;
+
+var objParm = WScript.arguments;
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create StagePosition object
+Position = new m.StagePosition(0,0,0,0,0);
+
+x = objParm(0)*1e-7;
+y = objParm(1)*1e-7;
+z = objParm(2)*1e-7;
+a = objParm(3) * 3.14159/180.0;
+
+Position.X = x;
+Position.Y = y;
+Position.Z = z;
+Position.A = a;
+
+
+//move stage
+m.Stage.GoTo(Position, 15);
+
+var data = {
+x:m.Stage.Position.X * 1000000,
+y:m.Stage.Position.Y * 1000000,
+z:m.Stage.Position.Z * 1000000,
+a:m.Stage.Position.A * 180.0/3.14159
+};
+
+
+WScript.echo('{"X":'+data["x"]+', "Y":'+data["y"]+', "Z":'+data["z"]+', "A":'+data["a"]+'}');
--- /dev/null
+var m;
+var Position;
+var x;
+var y;
+var z;
+var a;
+var b;
+
+var objParm = WScript.arguments;
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create StagePosition object
+Position = new m.StagePosition(0,0,0,0,0);
+
+x = objParm(0)*1e-7;
+y = objParm(1)*1e-7;
+z = objParm(2)*1e-7;
+a = objParm(3) * 3.14159/180.0;
+
+Position.X = m.Stage.Position.X + x;
+Position.Y = m.Stage.Position.Y + y;
+Position.Z = m.Stage.Position.Z + z;
+Position.A = m.Stage.Position.A + a;
+
+
+//move stage
+m.Stage.GoTo(Position, 15);
+
+var data = {
+x:m.Stage.Position.X*1000000,
+y:m.Stage.Position.Y*1000000,
+z:m.Stage.Position.Z*1000000,
+a:m.Stage.Position.A
+};
+
+
+WScript.echo(data["x"], data["y"], data["z"], data["a"]);
--- /dev/null
+var m;
+var Position;
+var x;
+var y;
+var z;
+var a;
+var b;
+
+var objParm = WScript.arguments;
+
+//create TEMScripting Scripting
+m = new ActiveXObject("TEMScripting.Instrument");
+
+//create StagePosition object
+Position = new m.StagePosition(0,0,0,0,0);
+
+x = objParm(0)*1e-6;
+y = objParm(1)*1e-6;
+z = objParm(2)*1e-6;
+a = objParm(3) * 3.14159/180.0;
+
+Position.X = m.Stage.Position.X + x;
+Position.Y = m.Stage.Position.Y + y;
+Position.Z = m.Stage.Position.Z + z;
+Position.A = m.Stage.Position.A + a;
+
+
+//move stage
+m.Stage.GoTo(Position, 15);
+
+var data = {
+x:m.Stage.Position.X*1000000,
+y:m.Stage.Position.Y*1000000,
+z:m.Stage.Position.Z*1000000,
+a:m.Stage.Position.A
+};
+
+
+WScript.echo(data["x"], data["y"], data["z"], data["a"]);
--- /dev/null
+
+class VEM
+
+ def self.create (inst)
+ if inst == "hitachi" then
+ HITACHIControl.new()
+ elsif inst == "fei" then
+ FEIControl.new()
+ elsif inst == "jeol" then
+ JEOLControl.new()
+ end
+ end
+
+ def initialize
+ end
+
+ def setStageA(x, y, z, a)
+ end
+
+ def setStageR(x, y, z, a)
+ end
+
+ def setSpotSize(spsize)
+ end
+
+ def setMagnification(magsize)
+ end
+
+ def acquisition
+ end
+
+ def acquisition255
+ end
+
+ def setObj(params)
+ end
+
+ def setBeamTilt(params)
+ end
+
+ def setSpeed(params)
+ end
+
+ def getCondition
+ end
+end