当前位置:网站首页>CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
2022-07-06 09:03:00 【蚂蚁小兵】
前言
- 从事行业“几十年”,总能再不同场合碰见这几个打印函数,到底有啥区别,今天博主就给同学们缕一缕
- 演示软硬件环境 Win10 x64 ; CANoe 11 SP2 x64
- 本章节内容演示源码下载,点击跳转


write
1️⃣ 先创建工程和文件,用于演示

2️⃣ write 是最简单常用的打印函数了,这里贴出来,是让大家再熟悉下不同数据类型的打印格式。

3️⃣ 测试过程,输出的Soure类型是CAPL/.NET
on key 'a'
{
write ("pressed key %c",this);
}

writeEx
1️⃣ writeEx 就比write复杂多了,可以指定打印的显示位置,也可以指定打印的类型
- writeEx 会在窗口的最后一行接着打印,也就是不会自动换行

2️⃣ 测试过程,打印在Trace上,记得trace的CAPL要勾选上
on key 'b'
{
writeEx (TraceWindow,Information,"pressed key %c",this);
}

3️⃣ 测试过程,看得出输出在 System Page ,而且打印连续不换行
on key 'c'
{
writeEx (SystemWindow,Information,"pressed key %c",this);
writeEx (SystemWindow,Warning,"pressed key %c",this);
}

writeLineEX
1️⃣ 和writeEx的区别就是打印自动换行,可以指定打印的显示位置,也可以指定打印的类型

2️⃣ 测试过程
on key 'd'
{
writeLineEx (SystemWindow,Information,"pressed key %c",this);
writeLineEx (SystemWindow,Warning,"pressed key %c",this);
}

writeToLog
1️⃣ writeToLog 顾名思义,就是向Logging 文件写东西了,

2️⃣ 既然是向logging文件写数据,那就要先创建一个logging Block ,设置成CAPL触发的模式,需要logging

3️⃣ 测试代码如下:
On key 'f'
{
char timeBuffer[64];
getLocalTimeString(timeBuffer);
write("pressed key %d",this);
setLogFileName("logging", "test.asc");
startLogging("logging",100);
writeToLog("%s *************writeToLog*************",timeBuffer);
writeToLogEx("%s: *************writeToLogEx*************",timeBuffer);
stopLogging("logging",100);
}
4️⃣ 输出结果
- writeToLog 和 writeToLogEx 的区别也可以看的出来 ,writeToLog就是多打印 “// 时间戳”

writeToLogEx
writeDbgLevel
1️⃣ 这和函数非常好用,建议大家学会使用,在比较大的项目工程中,是不建议使用write 和 writeLineEx
等输出函数来调试代码的,因为我们无法控制这些debug输出与否的
- 这个函数可以根据优先级决定是否打印出来
- 第一个参数是指定优先级,这个数值越低,说明优先级越高,debug信息被输出的可能性越大,当然,这却决于
setWriteDbgLevel设置的优先级 - 0的优先级最高,如果setWriteDbgLevel(0),那么每次调用writeDbgLevel 函数,第一个参数必须=0 ,才能够输出出来,否则输出被抑制
- 15的优先级最低,如果setWriteDbgLevel(15)那么每次调用writeDbgLevel 函数,第一个参数无论等于什么 ,都能够输出
- 在实际开发中,我们会通过weite 太debug我们的代码,等调试完毕之后,我们又不期望这些debug信息被打印出来,那么我们就可以通过setWriteDbgLevel 函数把输出优先级调高,达到抑制输出的目的
- 建议使用的,


2️⃣ 测试代码和测试结果
On key 'g'
{
setWriteDbgLevel(7);
writeDbgLevel (4, "This is shown:");
// Output: This is shown
writeDbgLevel (9, "This is not shown");
// No output
}


| End |
总结


有需要演示中所用demo工程的,可以关注下方公众号网盘自取啦,感谢阅读。

- 要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
- 有微信的小伙伴可以关注下浪哥车载诊断,一个行业内小小圈子,群里有
网盘资料,源码,还有各路大神闲时交流交流技术,聊聊工作机会啥的。- 如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。
边栏推荐
- 听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
- [deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
- Global and Chinese markets for modular storage area network (SAN) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- What is an R-value reference and what is the difference between it and an l-value?
- Basic concepts of libuv
- MapReduce instance (VIII): Map end join
- 五月刷题03——排序
- May brush question 03 - sorting
- Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
- One article read, DDD landing database design practice
猜你喜欢

机械工程师和电气工程师方向哪个前景比较好?

Design and implementation of online shopping system based on Web (attached: source code paper SQL file)

Redis distributed lock implementation redison 15 questions

基于B/S的网上零食销售系统的设计与实现(附:源码 论文 Sql文件)

MapReduce工作机制

Servlet learning diary 7 -- servlet forwarding and redirection

Mapreduce实例(七):单表join

Full stack development of quartz distributed timed task scheduling cluster

Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)

单片机实现模块化编程:思维+实例+系统教程(实用程度令人发指)
随机推荐
Webrtc blog reference:
有软件负载均衡,也有硬件负载均衡,选择哪个?
Elk project monitoring platform deployment + deployment of detailed use (II)
O & M, let go of monitoring - let go of yourself
Full stack development of quartz distributed timed task scheduling cluster
In order to get an offer, "I believe that hard work will make great achievements
五月刷题26——并查集
May brush question 03 - sorting
为什么要数据分层
Global and Chinese market of AVR series microcontrollers 2022-2028: Research Report on technology, participants, trends, market size and share
June brush question 01 - array
【深度學習】語義分割-源代碼匯總
A wave of open source notebooks is coming
Redis core configuration
Mapreduce实例(十):ChainMapReduce
May brush question 27 - figure
单片机如何从上电复位执行到main函数?
Global and Chinese market for annunciator panels 2022-2028: Research Report on technology, participants, trends, market size and share
Compilation of libwebsocket
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
