当前位置:   article > 正文

CPAL脚本自动化测试( log 系列函数)_怎么在capl里自动log

怎么在capl里自动log

setLogFileName

使用方法

在这里插入图片描述

函数作用

 设置日志文件的名称。 如果给出有效的扩展名,它也会更改文件类型。此功能在独立模式下不可用。从 CANoe 8.5 开始,文件名也可以包含域代码。 如果旧文件名仅包含自增域代码类型的域代码,为了向下兼容,新文件名将使用旧文件名的域代码进行扩展。 自动递增字段代码将照常添加到文件名中。

示例

  1. ...
  2. setLogFileName("Logging1", "newlog");
  3. ...
  4. Sets the name of the logging file to "newlog" in the directory of the current configuration.
  5. ...
  6. setLogFileName("Logging1", "c:\\canw\\demo\\automot\\newlog");
  7. ...
  8. Sets the absolute path of the logging file.
  9. ...
  10. setLogFileName("Logging1", "..\\Logging\\newlog");
  11. ...
  12. Sets the relative path of the logging file.
  13. Example File Type
  14. ...
  15. setLogFileName( "newlog.blf" );
  16. ...
  17. Sets the name of the logging file to newlog and the file type blf
  18. ...
  19. ...
  20. setLogFileName( "newlog.notSupportedExtension" );
  21. ...
  22. Does nothing //file extension not valid

setPostTrigger

使用方法

在这里插入图片描述

函数作用

 设置日志记录的后触发。 使用此函数设置的 posttrigger 在测量结束或下一次调用此函数之前有效。函数 stopLogging() 不考虑使用函数“setPostTrigger”的设置,而是使用 CAPL 函数 trigger()。

示例

  1. on start
  2. {
  3. SetPreTrigger(5000);
  4. SetPostTrigger(5000);
  5. }
  6. on key 'x'
  7. {
  8. //start and stop of all CAPL trigger/Logging blocks with pre and post trigger settings
  9. trigger();
  10. }

setPreTrigger

使用方法

在这里插入图片描述

函数作用

 设置记录的预触发。 使用该函数设置的预触发在测量结束或下一次调用该函数之前一直有效。 函数 startLogging() 不考虑函数 setPreTrigger 的设置,而是使用 CAPL 函数 trigger() 。

示例

  1. on start
  2. {
  3. SetPreTrigger(5000);
  4. SetPostTrigger(5000);
  5. }
  6. on key 'x'
  7. {
  8. //start and stop of all CAPL trigger/Logging blocks with pre and post trigger settings
  9. trigger();
  10. }

StartLogging

使用方法

在这里插入图片描述

函数作用

 1. 立即启动所有日志记录块,绕过所有日志记录触发器设置。
 2. 立即启动一个名为 strLoggingBlockName 的日志块,绕过所有日志触发器设置。
 3. 启动名为 strLoggingBlockName 的日志块,绕过所有日志触发器设置。该函数还将预触发时间设置为 preTriggerTime 的值。

示例

  1. startLogging();
  2. // starts all Logging Blocks
  3. stopLogging();
  4. // stops all Logging Blocks
  5. startLogging( "Logging 1");
  6. // starts the Logging Block "Logging 1"
  7. stopLogging( "Logging 1");
  8. // stops the Logging Block "Logging 1"
  9. startLogging( "Logging 1", 2000);
  10. // starts the Logging Block "Logging 1" with pre-trigger time 2000 milliseconds.
  11. stopLogging( "Logging 1", 1000);
  12. // stops the Logging Block "Logging 1" with post-trigger time 1000 milliseconds.

StopLogging

使用方法

在这里插入图片描述

函数作用

 1. 立即停止所有记录块,绕过所有记录触发设置。
 2. 立即停止名为 strLoggingBlockName 的日志记录块,绕过所有日志记录触发器设置。
 3. 停止名为 strLoggingBlockName 的日志块,绕过所有日志触发器设置。Functions 还将后触发时间设置为 postTriggerTime 的值。

示例

  1. startLogging();
  2. // starts all Logging Blocks
  3. stopLogging();
  4. // stops all Logging Blocks
  5. startLogging( "Logging 1");
  6. // starts the Logging Block "Logging 1"
  7. stopLogging( "Logging 1");
  8. // stops the Logging Block "Logging 1"
  9. startLogging( "Logging 1", 2000);
  10. // starts the Logging Block "Logging 1" with pre-trigger time 2000 milliseconds.
  11. stopLogging( "Logging 1", 1000);
  12. // stops the Logging Block "Logging 1" with post-trigger time 1000 milliseconds.

trigger

使用方法

在这里插入图片描述

函数作用

 向所有 CANoe 记录或触发块发送触发事件。对于记录块,触发事件开始和停止记录,具体取决于
  1. 触发模式(单触发或切换触发)
  2. 打开和关闭的触发条件
 在此块的触发器配置对话框中设置。对于触发块,触发事件会启动和停止整个分析分支或单个分析窗口的数据流(如过滤器),还取决于触发配置对话框中的触发模式和触发条件。

示例

  1. on message 100
  2. {
  3. write("logging start");
  4. trigger(); // start logging
  5. setTimer(logging,1000); // for 1000 ms
  6. }
  7. on timer logging
  8. {
  9. trigger(); // Stop logging
  10. }

triggerEx

使用方法

在这里插入图片描述

函数作用

 将触发事件发送到按名称指定的 CANoe 记录或触发块。对于记录块,触发事件开始和停止记录,具体取决于
  1. 触发模式(单触发或切换触发)
  2. 打开和关闭的触发条件
 在此块的触发配置对话框中设置。对于触发块,触发事件启动和停止整个分析分支或单个分析窗口的数据流(如过滤器),还取决于触发模式和触发条件 触发配置对话框。如果您没有输入名称,事件将被发送到位于 CAPL 节点后面的所有触发和记录块,并在测量设置中使用 CAPL 函数 triggerEx()。 如果想让CAPL节点对所有的Trigger Blocks都生效,则CAPL节点必须直接放在在线/离线切换之后。

示例

  1. on message 100
  2. {
  3. write("logging starts in Logging Block ""Logging""");
  4. triggerEx("Logging"); // start logging
  5. setTimer(logging,1000); // for 1000 ms
  6. }
  7. on timer logging
  8. {
  9. triggerEx("Logging"); // Stop logging
  10. }

writeToLog

使用方法

在这里插入图片描述

函数作用

 将输出字符串写入 ASCII 日志文件。 写入基于 C 函数 printf。编译器无法检查格式字符串。 非法格式条目将导致未定义的结果。 与 writeToLogEx 函数不同的是,每行的开头都会打印注释字符(“//”)和时间戳。结果字符串的最大长度限制为 1024 个字符。

示例

  1. void MarkLogFile(int marker) {
  2. // marks line of ASCII logging file with an integer
  3. writeToLog("===> %d",marker);
  4. }

writeToLogEx

使用方法

在这里插入图片描述

函数作用

 编译器无法检查格式字符串。 非法格式条目将导致未定义的结果。 与 writeToLog 函数不同的是,行首不会打印注释字符(“//”)和时间戳。结果字符串的最大长度限制为 1024 个字符。 将不带注释字符的自生成行导入 CANoe 可能会导致问题。

示例

  1. // write marker with current date and time to logging file
  2. void MarkLogFileWithTimeString(void)
  3. {
  4. char timeBuffer[64];
  5. getLocalTimeString(timeBuffer);
  6. writeToLogEx("===> %s",timeBuffer);
  7. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/816001
推荐阅读
相关标签
  

闽ICP备14008679号