0

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.

4

2 回答 2

2

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);
于 2018-11-01T17:30:46.750 回答
0

If you have output variable like this

FUNCTION Lightsensor_GetIlluminance : eErr 
VAR_OUTPUT
    value: UINT;
END_VAR

Then in the code you may uget your additional varaible like this.

eErr := Lightsensor_GetIlluminance(value => illumen);

Or if you create FUNCTION_BLOCK then in addition to method above you can use something like this.

FUNCTION_BLOCK Lightsensor_GetIlluminance 
VAR_OUTPUT
    value: UINT;
    error : eErr;
END_VAR

And in the code

Lightsensor_GetIlluminance();
IF NOT Lightsensor_GetIlluminance.error THEN
    illumen := Lightsensor_GetIlluminance.value;
END_IF;

So you may access varaible throu . but you have to call FB upfront.

于 2018-11-09T04:23:06.020 回答