If I call
Tc2_System.ADSLOGSTR() during execution of a test, my messages don’t arrive in the expected order. Let’s for example assume this very simple (always failing) test:
TEST('Test1'); FOR nCounter := 1 TO 5 BY 1 DO Tc2_System.ADSLOGSTR(msgCtrlMask := ADSLOG_MSGTYPE_HINT, msgFmtStr := 'Test Number is %s', strArg := INT_TO_STRING(nCounter)); sAssertionMessage := Tc2_Standard.CONCAT(STR1 := 'Assertion failed no. ', STR2 := INT_TO_STRING(nCounter)); AssertEquals_BOOL(Expected := TRUE, Actual := FALSE, Message := sAssertionMessage); END_FOR TEST_FINISHED();
This will result in this order of messages:
I want the messages to arrive in the correct order, how is this achieved?
The reason for this behavior is because all ADS messages that TcUnit creates/outputs are buffered (for deeper technical description read this). If
Tc2_System.ADSLOGSTR() is used directly, the messages can come out of sequence in relation to the message created by TcUnit as TcUnit buffers the messages to not overflow the ADS message router.
The solution is to use
TCUNIT_ADSLOGSTR(), which accepts the exact same inputs as
ADSLOGSTR(). By using this function, the
ADSLOGSTR() messages are put in the same buffer as TcUnit is using for its output.
So if we replaced the call to
TCUNIT_ADSLOGSTR() instead, we get this:
Required TcUnit version: 1.2 or later