D2000 offers the option of scripting - writing user scripts in ESL (Event Script Language) and Java.
A script can exist:
- Within a D2000 Event Handler process as an Event object whose parent is the corresponding D2000 Event Handler process.
- As part of pictures (so-called Active pictures) launched in D2000 HI or D2000 Thin Client processes. Within an active picture, the ESL script is an integral part of it (i.e. it is part of an object of type Picture).
ESL scripts can use (similar to eval tags) extensive mathematical data processing (Value Types, System Constants, Object Value Attributes, Expressions, and Functions).
In addition, there are ESL Extended Functions that are not available in calculated points. They also include XML file manipulation functions and JSON Format Manipulation Functions.
In addition, ESL scripts can also contain Actions that can mediate the functionality of other processes (e.g. DBManager) and can be divided into several groups:
- assignment actions
- action for accessing a database
- actions for handling error states
- control actions
- actions for communication with the operator
- archive manipulation actions
- actions for synchronization of script actions execution
- controlling alarms
- structure manipulation actions
- data container manipulation actions
- access right manipulation actions
- actions for manipulation with a list of objects
- other actions
One of the following types is specified in the Event object configuration:
- Trigger event - the script is executed when a specified condition occurs - a value changes, a process alarm occurs on the trigger object, the required value limit occurs, and others.
Note: with the EVENT action, the trigger event can be started from another script (synchronously or asynchronously - in this case even more than once). - Server event - the script executes its initialization part (between BEGIN and END) after starting (by default after the start of the D2000 Event Handler process, or after it is started by the OPENEVENT action, or after its transition to the active instance state in redundant systems). Subsequently, it is possible to call the RPC procedures that the event server implements (by using the CALL action) and, reciprocally, the event server can call the RPC procedures of other server events. Using the ON CHANGE action, the server event can be registered to be notified of a change in the value of any object - then the specified procedure is invoked.
Note: with the OPENEVENT action, the event server can be started not only on any D2000 Event Handler process but also on the D2000 HI process. In addition, it is possible to specify the instance of the server event and thus achieve multiple openings of the Server Event within the given process. - Client and server event - has similar properties to the Server event, but if it is opened by the OPENEVENT action on the D2000 HI process, then the client part of the script is run in the D2000 HI process and the server part of the script is run in the D2000 SES process (which by default is run on the server). Splitting the script into two parts enables both performance optimization and combining access to the client computer and the server.
- Unit event - such a script is a "library" that can be inserted into another event (or into a scheme) by the UNIT declaration and its PUBLIC procedures can be called by the CALL action.
Examples of scripting are included in the documentation of individual actions, however, there are also examples related to different topics:
- Example: Work with a database table (actions DB_ ...)
- Example: Work with a database table (actions PG_ *)
- Example: Work with a database (actions SQL_ ...)
- Example of work with lists of objects (LST_... actions)
- Example: work with data container (actions CNT_ ...)
An example of working with XML export/import, structures, and files can be found in the XML Tool.
An example of more advanced work with structured variables is in the Danfoss Ally Cloud protocol implementation.
Tip
The ESL Diagnostic Pack can be opened in the D2000 Cnf and D2000 GrEditor tools. It is used to diagnose scripts and find out the resources used (e.g. sizes of local variables, sizes and numbers of data containers, database transactions, connections, open JSON handles, open XML documents, and others). It is also possible to display the details of individual scripts, including the duration of individual script actions (maximum duration, total duration, number of executions), which can be used to tune the performance of scripts.
DbManager Diagnostic Pack is also available for debugging database actions.
Advanced tip
Using the ESL Interface object, it is possible to define the list and parameters of RPC procedures. Subsequently, in the event, using the IMPLEMENTATION keyword, it is declared that the event implements these RPC procedures, and in the body of the event, the keyword (IMPLEMENTATION RPC PROCEDURE SomeProcedure) must also be specified when defining the RPC procedure. An event will be saveable only when it implements all RPC procedures of all ESL Interface objects it refers to. The ESL Interface is thus used to enforce control over the implementation of agreed RPC procedures.
0 komentárov