#9 Is there a way to test direct adressed (%I* or %Q*) variables?



In a number of scenarios, CODESYS will not allow you write directly to certain variable types due to access restrictions e.g. :

A variable declared in a FBs VAR (a local var not in global scope)
The variable being set as a direct I/O adress (i.e. AT %I* or AT %Q*)

Writing to these kinds of variables wouldn't make sense and should be prevented under normal circumstances, so having special privileges during testing is a must. To support these cases, CfUnit provides helper functions like WRITE_PROTECTED_BOOL, WRITE_PROTECTED_INT (etc, etc.) for setting these type of variables. As an example of how to apply them, let’s assume you have a test:

METHOD PRIVATE TestCommsOkChannelsLow
    TestFB : FB_SomeTestFB;

Where the FB_SomeTestFB holds a variable:

iChannelInput AT %I* : ARRAY[1..8] OF BOOL;

Now you might want to write a value to the first channel of the iChannelInput like:

CfUnit.WRITE_PROTECTED_BOOL(Ptr := ADR(TestFB.iChannelInput[1]),
                            Value := FALSE);

Whereas afterwards you can make an assertion as usual:

AssertFalse(Condition := TestFB.ChannelInput[1],
                        Message := 'Channel is not false');


  • aliazzz

    aliazzz - 2020-04-27
    • status: --> closed
  • aliazzz

    aliazzz - 2020-05-01
    • Status: closed --> open

Log in to post a comment.