General Concepts of Script Development

<< Click to Display Table of Contents >>

Navigation:  Modbus Universal MasterOPC Server > Lua 5.1 Reference Manual > Function library >

General Concepts of Script Development

General Concepts of Script Development

Scripts can be developed in various elements of OPC server configuration: in nodes, devices, sub-devices or/and tags. While creating, a script includes 3 functions (for a tag) or 4 functions (for a node, device or sub-device): the initialization function, the deinitialization function, "before reading a device" function, and "after reading a device" function. A code is developed within bodies of those functions. User functions (see Function Definitions) must be declared out of system functions.

A script of a node, device or subdevice can include:

mbul   Global declarations (executed when loading a script)

mbul   Functions created automatically:

mbul   The initialization function (executed one time at node start):

function OnInit()

end

mbul   The deinitialization function (executed one time at node stop):

function OnClose()

end

mbul   The function executed before an attempt to read devices (executed periodically; a poll period can be set):

function OnBeforeReading()

end

mbul   The function executed after an attempt to read devices (executed periodically; a poll period can be set):

function OnAfterReading()

end

mbul   User-defined functions

   

A script of a tag can include:

mbul   Global declarations (executed when loading a script)

mbul   Functions created automatically:

mbul   The initialization function (executed one time at node start):

function OnInit()

end

mbul   The deinitialization function (executed one time at node stop):

function OnClose()

end

mbul   The function executed after reading a tag (created in the script after reading; executed periodically):

function OnRead()

end

mbul   The function executed before writing a tag (created in the script before writing; executed when attempting to write to a tag; the function is not executed when program writing):

function OnWrite()

end

The function is called by an OPC client when writing as well as while writing from a script of other tag. In order to detect that writing is performed from a script of other tag, the function server.IsWriteFromScript( ) is used.

mbul   User-defined functions