twincatstructured-text

Is there a way to print to output console? (twincat3)


Is there a way to print to output to console like debug.print() in VB.NET using structured text? (twincat3)


Solution

  • You can send messages through ADS commands from TwinCAT code. The function is called ADSLOGSTR. There also also own functions for DINT and REAL, but the STRING function of course can be used with anything.

    The function has three inputs:

    Here is an example the probably is what you need:

    IF test THEN
        ADSLOGSTR(
            msgCtrlMask := ADSLOG_MSGTYPE_HINT, 
            msgFmtStr   := 'Test message. Parameter is %s', 
            strArg      := 'ABC'
        );      
        test := false;
    END_IF
    

    When you set the test true, and call the function, you will see this on your Visual Studio error list. Note that it is not written to console.

    enter image description here

    I often use error messages (ADSLOG_MSGTYPE_ERROR) because I hide notes and warnings quite often and the I wouldn't notice my own entries. Other good way is to add the entry to the Windows log, if you want to log something to be seen later.