TWINCAT3导出html,twincat - Is there a way to print to output console? (twincat3) - Stack Overflow

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.

fmsDc.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值