Events available for this action

<< Click to Display Table of Contents >>

Manual > Server Creation Guide > Action Edition > Action Reference > Script Ver2 (SC2) >

Events available for this action

Events that can be used in Script Ver2 actions

In Script Ver. 2, you can use events listed in "Common Methods" in the Control Reference that have a "○" in the script action column.

 

The following are the events available in script version 2.

 

Event name

explanation

OnInitialize

This occurs only once when a script is executed. You can write the initialization process of the script.

 

OnHeartBeat

FA-ServerCalled whenever an action is performed due to an event.

 

OnTagValueChanged

This occurs every time the value of a tag registered with the AddTag method changes.

 

OnTerminate

This occurs only once at the end of the script. You can write the script termination process, etc.

 

OnTimer

This occurs when the timer set by calling the SetTimer method times out. It is used when you want to repeatedly evaluate a condition at a certain timing, or when you want to perform a specific process after a specified timer period has elapsed.

OnExpressionValueChanged

This occurs when the value of an arithmetic expression registered with the AddExpression method changes.

 

 

By using the above events, you can implement various processes in your script.

 

 

For example, you can write the following process:

 

Monitor tag changes (OnTagValueChanged event)

 

It monitors changes in the value of the tag registered by the AddTag method. When the value changes, the OnTagValueChanged event occurs.

 

Example script

event OnInitialize()
{
	::AddTag(c("U01.F01.T01", "U01.F01.T02", "U01.F01.T03"));
}

event OnTagValueChanged(tagname,value)
{
	if(value){
		if(tagname == "U01.F01.T01"){
			::WriteVal("U01.F01.T03", 1);
		}else if(tagname == "U01.F01.T02"){
			::WriteVal("U01.F01.T03", 0);
		}
	}                                                 
}

 

Performs 5-second timer processing (OnTimer event)

 

A timer is registered using the SetTimer method. When the timer condition is met, the OnTimer event occurs.

 

Example script

event OnInitialize()
{
	::SetTimer(0, 5000, -1);
}

event OnTimer(timerid,counter)
{
	::SvsDump("OnTimer Id:" & ::CStr(timerid) & " counter:" & ::CStr(counter));
}

 

Specify a condition in an arithmetic expression and monitor whether the condition is met (OnExpressionValueChanged event)

 

Use the AddExpression method to register a condition expression. When the condition expression is met, the OnExpressionValueChanged event occurs.

 

Example script

event OnInitialize()
{
	var vExpressionName = c("EX01","EX02");
	var vExpression = c("(U01.F01.T04 && U01.F01.T05) ||
                              U01.F01.T06" ,"U01.F01.T04 || U01.F01.T05 || U01.F01.T06");
	::AddExpression(vExpressionName, vExpression);
}

event OnExpressionValueChanged(name,value,firstevent)
{
	::SvsDump("OnExpressionValueChanged(Name:" & ::CStr(name) & 
             " Value:" & ::CStr(value) & " First:" & ::CStr(firstevent) & ")");
}