0

I would like to declare an array of pointer with an initialization

Apb : array [0..2] of pointer to bool := adr(r0), adr(r1), adr(r2);

Where r0, r1, r2 are declared in Modbus like Bitwise holding register. I got an error: Wrong initial value.

In case:

Apb : array [0..2] of pointer to bool;
Apb[0]^ := r0;

Everything works as I want.

1 Answer 1

1

I think that POU variable declarations do not want function calls in them or even variables assigned to other variables.

The only way to have variables in your declaration is to use VAR_CONSTANTs. You will still have to do some legwork, but it can make larger-scale substitutions easier to manage.

There is also a way to use dynamic values using pragmas (I never really use pragmas although, so Im not certain of how powerful it is).


Coming from more standard programming languages, this one has similar rules and constructs as C, but not nearly as much flexibility, dreadful syntax, and nothing even resembling 'void' types. I ended up using python templates to help generate POU variable declaration headers because the allowed syntax is quite strict, leading to excessively verbose declarations.

Sign up to request clarification or add additional context in comments.

1 Comment

Constants are not variables by definition. The CoDeSys compiler only accepts statically known values for initialization and neither functions nor variables can be resolved at compile time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.