Overview CAA_ResMan.library

A data structure the code generator of CoDeSys does not account for is called resource, if it can be managed by a handle and a release function.  

Examples:

Handle of serial interface

File handle

Semaphore

  ....

Generally resources will be requested by special creating functions, whereby a handle will be created, for example hFile := SysFileOpen(`Test.txt`,`r`);

After use the handle will be released, e.g. SysFileClose(hFile);

Troubles will occur, if variables comprising handles are reinitialized  outside of the CoDeSys application without releasing the associated resources. Generally the execution of the CoDeSys menu commands Online/Reset or Online/Download will provoke these situations. This library aims to provide a mechanism, by use of which it will be possible to manage resources even during runtime states that could not be handle by the application program so far.

With help of the Resource Manager all types of handles can be managed. However this exceeds the existence of the same release function for each class of handles with the following properties: The release function has exactly one input parameter; this parameter is of type CAA.HANDLE. The return of the release function is an integer (e.g. an error ENUM).

 

VAR

   eError CAA.ResMan.library: XYZ_ERROR;

   hHandle : CAA.HANDLE;

END_VAR

eError := FreeHandle(hHandle := hHandle);

 

The Resource Manager should not be used directly within the application. All CAA libraries have to make use of the Resource Manager implicitly and transparently for the particular library user.

The Resource Manager will be implemented as abstract data type in ANSI-C and commanded via calls in C or ST.

The functions of the Resource Manager may be subdivided in the following groups:

The implementation of the Resource Manager cares for releasing all resources at the "right" moment, especially when the following events are occurring:

  • CB.BEFORE_DOWNLOAD
  • CB.BEFORE_RESET
  • CB.SHUTDOWN

Each time a handle "quits" a library hCheckParent should be set to CAA.gc_hINVALID by use of RSM.SetParent, so that these handles may be recollected by the Resource Manager of the IEC application. As soon as a handle enters a library hCheckParent should be set to a value different from CAA.gc_hINVALID by use of RSM.SetParent, so that from now on the library has to care for the handle not being released automatically by the Resource Manager any longer. Within the release function passed to the Resource Manager the function RSM.Unregister has to be called after the release of the resources concerned.