Description of ExamDLL example
The example is placed in the folder /Pm/Examples/Others/PmDll/Exam
The example demonstrates usage of the DLL (dynamic linked libraries), their connection with the PROMOTIC system and calling the functions contained in these libraries.
The following objects were created in this example application:
The PmDll object named "Func" and graphic panel (PmPanel).
The "Func" object of the PmDll type used in order to access functions in DLL. On its page Dll it is necessary to set the full path to the file of the required library (in this case FuncDLL.dll).
The panel contains two buttons that run panel user methods MaxDll and SumDll.
The panel method SumDll
calls the function Sum
from library FuncDLL
that sums two integers. The result is written into the Debug_info
item in the INFO system.
panel method works the same way with the only difference that when it is called, the Max
function from the FuncDLL
library is runned for finding the maximum from three integers. The result is also written into the Debug_info
Listing from script:
in user method MaxDll of the "Main" panel:
In this case passing a parameter to the function is a litte bit complicated as the Max
function takes the structure consisting of three integers as a parameter. This structure is created in PROMOTIC
as an array of the length 3. To pass it to the function correctly, each value of the array has to be converted by the CLng
function to 4-bytes integers. The reason for this is that in VBScript each new variable is automatically assigned to corresponding data type. But this type needn't correspond to the type that is required by the library function which can be programmed in another language. Structured data types need to be passed by references. In this case the Max function is created so that it takes the structure of three numbers of the Integer
type (it means that 3*4 bytes). That's why before calling Max
, each number must be explicitly converted to 4-bytes value of the Long
type. See Syntax description of the declaration file of the DLL library functions
Description of FuncDLL.dll
This library was created in the programming language Visual C++. It offers two functions:
- Sum(a, b) function, whose parameters a, b are two integers passed by value and it returns their sum a+b.
- Max(st) function has st as an input parameter passed by reference that is a data structure consisting of three integer (4-bytes) values. Returns an integer that is their maximum.
The source code of the library in the language C++ is supplied with the example in the FuncDLL.cpp
file. This file is not needed when calling functions from the PROMOTIC system.
To allow PROMOTIC to call functions included in the DLL library, the declaration file needs to be created. This file has to have the same name as the corresponding library but the extension .inc
(in the case the name is FuncDLL.inc
), and it must be located in the same folder as the library. Each its line contains the declaration of one function. It is not needed to declare all functions from the library but only those that are used in the PROMOTIC system. See Syntax description of the declaration file of the DLL library functions
Example of communication with cards PCL720 and PCL818H
The example is placed in the folder /Pm/Examples/Others/PmDll/CardPCL
The following files form part of this example:
PCLCards.pra - PROMOTIC application
Ad818s.inc - initialization file for the Ad818s.dll library
Adapi32.inc - initialization file for the Adapi32.dll library
(in which there are declarations of used functions from the corresponding .dll)
For communication of the PROMOTIC application with cards it is necessary to copy (install) the corresponding .dll libraries from Advantech to the disk (e.g. into the Windows system folder). .inc files have to be also moved to the same folder. To be able to use the I/O cards, their configuration has to be set in the setup program from Advantech.
Starting the application
After starting the PCLCards application it is necessary to set the path to each used DLL. It is done for each DLL object in the "Dll" folder. Input-output operations are started by the key combinations that can be read from the folders in the objects tree.
library from Advantech contains special functions for the cards of the PCL818
type and adapi32.dll
contains general functions for the cards from Advantech.
More information can be obtained from these sources
Documentation PROMOTIC - how to work with DLL and .inc files
Documentation to used libraries - setup of cards and description of all functions
Documentation to I/O cards - description of the HW setting