Search code examples
plcst

Syntax for Getting Ouput Variable in Structured Text


I'm trying to use a library defined function (CCaux for Cross Control Products) with the following interface:

FUNCTION Lightsensor_GetIlluminance : eErr (* return error status. 0 ERR_SUCCESS, otherwise error code.*)
VAR_OUTPUT
    value: UINT;(*Illuminace value (Lux)*)
END_VAR

I can't seem to find the correct syntax for getting the "value" from the output variable. Here is what I have in my program:

VAR
    illumen : UINT;
END_VAR

Where I want illumen to be set to the output variable of Lightsensor_GetIlluminace. The following doesn't work since it sets the variable to the eErr:

illumen := CCAux.Lightsensor_GetIlluminance();

And:

illumen := CCAux.Lightsensor_GetIlluminance.value;

Doesn't work because I get the error 'value' is no input of 'Lightsensor_GetIlluminance'

And:

illumen := CCAux.Lightsensor_GetIlluminance(value := illumen);

fails because Lightsensor_GetIlluminance take exactly '0' inputs

I am using CoDeSys for context.


Solution

  • Here is the syntax for functions with additional outputs:

    <function> (<function output variable1> => <output variable 1>, <function output variable n> => <output variable n>)
    

    The following code should return the "Illuminace value":

     CCAux.Lightsensor_GetIlluminance(value => illumen);