当前位置:网站首页>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工程的,可以关注下方公众号网盘自取啦,感谢阅读。

- 要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
- 有微信的小伙伴可以关注下浪哥车载诊断,一个行业内小小圈子,群里有
网盘资料,源码,还有各路大神闲时交流交流技术,聊聊工作机会啥的。- 如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。
边栏推荐
- 【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer
- 硬件工程师的真实前途我说出来可能你们不信
- Leetcode:608 树节点
- 英雄联盟轮播图自动轮播
- June brush question 02 - string
- May brush question 02 - string
- Mysql database recovery (using mysqlbinlog command)
- Yarn organizational structure
- 面渣逆袭:Redis连环五十二问,图文详解,这下面试稳了
- 嵌入式中的合作开发--函数指针
猜你喜欢

MapReduce instance (VII): single table join

大学C语言入门到底怎么学才可以走捷径
[Yu Yue education] Wuhan University of science and technology securities investment reference

【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer

Publish and subscribe to redis

【深度学习】语义分割-源代码汇总

单片机实现模块化编程:思维+实例+系统教程(实用程度令人发指)

O & M, let go of monitoring - let go of yourself

Servlet learning diary 8 - servlet life cycle and thread safety

MapReduce instance (x): chainmapreduce
随机推荐
小白带你重游Spark生态圈!
Redis distributed lock implementation redison 15 questions
Day 5 of MySQL learning
Hard core! One configuration center for 8 classes!
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
【深度學習】語義分割-源代碼匯總
June brush question 01 - array
MapReduce instance (x): chainmapreduce
Appears when importing MySQL
What are the models of data modeling
Meituan Er Mian: why does redis have sentinels?
MapReduce working mechanism
Mysql database recovery (using mysqlbinlog command)
Cap theory
六月刷题01——数组
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
Segmentation sémantique de l'apprentissage profond - résumé du code source
May brush question 01 - array
Master slave replication of redis
