Async Scan Example

PowerScript

The example code performs the following operations: During the image scan, it adjusts the Tip Bias and Sample Bias according to the specified time delay. During the image scan, it reads and outputs the values of the channels registered in the channels list.

main 0 files
Async Scan Example..js
Async Scan Example..js 2855 bytes
var $AsyncScan = {
	
	"parameters" : {
		"channels"  : ["ZHeight", "TipBias", {"name":"SetPoint", "unit":"volt"}],
		"timeDelay" : 500, 			// unit: ms
		"initTipBias" : 0.0,  		// unit: V
		"initSetPoint" : 1.0, 		// unit: V
		"finiTipBias" : 1.0, 		// unit: V
		"finiSetPoint" : 2.0, 		// unit: V
		"xyScannerSize" : [0, 0],
		"xyScannerOffset" : [0, 0]
	},

	"addChannels" : function (chArray){
		for (var i in chArray){
			print('Add Ch: ' + chArray[i])
			spm.scan.channels.add(chArray[i])	
		}
		spm.scan.triggerLineScan()
		spm.sleep(50)
		spm.scan.stop()
		spm.sleep(50)
		spm.scan.stop()
		
	},

	"clearChannels" : function (){
		var chs = spm.scan.channels.names() 
		for (var i=0; i < chs.length; i++){
            		print('Remove Ch: '+chs[i])
            		spm.scan.channels.remove(chs[i])
            	}
	},
	
	"CalStep" : function (init, fini, TotalTime) {
		// Total Time unit: sec
		var stepCount = TotalTime*1000 / this.parameters.timeDelay 
		return (fini - init) / stepCount
	},
	
	"update" : function (aTipBias, aSetPoint) {
		spm.bias.tip = aTipBias;
		spm.zservo.setpoint.normValue = aSetPoint;
		print("Set Params. >> Bias (V): " + aTipBias + ", SetPoint (V): " + aSetPoint)
	},
	
	"init": function () {
		app.setPrintOutputVisible(false)
		this.clearChannels();
		this.addChannels(this.parameters.channels);
		var xySize =this.parameters.xyScannerSize;
		var xyOffset = this.parameters.xyScannerOffset;
		spm.xyscanner.moveTo(-1 * xySize[0]/2 + xyOffset[0], -1 * xySize[1]/2 + xyOffset[1])
		spm.sleep(2000)
	},

	"fini": function () {
		this.update(this.parameters.initTipBias, this.parameters.initSetPoint)
	},
	
	"run" : function (estimateTime){
		this.init();
		var tipBias = this.parameters.initTipBias;
		var setPoint = this.parameters.initSetPoint;
		print("Estimate Time: " + estimateTime + " sec");
		var stepTipBias = this.CalStep(tipBias, this.parameters.finiTipBias, estimateTime);
		var stepSetPoint = this.CalStep(setPoint, this.parameters.finiSetPoint, estimateTime);		
		print("Tip Bias Step: " + stepTipBias);
		print("SetPoint Step: " + stepSetPoint);

		this.update(tipBias, setPoint);
		spm.scan.triggerImageScan();
		spm.sleep(60);
		while (spm.scan.isImageScanning){
			tipBias += stepTipBias;
			setPoint += stepSetPoint;
			this.update(tipBias, setPoint);
			spm.sleep(this.parameters.timeDelay);
		}
		this.fini()
		print("Done Image Scan")
	}
};


var slowScanLineNum = 1 ;
var eachEndOverScanPercent = 0;
$AsyncScan.parameters.xyScannerSize = [5, 0];
$AsyncScan.parameters.xyScannerOffset = [0, 0];
$AsyncScan.parameters.timeDelay = 500;
eachEndOverScanPercent *= 0.04;
eachEndOverScanPercent += 1;
var estimateTime = slowScanLineNum / (spm.scan.rate * eachEndOverScanPercent);


$AsyncScan.run(estimateTime);
Comments (0)

No comments yet. Be the first to comment!

Snippet Information
Author: jungyu.lee
Language: PowerScript
Created: Feb 23, 2026
Updated: 0 minutes ago
Views: 10
Stars: 0