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

冷暖自知 提交于 2019-12-11 14:58:32

问题


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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/51700348/is-there-a-way-to-print-to-output-console-twincat3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!