Is there a way to print to output to console like debug.print() in VB.NET using structured text? (twincat3)
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:
msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_LOG
msgCtrlMask := ADSLOG_MSGTYPE_MSGBOX
%s
can be used to add parameter without CONCAT functions. See the last parameter.%s
in previous string.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.
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.