Working with external optional Libraries

Optional external libraries serve to make optional runtime system components available in IEC. Optional means here that a component cannot be integrated in any runtime system because of resource or system restrictions. So optional components and their corresponding libraries are not available in all runtime systems.

To make a library in CODESYS optional, it is necessary to separate data types, interfaces, constants, etc. from the actual implementation. This separation is necessary because it is not possible to use a conditional compilation in the declaration part of CODESYS. By splitting the implementation and the data types, it is possible that the data types are used in the declaration part, but are conditionally compiled against the external interface in the implementation part. This enables the library developer to react to optional external interfaces.

The following example illustrates the use of an optional interface.

{IF NOT defined (pou:TLS.CmpTlsCreateContext2)}
IF itfCertVerifer <> 0 THEN
    eErrorID := ERROR.WRONG_PARAMETER;
    RETURN;
END_IF
{END_IF}

(* ... *)

{IF defined (pou:TLS.CmpTlsCreateContext2)}
_hTlsContext :=  TLS.CmpTlsCreateContext2(_hCert, eTlsMethod, psChiphers, TO_DWORD(udiVerificationMode), itfRTSCertVerfier, ADR(udiResult));
{ELSIF defined (pou:TLS.CmpTlsCreateContext)}
_hTlsContext :=  TLS.CmpTlsCreateContext(_hCert, eTlsMethod, psChiphers, TO_DWORD(udiVerificationMode), ADR(udiResult));
{ELSE}
_hTlsContext := RTS_INVALID_HANDLE;
udiResult := ERRORS.ERR_FAILED;
{END_IF}

The individual possibilities for reacting to certain properties of the system via conditional compilation are discussed in section Identify your System.