Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 724
Jess Avatar asked Jan 02 '23 01:01

Jess


1 Answers

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
  • Mask that describes the message type
  • Types can be found here
  • For example, to show warning message and save it to Windows log: msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_LOG
  • To show just a Windows MessageBox: msgCtrlMask := ADSLOG_MSGTYPE_MSGBOX
  • msgFmtStr
  • The message to be shown as STRING
  • A %s can be used to add parameter without CONCAT functions. See the last parameter.
  • strArg
  • A STRING that is replaces the %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.

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.

like image 134
Quirzo Avatar answered Jun 08 '23 14:06

Quirzo