Scripting inside libraries

From Axel Public Wiki
Revision as of 10:13, 6 April 2020 by Axelpwiki (talk | contribs)
Jump to navigation Jump to search

This page describes advanced capabilites of function blocks and libraries, that allow to advanced scripting capabilites using AlFramework technology to them.

At the moment there is no GUI to add this attributes, so PLCLIB files must be manually edit using an external text editor to add them.

Add/remove/rename events for Function Blocks

It is possible to invoke a specific function when a function block instance is added, removed, or renamed in the project, using the instanceEditFunc attribute

<functionBlock name="myFB" version="1.0.0" creationDate="0" lastModifiedDate="0" instanceEditFunc="extensionName.functionName">
   <title>myFB</title>
   <descr>myFB descr</descr>
   ...

The invoked function (that can be implemented in any AlFramework extension, local or global, in any of the supported languages) must have this prototype (JavaScript example):

function OnInstanceEdit(editType, plcVar, oldName)
{
/*
--- PARAMETERS:
editType can be
   add = 0,
   remove = 1,
   rename = 2,  

plcVar is an IAlCOMPlcVar instance (see LogicLab technical reference)

oldName is only passed on 'rename' action; the plcVar already has the new name

--- RETURN VALUE: none
*/
}

Inside the function you can do any action on the plcVar (that is the function block instance) or on the project. For example:

  • on 'add': you can add global variables, parameters, assign programs to task, and initialize the plcVar instance VAR_INPUT variables
  • on 'remove': you can rollback actions done on 'add', like deleting global variables
  • on 'rename': you can adjust other project objects in relation of the new name

Please note that the 'rename' event will NOT be generated when editing the PLC variables using textual declaration (there will be a 'remove' and an 'add' event instead)

Adding PCT templates to Libraries

It is possible to associate and load a PCT file (and so extensions written in JavaScript, but also HTML pages and so on) to PLCLIB libraries, using the PCTtemplateName attribute:

<plcLibrary schemaVersion="2.7">
   <lib version="1.0.0" name="myLib" fullXml="true" PCTtemplateName="myLib.PCT">
   ...

In this case when the myLib.PLCLIB is loaded, LogicLab will also load the specified myLib.PCT file.

You can specify:

  • a PCT file relative to the PLCLIB position (the original position, that is the "Link" column in the Library manager)
  • a PCT file in the installation folder, using the pseudo-variables %CATALOG% or %APPPATH%
  • a PCT file embedded inside the PLCLIB, using the pseudo-variable %EMBFILES% (see below)

Embedding files inside the PLCLIB

You can embed a full set of files inside the PLCLIB, to make it fully portable along with its PCT file, scripts or HTML pages.

  • at first you have to develop everything outside the PLCLIB in a relative directory:
<plcLibrary schemaVersion="2.7">
   <lib version="1.0.0" name="myLib" fullXml="true" PCTtemplateName="devel\myLib.PCT">
   ...

Example Filesystem layout:

C:\myLibFolder\
   myLib.PLCLIB
   devel\
      myLib.PCT
      myLib.JS
      myLib.HTML
      ...
  • only at the end embed everything inside the library with the external tool plcLibEmbed
C:\myLibFolder> plcLibEmbed.bat devel myLib.PLCLIB
  • now you change the PCT template inside the PLCLIB using %EMBFILES% variable
<plcLibrary schemaVersion="2.7">
   <lib version="1.0.0" name="myLib" fullXml="true" PCTtemplateName="%EMBFILES%\myLib.PCT">
   ...

Example

See [here http://bla] for a working example. The library will show a HTML popup when you create a new instance of myFB block, and put some configuration data inside it.