当前位置:网站首页>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工程的,可以关注下方公众号网盘自取啦,感谢阅读。
- 要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
- 有微信的小伙伴可以关注下浪哥车载诊断,一个行业内小小圈子,群里有
网盘资料
,源码
,还有各路大神
闲时交流交流技术,聊聊工作机会啥的。- 如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。
边栏推荐
- 五月刷题26——并查集
- Publish and subscribe to redis
- Redis' performance indicators and monitoring methods
- Global and Chinese market of electric pruners 2022-2028: Research Report on technology, participants, trends, market size and share
- MapReduce instance (IX): reduce end join
- Processes of libuv
- 一大波开源小抄来袭
- Minio distributed file storage cluster for full stack development
- DCDC power ripple test
- Nc17 longest palindrome substring
猜你喜欢
Servlet learning diary 8 - servlet life cycle and thread safety
MapReduce instance (x): chainmapreduce
Hard core! One configuration center for 8 classes!
MapReduce instance (IX): reduce end join
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
Compilation of libwebsocket
Kratos ares microservice framework (I)
MapReduce工作机制
英雄联盟轮播图自动轮播
Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
随机推荐
leetcode-14. Longest common prefix JS longitudinal scanning method
Publish and subscribe to redis
Leetcode:608 tree node
May brush question 03 - sorting
手把手教您怎么编写第一个单片机程序
Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
Mapreduce实例(八):Map端join
单片机如何从上电复位执行到main函数?
MapReduce工作机制
Redis core configuration
What you have to know about network IO model
In order to get an offer, "I believe that hard work will make great achievements
May brush question 27 - figure
YARN组织架构
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
学习单片机对社会的帮助是很大的
硬件工程师的真实前途我说出来可能你们不信
六月刷题01——数组
51单片机进修的一些感悟