Материал: Toolkit asynchronous DLLs with RTE interface

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

Custom-DLL-Interface for RTE

Description of

the interface for asynchronous calls of

functions located in DLLs

from IEC-Program (PLC-program)

1.Intruduction

1.1.Overview

The realtimeextension of 3S-company for WindowsNT4.0 consists of a kernel-part and an applicationpart. The kernelpart is a krnelmodedriver, which works as a taskscheduler and a PLC. With the programmingsystem CoDeSys, tasks can be programmed and configured to work in realtime. Within these tasks, realtime-dedicated functions can be managed. This means, for example, no Windows-API-calls are possible, IOs are updated by direct hardwareaccess and so on.

The applicationpart is implemented as systemservice, means here we can do all the things, which need Windows-API-calls, like networking and others.

Now there is a need to start these jobs from the PLC (running in the kernel, in our realtimetasks). So we implemented an interface, which allows us to call functions within DLLs.

In the IEC-Program (CoDeSys) the call to a library-functionblock leads to a call of a DLL-function in usermode (Windows-API).

The work of the DLL-function is done in the context of an own thread for each call. So more than one call can be active at a time and all the calls are controlled by timeouts and exceptionhandlers.

1.2.Which DLLs are loaded

Used DLLs are made visible to the system by registry-entries:

In

\\HKEY_LOCAL_MACHINE\Software\3S Smart Software Solutions\Codesys SP\RTPLC\External DLLs

there must exist a value for each DLL that should be used. The form is:

Valuename: Dllx, where x is a number starting from 0.

Value: The filename of the DLL, with or without (if located in system32) path.

All these Dlls (no matter how many) are loaded to memory with Start system, and unloaded with Stop system.

Example for an entry:

Dll0 d:\Workspace\AsynchDll\AsynchDll.dll

2.The interface and the toolkit

All the functions in a DLL can be called through the library functionblock ‘DllCall‘ aufgerufen werden.

The parameters are :

bEnable At a rising edge the job is started.

szFunktionName The name of the function to be called.

ulSizeIn Size of the inputbuffer in bytes.

ulSizeOut Size of the outputbuffer in bytes.

pAdrIn address of the inputdata (address of a structure in IEC.)

pAdrOut address of outputdata (address of a structure in IEC.)

The returnvalue of iStatus is one of:

STATUS_NOTENABLED,

STATUS_PROCESSING,

STATUS_READY,

STATUS_ERROR,

STATUS_TIMEOUT,

STATUS_EXCEPTION,

STATUS_USERTERMINATED

The functionblock must be called cyclic, to make changes of enable visible to the PLC and give the PLC the possibility to set the current state.

The functionblock is part of the library DllCall.lib.

The library ‚DllCall.lib‘ is based on the library ‚SysLibSystemCall.lib‘, which must be included manually into the program.

The functions within the DLL, must fit the following prototype:

typedef BOOL (_cdecl *PFCUSTOMDLLFUNCTION)(char* pBufferIn, int iSizeIn, char* pBufferOut, int iSizeOut);

The returnvalue maintains the states STATUS_ERROR (returnvalue FALSE) or STATUS_READY of DllCall.

The communication between the PLC and the DLL is implemented with sharedmemory-channels and is limited to 100bytes (total) input- and outputdata.

The name of the function must not be longer than 80 bytes.

3S – Smart Software Solutions

Page 3 von 3

Источник: https://studfile.net/preview/16370040/