有没有办法打印到输出控制台? (twincat3) [英] Is there a way to print to output console? (twincat3)

查看:363
本文介绍了有没有办法打印到输出控制台? (twincat3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用结构化文本将输出打印到VB.NET中的debug.print()这样的控制台? (twincat3)

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

推荐答案

您可以通过TwinCAT代码中的ADS命令发送消息.该函数称为 ADSLOGSTR .还有DINT和REAL的函数,但是STRING函数当然可以与任何东西一起使用.

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.

该函数具有三个输入:

  • msgCtrlMask
    • 描述消息类型的掩码
    • 可以在此处
    • 找到类型
    • 例如,要显示警告消息并将其保存到Windows日志:msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_LOG
    • 仅显示Windows MessageBox:msgCtrlMask := ADSLOG_MSGTYPE_MSGBOX
    • 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
      • 要显示为STRING的消息
      • A %s可用于添加不带CONCAT功能的参数.请参阅最后一个参数.
      • The message to be shown as STRING
      • A %s can be used to add parameter without CONCAT functions. See the last parameter.
      • 一个STRING替换了先前字符串中的%s.

      下面是一个示例,可能是您需要的:

      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
      

      当您将测试设置为true并调用该函数时,您将在Visual Studio错误列表中看到此错误.请注意,它没有写入控制台.

      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.

      我经常使用错误消息(ADSLOG_MSGTYPE_ERROR),因为我经常隐藏注释和警告,并且我不会注意到自己的条目.另一个好方法是,如果您想记录一些内容以便以后查看,则将该条目添加到Windows日志中.

      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.

      这篇关于有没有办法打印到输出控制台? (twincat3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆