 
// Faux microscope library. 

// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this address work)
// version20200718, v1.0, July 2020, www.dmscripting.com

// Installing this script as a Library in an offline version of DigitalMicrograph will allow initial drafts of microscope
// control scripts to be developed away from the microscope. Scripters need only move to the microscope for the final setup
// testing and commissioning.

// You should check the behaviour of any command with your microscope before attempting to use it.
// You can do this by writing short scripts to probe the values which your microscope returns.
/* eg the script

number focus=emggetmagnification()
return ("\nMagnification = "+magnfication)

will output the returned magnification to the Output (Results) window and show you the format.
*/

// The numerical and string values returned here should not be taken as being representative of what the command will actually
// return. Values are simply supplied to make the script work. You must establish what your microscope will return by testing individual commands 
// at your microscope. Any taggroups returned by functions are empty, so do not attempt to extract information from them.

// Some caution is needed when setting microscope values, as script commands do not protect the microscope from
// silly or dangerous values. For example if you set a stage x (alpha) tilt to 40 degs, the stage will
// move to that value unless there is a hardware stop built-in (which there is). However, it is prudent
// when changing values via script to again test the behaviour of the system will small standalone scripts
// like the one above. You can always build-in your own software limits to that ensure your script does not 
// attempt to push the microscope beyond its limits. 
 
 // The commands below are the generic microscope control commands (TEM agnostic)
 // available in GMS 2

// these are the default values which those commands which return microscope values will use. If you want to change the behaviour of the library you can edit them.
// either do this prior to installing the script as a library. Alternatively, this can be done after installation. This entails editing the default value in the
// Global Info - in DigitalMicrograph select File/Global Info/Global Tags/Faux Microscope.

// For commands where you set the values - eg EMSetBeamTilt() - you will need to enter numerical values (these can be any value) when you run the command. 
// The library will simply list that the command has been called and will report the values in the Output window.


number defaultcangetcamlen=1
if(!getpersistentnumbernote("Faux Microscope:Can Get Camera Length (0-1)", defaultcangetcamlen))
	{
		setpersistentnumbernote("Faux Microscope:Can Get Camera Length (0-1)", defaultcangetcamlen)
	}

number defaultcangeth=0
if(!getpersistentnumbernote("Faux Microscope:Can Get High Tension (0-1)", defaultcangeth))
	{
		setpersistentnumbernote("Faux Microscope:Can Get High Tension (0-1)", defaultcangeth)
	}

number defaultcangetilluminationmode=1
if(!getpersistentnumbernote("Faux Microscope:Can Get Illumination Mode (0-1)", defaultcangetilluminationmode))
	{
		setpersistentnumbernote("Faux Microscope:Can Get Illumination Mode (0-1)", defaultcangetilluminationmode)
	}

number defaultcangetimagingopticsmode=1
if(!getpersistentnumbernote("Faux Microscope:Can Get Imaging Optics Mode (0-1)", defaultcangetimagingopticsmode))
	{
		setpersistentnumbernote("Faux Microscope:Can Get Imaging Optics Mode (0-1)", defaultcangetimagingopticsmode)
	}

number defaultcangetmagnification=1
if(!getpersistentnumbernote("Faux Microscope:Can Get Magnification (0-1)", defaultcangetmagnification))
	{
		setpersistentnumbernote("Faux Microscope:Can Get Magnification (0-1)", defaultcangetmagnification)
	}


number defaultbeamshiftx=8000
if(!getpersistentnumbernote("Faux Microscope:Beam Shift X", defaultbeamshiftx))
	{
		setpersistentnumbernote("Faux Microscope:Beam Shift X", defaultbeamshiftx)
	}

number defaultbeamshifty=8010
if(!getpersistentnumbernote("Faux Microscope:Beam Shift Y", defaultbeamshifty))
	{
		setpersistentnumbernote("Faux Microscope:Beam Shift Y", defaultbeamshifty)
	}

number defaultbeamtiltx=8020
if(!getpersistentnumbernote("Faux Microscope:Beam Tilt X", defaultbeamtiltx))
	{
		setpersistentnumbernote("Faux Microscope:Beam Tilt X", defaultbeamtiltx)
	}

number defaultbeamtilty=8030
if(!getpersistentnumbernote("Faux Microscope:Beam Tilt Y", defaultbeamtilty))
	{
		setpersistentnumbernote("Faux Microscope:Beam Tilt Y", defaultbeamtilty)
	}
	
number defaultbrightness=8040
if(!getpersistentnumbernote("Faux Microscope:Brightness", defaultbrightness))
	{
		setpersistentnumbernote("Faux Microscope:Brightness", defaultbrightness)
	}

number defaultcalibratedbeamshiftx=8050
if(!getpersistentnumbernote("Faux Microscope:Calibrated Beam Shift X", defaultcalibratedbeamshiftx))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Shift X", defaultcalibratedbeamshiftx)
	}
	
number defaultcalibratedbeamshifty=8060
if(!getpersistentnumbernote("Faux Microscope:Calibrated Beam Shift Y", defaultcalibratedbeamshifty))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Shift Y", defaultcalibratedbeamshifty)
	}

number defaultcalibratedbeamtiltx=8070
if(!getpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt X", defaultcalibratedbeamtiltx))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt X", defaultcalibratedbeamtiltx)
	}
	
number defaultcalibratedbeamtilty=8080
if(!getpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt Y", defaultcalibratedbeamtilty))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt Y", defaultcalibratedbeamtilty)
	}

number defaultcalcameralength=30
if(!getpersistentnumbernote("Faux Microscope:Calibrated Camera Length", defaultcalcameralength))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Camera Length", defaultcalcameralength)
	}

number defaultcalfieldofview=4000
if(!getpersistentnumbernote("Faux Microscope:Calibrated Field of View", defaultcalfieldofview))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Field of View", defaultcalfieldofview)
	}

number defaultcalfocus=423
if(!getpersistentnumbernote("Faux Microscope:Calibrated Focus", defaultcalfocus))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Focus", defaultcalfocus)
	}

number defaultcalibratedimageshiftx=8090
if(!getpersistentnumbernote("Faux Microscope:Calibrated Image Shift X", defaultcalibratedimageshiftx))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Image Shift X", defaultcalibratedimageshiftx)
	}
	
number defaultcalibratedimageshifty=8100
if(!getpersistentnumbernote("Faux Microscope:Calibrated Image Shift Y", defaultcalibratedimageshifty))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Image Shift Y", defaultcalibratedimageshifty)
	}

number defaultcalibratedmagnification=123456
if(!getpersistentnumbernote("Faux Microscope:Calibrated Magnification", defaultcalibratedmagnification))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Magnification", defaultcalibratedmagnification)
	}

number defaultcalibratedobjectivestigmationx=8110
if(!getpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation X", defaultcalibratedobjectivestigmationx))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation X", defaultcalibratedobjectivestigmationx)
	}
	
number defaultcalibratedobjectivestigmationy=8120
if(!getpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation Y", defaultcalibratedobjectivestigmationy))
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation Y", defaultcalibratedobjectivestigmationy)
	}

number defaultcameralength=47
if(!getpersistentnumbernote("Faux Microscope:Camera Length", defaultcameralength))
	{
		setpersistentnumbernote("Faux Microscope:Camera Length", defaultcameralength)
	}

number defaultcondensorstigmationx=8130
if(!getpersistentnumbernote("Faux Microscope:Condensor Stigmation X", defaultcondensorstigmationx))
	{
		setpersistentnumbernote("Faux Microscope:Condensor Stigmation X", defaultcondensorstigmationx)
	}

number defaultcondensorstigmationy=8140
if(!getpersistentnumbernote("Faux Microscope:Condensor Stigmation Y", defaultcondensorstigmationy))
	{
		setpersistentnumbernote("Faux Microscope:Condensor Stigmation Y", defaultcondensorstigmationy)
	}

number defaultfocus=8150
if(!getpersistentnumbernote("Faux Microscope:Focus", defaultfocus))
	{
		setpersistentnumbernote("Faux Microscope:Focus", defaultfocus)
	}
	
number defaulthightension=200000
if(!getpersistentnumbernote("Faux Microscope:High Tension", defaulthightension))
	{
		setpersistentnumbernote("Faux Microscope:High Tension", defaulthightension)
	}

string defaultilluminationmode="IMAGING"
if(!getpersistentstringnote("Faux Microscope:Illumination Mode", defaultilluminationmode))
	{
		setpersistentstringnote("Faux Microscope:Illumination Mode", defaultilluminationmode)
	}

number defaultimageshiftx=8160
if(!getpersistentnumbernote("Faux Microscope:Image Shift X", defaultimageshiftx))
	{
		setpersistentnumbernote("Faux Microscope:Image Shift X", defaultimageshiftx)
	}
	
number defaultimageshifty=8170
if(!getpersistentnumbernote("Faux Microscope:Image Shift Y", defaultimageshifty))
	{
		setpersistentnumbernote("Faux Microscope:Image Shift Y", defaultimageshifty)
	}

string defaultimagingopticsmode="PROBE"
if(!getpersistentstringnote("Faux Microscope:Imaging Optics Mode", defaultimagingopticsmode))
	{
		setpersistentstringnote("Faux Microscope:Imaging Optics Mode", defaultimagingopticsmode)
	}

number defaultmagnificationindex=17
if(!getpersistentnumbernote("Faux Microscope:Magnification Index", defaultmagnificationindex))
	{
		setpersistentnumbernote("Faux Microscope:Magnification Index", defaultmagnificationindex)
	}
	
number defaultmagnification=120000
if(!getpersistentnumbernote("Faux Microscope:Magnification", defaultmagnification))
	{
		setpersistentnumbernote("Faux Microscope:Magnification", defaultmagnification)
	}

string defaultmicroscopename="JEOL-ARM200F"
if(!getpersistentstringnote("Faux Microscope:Microscope Name", defaultmicroscopename))
	{
		setpersistentstringnote("Faux Microscope:Microscope Name", defaultmicroscopename)
	}

number defaultobjectivestigmationx=8180
if(!getpersistentnumbernote("Faux Microscope:Objective Stigmation X", defaultobjectivestigmationx))
	{
		setpersistentnumbernote("Faux Microscope:Objective Stigmation X", defaultobjectivestigmationx)
	}

number defaultobjectivestigmationy=8190
if(!getpersistentnumbernote("Faux Microscope:Objective Stigmation Y", defaultobjectivestigmationy))
	{
		setpersistentnumbernote("Faux Microscope:Objective Stigmation Y", defaultobjectivestigmationy)
	}

string defaultoperationmode="SCANNING"
if(!getpersistentstringnote("Faux Microscope:Operation Mode", defaultoperationmode))
	{
		setpersistentstringnote("Faux Microscope:Operation Mode", defaultoperationmode)
	}

number defaultscreenposition=1
if(!getpersistentnumbernote("Faux Microscope:Screen Position", defaultscreenposition))
	{
		setpersistentnumbernote("Faux Microscope:Screen Position", defaultscreenposition)
	}

number defaultspotsize=4
if(!getpersistentnumbernote("Faux Microscope:Spot Size", defaultspotsize))
	{
		setpersistentnumbernote("Faux Microscope:Spot Size", defaultspotsize)
	}

number defaultstagealpha=3.7
if(!getpersistentnumbernote("Faux Microscope:Stage Alpha", defaultstagealpha))
	{
		setpersistentnumbernote("Faux Microscope:Stage Alpha", defaultstagealpha)
	}

number defaultstagebeta=-4.2
if(!getpersistentnumbernote("Faux Microscope:Stage Beta", defaultstagebeta))
	{
		setpersistentnumbernote("Faux Microscope:Stage Beta", defaultstagebeta)
	}

number defaultstagepositionx=123
if(!getpersistentnumbernote("Faux Microscope:Stage Position X", defaultstagepositionx))
	{
		setpersistentnumbernote("Faux Microscope:Stage Position X", defaultstagepositionx)
	}

number defaultstagepositiony=-57
if(!getpersistentnumbernote("Faux Microscope:Stage Position Y", defaultstagepositiony))
	{
		setpersistentnumbernote("Faux Microscope:Stage Position Y", defaultstagepositiony)
	}

number defaultstagepositionz=39
if(!getpersistentnumbernote("Faux Microscope:Stage Position Z", defaultstagepositionz))
	{
		setpersistentnumbernote("Faux Microscope:Stage Position Z", defaultstagepositionz)
	}

number defaultmicroscopeisready=1
if(!getpersistentnumbernote("Faux Microscope:Microscope is Ready (0-1)", defaultmicroscopeisready))
	{
		setpersistentnumbernote("Faux Microscope:Microscope is Ready (0-1)", defaultmicroscopeisready)
	}

// Function Definitions

// Tests whether the microscope can return the camera length

number EMCanGetCameraLength( )
	{
		number cangetcamlen
		getpersistentnumbernote("Faux Microscope:Can Get Camera Length (0-1)", cangetcamlen)
		result("\n\nTesting EMCanGetCameraLength()\t: Can Get Camera Length Status = "+cangetcamlen)
		return cangetcamlen
	}


// Tests whether the microscope can return the HT value

number EMCanGetHighTension( )
	{
		number cangetht
		getpersistentnumbernote("Faux Microscope:Can Get High Tension (0-1)", cangetht)
		result("\n\nTesting EMCanGetHighTension() \t: Can Get High Tension = "+cangetht)
		return cangetht
	}


// Tests whether the microscope can return the current illumination mode

number EMCanGetIlluminationMode( )
	{
		number cangetillumnmode
		getpersistentnumbernote("Faux Microscope:Can Get Illumination Mode (0-1)", cangetillumnmode)
		result("\n\nTesting EMCanGetIlluminationmode() \t: Can Get Illumination Mode = "+cangetillumnmode)
		return cangetillumnmode
	}


// Tests whether the microscope can return the current optics mode

number EMCanGetImagingOpticsMode( )
	{
		number cangetopticsmode
		getpersistentnumbernote("Faux Microscope:Can Get Imaging Optics Mode (0-1)", cangetopticsmode)
		result("\n\nTesting EMCanGetImagingOpticsmode() \t: Can Get Imaging Optics Mode = "+cangetopticsmode)
		return cangetopticsmode
	}


// Tests whether the microscope can return the current magnification

number EMCanGetMagnification()
	{
		number cangetmagnification
		getpersistentnumbernote("Faux Microscope:Can Get Magnification (0-1)", cangetmagnification)
		result("\n\nTesting EMCanGetMagnification() \t: Can Get Magnification = "+cangetmagnification)
		return cangetmagnification
	}
	
	
// Changes the beam shift by the amount specified in x and y

void EMChangeBeamShift( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeBeamShift() called : Shift in x = "+xAmount+"  Shift in y = "+yAmount)
		return
	}

// Changes the beam tilt by the amount specified in x and y

void EMChangeBeamTilt( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeBeamTilt() called : Tilt in x = "+xAmount+"  Tilt in y = "+yAmount)
	}

// Changes the beam shift by the calibrated amounts supplied

void EMChangeCalibratedBeamShift( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeCalibratedBeamShift() called : Cal Shift in x = "+xAmount+"  Cal Shift in y = "+yAmount)
	}

// Changes the beam tilt by the calibrated amounts

void EMChangeCalibratedBeamTilt( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeCalibratedBeamTilt() called : Cal Tilt in x = "+xAmount+"  Cal Tilt in y = "+yAmount)
	}

// Changes the focus by the calibrated amount

void EMChangeCalibratedFocus( Number amount )
	{
		result("\n\nEMChangeCalibratedFocus() called : Cal Focus Changed by = "+Amount)
	}

// Change the focus - by an uncalibrated amount 

void EMChangeFocus( Number amount )
	{
		result("\n\nEMChangeFocus() called : Focus Changed by = "+Amount)
	}

// Change the image shift by a calibrated amount

void EMChangeCalibratedImageShift( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeCalibratedImageShift() called : Cal Image Shift in x = "+xAmount+"  Cal Image Shift in y = "+yAmount)
	}

// Change the Image Shift by an uncalibrated amount

void EMChangeImageShift( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeImageShift() called : Cal Image Shift in x = "+xAmount+"  Cal Image Shift in y = "+yAmount)
	}

// Change Calibrated Objective Stigmation

void EMChangeCalibratedObjectiveStigmation( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeCalibratedObjectiveStigmation() called : Cal Objective Stigmation in x = "+xAmount+"  Cal Objective Stigmation in y = "+yAmount)
	}

// Change the (uncalibrated) objective stigmation

void EMChangeObjectiveStigmation( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeObjectiveStigmation() called : Objective Stigmation in x = "+xAmount+"  Objective Stigmation in y = "+yAmount)
	}

// Change the Condensor Stigmation

void EMChangeCondensorStigmation( Number xAmount, Number yAmount )
	{
		result("\n\nEMChangeCondensorStigmation() called : Condensor Stigmation in x = "+xAmount+"  Condensor Stigmation in y = "+yAmount)
	}

// Get the current Beam Shift

void EMGetBeamShift( number &shiftX, number &shiftY )
	{
		getpersistentnumbernote("Faux Microscope:Beam Shift X", shiftx)
		getpersistentnumbernote("Faux Microscope:Beam Shift Y", shifty)
		result("\n\nEMGetBeamShift() called : Beam Shift in x = "+shiftx+"  Beam Shift in y = "+shifty)
		return
	}
	
// Get the current Beam Tilts

void EMGetBeamTilt( number &tiltX, Number &tiltY )
	{
		getpersistentnumbernote("Faux Microscope:Beam Tilt X", tiltX)
		getpersistentnumbernote("Faux Microscope:Beam Tilt Y", tiltY)
		result("\n\nEMGetBeamTilt() called: Beam Tilt in x = "+tiltX+"  Beam Tilt in y = "+tiltY)
		return
	}

// Get the current Brightness

Number EMGetBrightness( )
	{
		number brightness
		getpersistentnumbernote("Faux Microscope:Brightness", brightness)
		result("\n\nEMGetBrightness() called: Brightness = "+brightness)
		return brightness
	}

// Get the Calibrated Beam Shift

void EMGetCalibratedBeamShift( Number &calbeamshiftX, Number &calbeamshiftY )
	{
		getpersistentnumbernote("Faux Microscope:Calibrated Beam Shift X", calbeamshiftx)
		getpersistentnumbernote("Faux Microscope:Calibrated Beam Shift Y", calbeamshifty)
		result("\n\nEMGetCalibratedBeamShift() called : Cal Beam Shift in x = "+calbeamshiftx+"  Cal Beam Shift in y = "+calbeamshifty)
		return
	}

// Get the calibrated beam tilt

void EMGetCalibratedBeamTilt( number caltiltX, Number  caltiltY )
	{
		getpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt X", caltiltx)
		getpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt Y", caltilty)
		result("\n\nEMGetCalibratedBeamTilt() called : Cal Beam Tilt in x = "+caltiltx+"  Cal Beam Tilt in y = "+caltilty)
		return
	}

// Get the calibrated camera length

Number EMGetCalibratedCameraLength( String deviceLocation, TagGroup stateInfo, Number calCL, Number matchOptions )
	{
		devicelocation="Diffraction Camera"
		stateinfo=newtaggroup()
		getpersistentnumbernote("Faux Microscope:Calibrated Camera Length", calCL)
		matchoptions=0
		result("\n\nEMGetCalibratedCameraLength() called : Calibrated Camera Length = "+calCL)
		number unknownnumber =1
		return unknownnumber
	}

// Get the calibrated field of view for the selected camera location

Number EMGetCalibratedFieldOfView( String deviceLocation, TagGroup stateInfo, number calFOV, Number matchOptions )
	{
		devicelocation="Chosen Camera"
		taggroup stateinfo
		number calFOV
		getpersistentnumbernote("Faux Microscope:Calibrated Field of View", calFOV)
		number matchoptions=0
		result("\n\nEMGetCalibratedFieldofView() called : Calibrated Field of View = "+calFOV)
		number unknownnumber=1
		return unknownnumber
	}

// Gets the current calibrated focus value

Number EMGetCalibratedFocus( )
	{
		number calfocus
		getpersistentnumbernote("Faux Microscope:Calibrated Focus", calfocus)
		result("\n\nEMGetCalibratedFocus() called : Calibrated Focus = "+calfocus)
		return calfocus
	}

// Gets the current calibrated image shifts

void EMGetCalibratedImageShift( Number &calimgshiftX, Number &calimgshiftY )
	{
		getpersistentnumbernote("Faux Microscope:Calibrated Image Shift X", calimgshiftx)
		getpersistentnumbernote("Faux Microscope:Calibrated Image Shift Y", calimgshifty)
		result("\n\nEMGetCalibratedImageShift() called : Calibrated Image Shift x = "+calimgshiftx+"  Calibrated Image Shift Y = "+calimgshifty)
		return
	}


// Gets the current calibrated magnification

Number EMGetCalibratedMag( String deviceLocation, TagGroup stateInfo, Number &calMag, Number matchOptions )
	{

		devicelocation="Chosen Camera"
		taggroup stateinfo
		number calMag
		getpersistentnumbernote("Faux Microscope:Calibrated Magnification", calMag)
		number matchoptions=0
		result("\n\nEMGetCalibratedMagnification() called : Calibrated Magnification = "+calmag)
		number unknownnumber=1
		return unknownnumber
	}

// Gets the current calibrated objective stigmation x and y values

void EMGetCalibratedObjectiveStigmation( Number &calobjstigX, Number & calobjstigY )
	{
		getpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation X", calobjstigx)
		getpersistentnumbernote("Faux Microscope:Calibrated Objective Stigmation Y", calobjstigy)
		result("\n\nEMGetCalibratedObjectiveStigmation() called : Calibrated Objective Stigmation X = "+calobjstigx+ "  Calibrated Objective Stigmation Y = "+calobjstigy)
		return
	}

// Gets the taggroup which (presumably) reports on the state of calibrations - (presumably) which are, and which are not, present.

TagGroup EMGetCalibrationStateTags( )
	{
		taggroup caltags=newtaggroup()
		result("\n\nEMGetCalibrationStateTags() called : Taggroup returned.")
		return caltags
	}

// Gets the current camera length

Number EMGetCameraLength( )
	{
		number cameralength
		getpersistentnumbernote("Faux Microscope:Camera Length", cameralength)
		result("\n\nEMGetCamerLength() called : Camera Length = "+cameralength)
		return cameralength
	}

// get the current condensor stigmator values

void EMGetCondensorStigmation( number &condstigx, number &condstigy )
	{
		getpersistentnumbernote("Faux Microscope:Condensor Stigmation X", condstigx)
		getpersistentnumbernote("Faux Microscope:Condensor Stigmation Y", condstigy)
		result("\n\nEMGetCondensorStigmation() called : Condensor Stigmation X = "+condstigx+"  Condensor Stigmation Y = "+condstigy)
		return
	}

// Gets the current focus

number EMGetFocus()
	{
		number focus
		getpersistentnumbernote("Faux Microscope:Focus", focus)
		result("\n\nEMGetFocus() called : Focus = "+focus)
		return focus
	}

// Gets the current high tension value

Number EMGetHighTension( )
	{
		number hightension
		getpersistentnumbernote("Faux Microscope:High Tension", hightension)
		result("\n\nEMGetHighTension() called : High Tension = "+hightension)
		return hightension
	}

// Gets the current illumination mode as a string

String EMGetIlluminationMode( )
	{
		string illuminationmode
		getpersistentstringnote("Faux Microscope:Illumination Mode", illuminationmode)
		result("\n\nEMGetIlluminationMode() called : Illumination Mode = "+illuminationmode)
		return illuminationmode
	}

// Gets a taggroup which contains the various illuminatin modes available

TagGroup EMGetIlluminationModes( )
	{
		taggroup illummodetags=newtaggroup()
		result("\n\nEMGetIlluminationModes() called : Illumination Modes taggroup returned")
		return illummodetags
	}

// Gets the current image shift x and y values

void EMGetImageShift( number &getimageshiftx, number &getimageshifty )
	{
		getpersistentnumbernote("Faux Microscope:Image Shift X", getimageshiftx)
		getpersistentnumbernote("Faux Microscope:Image Shift Y", getimageshifty)
		result("\n\nEMGetImageShift() called : Image Shift x = "+getimageshiftx+"  Image Shift y = "+getimageshifty)
		return
	}

// Get the imaging optics mode

String EMGetImagingOpticsMode( )
	{
		string imagingopticsmode
		getpersistentstringnote("Faux Microscope:Imaging Optics Mode", imagingopticsmode)
		result("\n\nEMGetImagingOpticsMode() called : Imaging Optics Mode = "+imagingopticsmode)
		return imagingopticsmode
	}

// Get the available imaging optics modes as a taggroup()

TagGroup EMGetImagingOpticsModes( )
	{
		taggroup imagingmodes=newtaggroup()
		result("\n\nEMGetImagingOpticsModes() called : Optics Modes Taggroup returned.")
		return imagingmodes
	}

// Gets the index of the current magnification 

Number EMGetMagIndex( )
	{
		number magindex
		getpersistentnumbernote("Faux Microscope:Magnification Index", magindex)
		result("\n\nEMGetMagIndex() called : Magnification Index = "+magindex)
		return magindex
	}

// Gets the current magnification

Number EMGetMagnification( )
	{
		number magnification
		getpersistentnumbernote("Faux Microscope:Magnification", magnification)
		result("\n\nEMGetMagIndex() called : Magnification = "+magnification)
		return magnification
	}

// Gets the microscope name

String EMGetMicroscopeName( )
	{
		string microscopename
		getpersistentstringnote("Faux Microscope:Microscope Name", microscopename)
		result("\n\nEMGetMicroscopeName() called : Microscope Name = "+microscopename)
		return microscopename
	}

// Gets the current objective stigmation

void EMGetObjectiveStigmation( Number &getstigx, Number &getstigy )
	{
		getpersistentnumbernote("Faux Microscope:Objective Stigmation X", getstigx)
		getpersistentnumbernote("Faux Microscope:Objective Stigmation Y", getstigy)
		result("\n\nEMGetObjectiveStigmation() called : Objective Stig x = "+getstigx+" Objective Stig y = "+getstigy)
		return
	}

// Gets the current microscope operation mode

String EMGetOperationMode( )
	{
		string operationmode
		getpersistentstringnote("Faux Microscope:Operation Mode", operationmode)
		result("\n\nEMGetOperationMode() called : Operation Mode = "+operationmode)
		return operationmode
	}

// Gets the fluorescent screen position as an index

Number EMGetScreenPosition( )
	{
		number screenposition
		getpersistentnumbernote("Faux Microscope:Screen Position", screenposition)
		result("\n\nEMGetScreenPosition() called : Screen Position = "+screenposition)
		return screenposition
	}
	
// Gets the current spot size

Number EMGetSpotSize( )
	{
		number spotsize
		getpersistentnumbernote("Faux Microscope:Spot Size", spotsize)
		result("\n\nEMGetSpotSize() called : Spot Size = "+spotsize)
		return spotsize
	}

// Gets the current stage alpha (x) tilt

Number EMGetStageAlpha( )
	{
		number stagealpha
		getpersistentnumbernote("Faux Microscope:Stage Alpha", stagealpha)
		result("\n\nEMGetStageAlpha() called : Stage Alpha = "+stagealpha)
		return stagealpha
	}

// Gets the current stage beta (y) tilt

Number EMGetStageBeta( )
	{
		number stagebeta
		getpersistentnumbernote("Faux Microscope:Stage Beta", stagebeta)
		result("\n\nEMGetStageBeta() called : Stage Beta = "+stagebeta)
		return stagebeta
	}

// Reads the current stage positions. The values read are selected by an axisflags parameter
// which can be any integer between 0 and 31 - see function for details


void EMGetStagePositions( Number axisFlags, number &stagepositionx, number &stagepositiony, number &stagepositionz, Number &stagealpha, number &stagebeta )
	{
		getpersistentnumbernote("Faux Microscope:Stage Alpha", stagealpha)
		getpersistentnumbernote("Faux Microscope:Stage Beta", stagebeta)
		getpersistentnumbernote("Faux Microscope:Stage Position X", stagepositionx)
		getpersistentnumbernote("Faux Microscope:Stage Position Y", stagepositiony)
		getpersistentnumbernote("Faux Microscope:Stage Position Z", stagepositionz)
		
		Result("\n\nEMGetStagePositions() called :\n")
		
		
		// Axis flags treat the passed in decimal as it binary encoded value to select
		// which parameters are read in the the order x, y, z, alpha, beta : 1, 2, 4, 8, 16
		// Selecting the decimal value of 11 (1 + 2 + 8) binary 11010 reads only x, y and alpha
		
		if(axisflags<0) axisflags=0
		if(axisflags>31) axisflags=31
		
		string axisflagsasbinary=binary(axisflags)
		number binlength=len(axisflagsasbinary)
		
		number i
		
		
		// Loop to read the binary digits of axisflags and output the relevant data
		
		for(i=0; i<binlength; i++)
			{
				string thischar=mid(axisflagsasbinary, binlength-1-i, 1)
				if(thischar=="1")
					{
						if(i==0) result("\nStage Position X = "+stagepositionx)
						if(i==1) result("\nStage Position Y = "+stagepositiony)
						if(i==2) result("\nStage Position Z = "+stagepositionz)

						if(i==3) result("\nStage Alpha = "+stagealpha)
						if(i==4) result("\nStage Beta = "+stagebeta)
					}
			}
	}
	

// Gets the current stage x and y positions
	
void EMGetStageXY( Number &stagexposition, Number &stageyposition )
	{
		getpersistentnumbernote("Faux Microscope:Stage Position X", stagexposition)
		getpersistentnumbernote("Faux Microscope:Stage Position Y", stageyposition)
		result("\n\nEMGetStageXY() called : Stage X Position = "+stagexposition+"  Stage Y Position = "+stageyposition)
	}
	
	
// Gets the current stage x position
	
Number EMGetStageX( )
	{
		number stagexposition
		getpersistentnumbernote("Faux Microscope:Stage Position X", stagexposition)
		result("\n\nEMGetStageX() called : Stage X Position = "+stagexposition)
		return stagexposition
	}

// Gets the current stage y position
	
Number EMGetStageY( )
	{
		number stageyposition
		getpersistentnumbernote("Faux Microscope:Stage Position Y", stageyposition)
		result("\n\nEMGetStageY() called : Stage Y Position = "+stageyposition)
		return stageyposition
	}

// Gets the current stage z position
	
Number EMGetStageZ( )
	{
		number stagezposition
		getpersistentnumbernote("Faux Microscope:Stage Position Z", stagezposition)
		result("\n\nEMGetStageZ() called : Stage Z Position = "+stagezposition)
		return stagezposition
	}
	
// Returns a boolean indicating if the microscope is ready

number EMIsReady( )
	{
		number microscopeisready
		getpersistentnumbernote("Faux Microscope:Microscope is Ready (0-1)", microscopeisready)
		result("\n\nEMIsReady() called : Microscope is Ready = "+microscopeisready)
		return microscopeisready
	}


// Note the EMSet . . () commands can be used to change the values saved in the Global Info. So if you want
// particular values when testing a script, you can set them with the relevant shift command, or you can
// edit the tags directly: File/Global Info/Global Tags/Faux Microscope


// Sets the beam shift to the values specified

void EMSetBeamShift( Number beamshiftX, Number beamshiftY )
	{
		setpersistentnumbernote("Faux Microscope:Beam Shift X", beamshiftX)
		setpersistentnumbernote("Faux Microscope:Beam Shift Y", beamshiftY)
		result("\n\nEMSetBeamShift() called : Setting Beam Shift x = "+beamshiftX+"  Beam Shift y = "+beamshiftY)
		return
	}

// Sets the beam tilts to the values specified

void EMSetBeamTilt( Number beamtiltX, Number beamtiltY )
	{
		setpersistentnumbernote("Faux Microscope:Beam Tilt X", beamtiltx)
		setpersistentnumbernote("Faux Microscope:Beam Tilt Y", beamtilty)
		result("\n\nEMSetBeamTilt() called : Setting Beam Tilt x = "+beamtiltX+"  Beam Tilt y = "+beamtiltY)
		return
	}
	
// Sets the brightness to the value specified

void EMSetBrightness( Number brightness )
	{
		setpersistentnumbernote("Faux Microscope:Brightness", brightness)
		result("\n\nEMSetBrightness() called : Setting Brightness = "+brightness)
		return
	}
	
// Sets the calibrated beam shift to the values specified

void EMSetCalibratedBeamShift( Number calbeamshiftX, Number calbeamshiftY )
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Shift X", calbeamshiftx)
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Shift Y", calbeamshifty)
		result("\n\nEMSetCalibratedBeamShift() called : Setting Cal Beam Shift x = "+calbeamshiftx+"  Cal Beam Shift y = "+calbeamshifty)
		return
	}

// Sets the calibrated beam tilts to the values specified
	
void EMSetCalibratedBeamTilt( number  setcaltiltX, number setcaltiltY )
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt X", setcaltiltX)
		setpersistentnumbernote("Faux Microscope:Calibrated Beam Tilt Y", setcaltiltY)
		result("\n\nEMSetCalibratedBeamTilt() called : Setting Cal Beam Tilt x = "+setcaltiltX+"  Cal Beam Tilt y = "+setcaltiltY)
		return
	}

// Sets the calibrated focus to the value specified

void EMSetCalibratedFocus( Number setcalfocus )
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Focus", setcalfocus)
		result("\n\nEMSetCalibratedFocus() called : Setting Cal Focus = "+setcalfocus)
		return
	}

// Sets the calibrated image shift to the values specified

void EMSetCalibratedImageShift( Number setcalimageshiftX, Number setcalimageshiftY)
	{
		setpersistentnumbernote("Faux Microscope:Calibrated Image Shift X", setcalimageshiftX)
		setpersistentnumbernote("Faux Microscope:Calibrated Image Shift Y", setcalimageshiftY)
		result("\n\nEMSetCalibratedImageShift() called : Setting Cal Image Shift x = "+setcalimageshiftX+"  Cal Image Shift y = "+setcalimageshiftY)
		return
	}


// Sets the calibrated objective stigmation to the values specified

void EMSetCalibratedObjectiveStigmation( Number setcalobjstigX, Number setcalobjstigY )
	{
		setpersistentnumbernote("Faux Microscope:Objective Stigmation X", setcalobjstigX)
		setpersistentnumbernote("Faux Microscope:Objective Stigmation Y", setcalobjstigY)
		result("\n\nEMSetCalibratedObjectiveStigmation() called : Setting Cal Objective Stig x = "+setcalobjstigX+"  Cal Objective Stig y = "+setcalobjstigY)
		return
	}

// Sets the condensor stigmation values to the those specified

void EMSetCondensorStigmation( Number setcondstigX, Number setcondstigY )
	{
		setpersistentnumbernote("Faux Microscope:Condensor Stigmation X", setcondstigX)
		setpersistentnumbernote("Faux Microscope:Condensor Stigmation Y", setcondstigY)
		result("\n\nEMSetCondensorStigmation() called : Setting Condensor Stig x = "+setcondstigX+"  Condensor Stig y = "+setcondstigY)
		return
	}

// Sets the focus to the value specified - note it is not clear from the documentation what value this
// function returns. I have presumed boolean - if successful - you will need to check the behaviour.

Number EMSetFocus( Number setfocus )
	{
		setpersistentnumbernote("Faux Microscope:Focus", setfocus)
		result("\n\nEMSetFocus() called : Setting Focus = "+setfocus)
		return 1
	}

// Sets the image shift to the values specified

void EMSetImageShift( Number setimageshiftX, Number setimageshiftY )
	{
		setpersistentnumbernote("Faux Microscope:Image Shift X", setimageshiftx)
		setpersistentnumbernote("Faux Microscope:Image Shift Y", setimageshifty)
		result("\n\nEMSetImageShift() called : Setting Image Shift x = "+setimageshiftx+"  Setting Image Shift y = "+setimageshifty)
	}
	
// Sets the magnification index - each magnification has a numberical value eg 1- 40

void EMSetMagIndex( Number setmagindex )
	{
		setpersistentnumbernote("Faux Microscope:Magnification Index", setmagindex)
		result("\n\nEMSetMagIndex() called : Setting Mag Index = "+setmagindex)
		return
	}

// Sets the objective stigmation value

void EMSetObjectiveStigmation( Number setobjstigX, Number setobjstigY )
	{
		setpersistentnumbernote("Faux Microscope:Objective Stigmation X", setobjstigX)
		setpersistentnumbernote("Faux Microscope:Objective Stigmation Y", setobjstigY)
		result("\n\nEMSetObjectiveStigmation() called : Setting Objective Stig x = "+setobjstigX+"  Setting Objective Stig y = "+setobjstigY)
		return
	}

// Sets the screen position

void EMSetScreenPosition( Number setscreenpos )
	{
		setpersistentnumbernote("Faux Microscope:Screen Position", setscreenpos)
		result("\n\nEMSetScreenPosition() called : Setting Screen to = "+setscreenpos)
		return
	}

// Sets the spot size to the values specified

void EMSetSpotSize( Number spotSize )
	{
		setpersistentnumbernote("Faux Microscope:Spot Size", spotsize)
		result("\n\nEMSetSpotSize() called : Setting Spot Size to = "+spotsize)
		return
	}

// Sets the stage alpha (x tilt) to the value specified

void EMSetStageAlpha( Number setstagealpha )
	{
		setpersistentnumbernote("Faux Microscope:Stage Alpha", setstagealpha)
		result("\n\nEMSetStageAlpha() called : Setting Stage Alpha to = "+setstagealpha)
		return
	}


// Sets the stage beta (y tilt) to the value specified

void EMSetStageBeta( Number setstagebeta )
	{
		setpersistentnumbernote("Faux Microscope:Stage Beta", setstagebeta)
		result("\n\nEMSetStageBeta() called : Setting Stage Beta to = "+setstageBeta)
		return
	}

// Sets the current stage positions. The values read are selected by an axisflags parameter
// which can be any integer between 0 and 31 - see function for details


void EMSetStagePositions( Number axisFlags, number stagepositionx, number stagepositiony, number stagepositionz, Number stagealpha, number stagebeta )
	{
	
		Result("\n\nEMSetStagePositions() called :\n")
		
		
		// Axis flags treat the passed in decimal as it binary encoded value to select
		// which parameters are read in the the order x, y, z, alpha, beta : 1, 2, 4, 8, 16
		// Selecting the decimal value of 11 (1 + 2 + 8) binary 11010 reads only x, y and alpha
		
		if(axisflags<0) axisflags=0
		if(axisflags>31) axisflags=31
		
		string axisflagsasbinary=binary(axisflags)
		number binlength=len(axisflagsasbinary)
		
		number i
		
		
		// Loop to read the binary digits of axisflags and output the relevant data
		
		for(i=0; i<binlength; i++)
			{
				string thischar=mid(axisflagsasbinary, binlength-1-i, 1)
				if(thischar=="1")
					{
						if(i==0) // stage x
							{
								setpersistentnumbernote("Faux Microscope:Stage Position X", stagepositionx)
								result("\nStage Position X set to = "+stagepositionx)
							}
						if(i==1) // stage y
							{
								setpersistentnumbernote("Faux Microscope:Stage Position Y", stagepositiony)
								result("\nStage Position Y set to = "+stagepositiony)
							}
						if(i==2) // stage z
							{
								setpersistentnumbernote("Faux Microscope:Stage Position Z", stagepositionz)
								result("\nStage Position Z set to = "+stagepositionz)
							}
						if(i==3) // stage alpha (x tilt)
							{
								setpersistentnumbernote("Faux Microscope:Stage Alpha", stagealpha)
								result("\nStage Alpha set to = "+stagealpha)
							}
						if(i==4) // stage beta (y tilt)
							{
								setpersistentnumbernote("Faux Microscope:Stage Beta", stagebeta)
								result("\nStage Beta set to= "+stagebeta)
							}
					}
			}
	}

// Sets the stage x and y values to those specified

void EMSetStageXY( Number bisetstagex, Number bisetstagey )
	{
		setpersistentnumbernote("Faux Microscope:Stage Position X", bisetstagex)
		setpersistentnumbernote("Faux Microscope:Stage Position Y", bisetstagey)
		result("\n\nEMSetStageXY() called : Setting Stage x = "+bisetstagex+"  Setting Stage y = "+bisetstagey)
		return
	}

// Sets the stage x position to the value specified

void EMSetStageX( Number monosetstagex )
	{
		setpersistentnumbernote("Faux Microscope:Stage Position X", monosetstagex)
		result("\n\nEMSetStageX() called : Setting Stage x = "+monosetstagex)
		return
	}

// Sets the stage y position to the value specified

void EMSetStageY( Number monosetstagey )
	{
		setpersistentnumbernote("Faux Microscope:Stage Position Y", monosetstagey)
		result("\n\nEMSetStageY() called : Setting Stage y = "+monosetstagey)
		return
	}

// Sets the stage z position to the value specified

void EMSetStageZ( Number monosetstagez )
	{
		setpersistentnumbernote("Faux Microscope:Stage Position Z", monosetstagez)
		result("\n\nEMSetStageZ() called : Setting Stage z = "+monosetstagez)
		return
	}

// Updates the calibration state - does nothing here

void EMUpdateCalibrationState( )
	{
		result("\n\nEMUpdateCalibrationState() called : Does nothing here.")
		return
	}

// Waits until the microscope is ready

void EMWaitUntilReady( )
	{
		result("\n\nEMWaitUntilReady() called : I am waiting.")
		delay(120) // 1s delay for fun
		result("\nMicroscope is ready.\n")
		return
	}







// Test of functions

result("\n\nTesting Faux Library Functions:")

number mag=emcangetmagnification()
number getcamlen=EMCanGetCameraLength()
number getht= EMCanGetHighTension()
number getillum=EMCanGetIlluminationMode()

number getoptics=EMCanGetImagingOpticsMode()

number xshift=25, yshift=35
EMChangeBeamShift( xshift, yshift)

number xtilt=30, ytilt=40
EMChangeBeamTilt( xtilt, ytilt )

number calbeamshiftx=35, calbeamshifty=45
EMChangeCalibratedBeamShift( calbeamshiftx, calbeamshifty )

number calbeamtilt=40, calbeamshift=50
EMChangeCalibratedBeamTilt( calbeamshiftx, calbeamshifty )

number changecalfocus=45
EMChangeCalibratedFocus(changecalfocus)

number focus=47
EMChangeFocus( focus )

number calimgshiftx=50, calimgshifty=60
EMChangeCalibratedImageShift(calimgshiftx, calimgshifty)

number imgshiftx=53, imgshifty=63
EMChangeImageShift(imgshiftx, imgshifty)

number calobjstigx=55, calobjstigy=65
EMChangeCalibratedObjectiveStigmation(calobjstigx, calobjstigy)

number objstigx=57, objstigy=67
EMChangeObjectiveStigmation(objstigx, objstigy)

number condstigx = 60, condstigy=70
EMChangeCondensorStigmation( condstigx, condstigy )

number beamshiftx, beamshifty
EMGetBeamShift(beamshiftx, beamshifty)

number beamtiltx, beamtilty
EMGetBeamTilt( beamtiltx, beamtilty )

number brightness
brightness=EMGetBrightness( )

number getcalbeamshiftx, getcalbeamshifty
EMGetCalibratedBeamShift( getcalbeamshiftX, getcalbeamshiftY )

number getcalbeamtiltx, getcalbeamtilty
EMGetCalibratedBeamTilt( getcalbeamtiltx, getcalbeamtilty)

string devicelocation
taggroup stateinfo
number calcameralength
number matchoptions
number unknownnumber
unknownnumber= EMGetCalibratedCameraLength(deviceLocation, stateInfo, calcameralength, matchOptions )

number calFOV
unknownnumber=EMGetCalibratedFieldOfView(deviceLocation, stateInfo, calFOV, matchOptions )

number calfocus=EMGetCalibratedFocus( )

number getcalimgshiftx, getcalimgshifty
EMGetCalibratedImageShift( getcalimgshiftX, getcalimgshiftY )

number calMag
unknownnumber=EMGetCalibratedMag(deviceLocation, stateInfo, calMag, matchOptions )

number getcalobjstigx, getcalobjstigy
EMGetCalibratedObjectiveStigmation( getcalobjstigx, getcalobjstigy )

taggroup calstatetags=EMGetCalibrationStateTags( )

number cameralength=EMGetCameraLength( )

number getcondstigx, getcondstigy
EMGetCondensorStigmation( getcondstigx, getcondstigy )

number getfocus=EMGetFocus()

number hightension=EMGetHighTension()

string illuminationmode=EMGetIlluminationMode()

taggroup illummodestaggroup=EMGetIlluminationModes( )

number getimageshiftx, getimageshifty
EMGetImageShift(getimageshiftx, getimageshifty )

string getimagingopticsmode=EMGetImagingOpticsMode( )

TagGroup imagingopticsmodes=EMGetImagingOpticsModes( )

number getmagindex=EMGetMagIndex()

number magnification=EMGetMagnification()

string microscopename=EMGetMicroscopeName()

number getobjstigx, getobjstigy
EMGetObjectiveStigmation( getobjstigx, getobjstigy )

string operationmode=EMGetOperationMode()

number screenposition=EMGetScreenPosition()

number spotsize=EMGetSpotSize()

number stagealpha=EMGetStageAlpha()

number stagebeta=EMGetStageBeta()

number axisflags=31 // this value reads all the stage parameters
number getstagexpos, getstageypos, getstagezpos
EMGetStagePositions(axisflags, getstagexpos, getstageypos, getstagezpos, stagealpha, stagebeta)

number getstagexposition, getstageyposition
EMGetStageXY(getstagexposition, getstageyposition)

getstagexposition=EMGetStagex()

getstageyposition=EMGetStagey()

getstageyposition=EMGetStagez()

number microscopeisready=EMIsReady()

number setbeamshiftx=7000, setbeamshifty=7010
EMSetBeamShift(setbeamshiftx, setbeamshifty)

number setbeamtiltx=7020, setbeamtilty=7030
EMSetBeamTilt(setbeamtiltx, setbeamtilty)

number setbrightness=7040
EMSetBrightness(setbrightness)

number setcalbeamshiftx=7050, setcalbeamshifty=7060
EMSetCalibratedBeamShift(setcalbeamshiftX, setcalbeamshiftY )

number setcalbeamtiltx=7070, setcalbeamtilty=7080
EMSetCalibratedBeamTilt(setcalbeamtiltX, setcalbeamtiltY )

number setcalfocus=7090
EMSetCalibratedFocus(setcalfocus)

number setcalimageshiftx=7100, setcalimageshifty=7110
EMSetCalibratedImageShift( setcalimageshiftx, setcalimageshifty)

number setcalobjstigx=7120, setcalobjstigy=7130
EMSetCalibratedObjectiveStigmation(setcalobjstigx, setcalobjstigy )

number setcondstigx=7140, setcondstigy=7150
EMSetCondensorStigmation(setcondstigx, setcondstigy )

number setfocus=7160
EMSetFocus(setfocus)

number setimageshiftx=7170, setimageshifty=7180
EMSetImageShift( setimageshiftX, setimageshiftY )

number setmagindex=15
EMSetMagIndex(setmagindex)

number setobjstigx=7190, setobjstigy=7200
EMSetObjectiveStigmation( setobjstigX, setobjstigY )

number setscreenpos=2
EMSetScreenPosition(setscreenpos)

number setspotsize=2
EMSetSpotSize(setspotsize)

number setstagealpha=11.9
EMSetStageAlpha(setstagealpha)

number setstagebeta=2.3
EMSetStageBeta(setstagebeta)

number setstagexpos=123, setstageypos=407, setstagezpos=-23, allsetstagealpha=13.1, allsetstagebeta=7.2
number setaxisflags=31 // set all the parameters
EMSetStagePositions( axisFlags, setstagexpos, setstageypos, setstagezpos, allsetstagealpha, allsetstagebeta )

number bisetstagex=135, bisetstagey=427
EMSetStageXY( bisetstagex, bisetstagey )

number monosetstagex=143
EMSetStageX(monosetstagex)

number monosetstagey=447
EMSetStageY(monosetstagey)

number monosetstagez=73
EMSetStageZ(monosetstagez)

EMUpdateCalibrationState( ) // this function does nothing here

EMWaitUntilReady() // waits until the microscope is ready - a 2s delay is added here for effect.


result("\n\nThe numerical and string values returned by these library functions are arbitrary. Do not assume that")
result("\nthe values returned by your system will be similar to these. eg is your high tension")
result("\nvalue returned in volts or kV? If, during development, your script needs a")
result("\nparticular value to run, you should check the typical values which the particular EM. . ()")
result("\nfunction returns at YOUR microscope. Then edit the default values of this library")
result("\nso that they match what your script will see in practice. Library default values")
Result("\ncan be edited at : File/Global Info/Global Tags/Faux Microscope.")
result("\nAny taggroups returned by these library functions are empty.")
result("\n\nTypically, the main role of the library is to permit you to incorporate the relevant script commands")
result("\ninto your code without encountering errrors. Temporary lines of code can be inserted in the script which set")
result("\nvalues to those required. These temporary lines of code are then removed when the script is")
result("\nmoved to the microscope for final polishing.")
