CPAL脚本自动化测试 ———— log 系列函数

setLogFileName

使用方法

在这里插入图片描述

函数作用

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

示例

...
setLogFileName("Logging1", "newlog");
...
Sets the name of the logging file to "newlog" in the directory of the current configuration.

...
setLogFileName("Logging1", "c:\\canw\\demo\\automot\\newlog");
...
Sets the absolute path of the logging file.

...
setLogFileName("Logging1", "..\\Logging\\newlog");
...
Sets the relative path of the logging file.
 
Example File Type

...
setLogFileName( "newlog.blf" );
...
Sets the name of the logging file to newlog and the file type blf
...

...
setLogFileName( "newlog.notSupportedExtension" );
...
Does nothing //file extension not valid

setPostTrigger

使用方法

在这里插入图片描述

函数作用

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

示例

on start
{
  SetPreTrigger(5000);
   SetPostTrigger(5000);
}

on key 'x'
{
  //start and stop of all CAPL trigger/Logging blocks with pre and post trigger settings
   trigger();
}

setPreTrigger

使用方法

在这里插入图片描述

函数作用

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

示例

on start
{
  SetPreTrigger(5000);
  SetPostTrigger(5000);
}

on key 'x'
{

    //start and stop of all CAPL trigger/Logging blocks with pre and post trigger settings
  trigger();
}

StartLogging

使用方法

在这里插入图片描述

函数作用

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

示例

startLogging();
// starts all Logging Blocks
stopLogging();
// stops all Logging Blocks
startLogging( "Logging 1");
// starts the Logging Block "Logging 1"
stopLogging( "Logging 1");
// stops the Logging Block "Logging 1"
startLogging( "Logging 1", 2000);
// starts the Logging Block "Logging 1" with pre-trigger time 2000 milliseconds.
stopLogging( "Logging 1", 1000);
// stops the Logging Block "Logging 1" with post-trigger time 1000 milliseconds.

StopLogging

使用方法

在这里插入图片描述

函数作用

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

示例

startLogging();
// starts all Logging Blocks
stopLogging();
// stops all Logging Blocks
startLogging( "Logging 1");
// starts the Logging Block "Logging 1"
stopLogging( "Logging 1");
// stops the Logging Block "Logging 1"
startLogging( "Logging 1", 2000);
// starts the Logging Block "Logging 1" with pre-trigger time 2000 milliseconds.
stopLogging( "Logging 1", 1000);
// stops the Logging Block "Logging 1" with post-trigger time 1000 milliseconds.

trigger

使用方法

在这里插入图片描述

函数作用

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

示例

on message 100 
{
  write("logging start");
  trigger(); // start logging
  setTimer(logging,1000); // for 1000 ms
}

on timer logging
{
  trigger(); // Stop logging
}

triggerEx

使用方法

在这里插入图片描述

函数作用

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

示例

on message 100 
{
  write("logging starts in Logging Block ""Logging""");
  triggerEx("Logging"); // start logging
  setTimer(logging,1000); // for 1000 ms
}

on timer logging
{
  triggerEx("Logging"); // Stop logging
}

writeToLog

使用方法

在这里插入图片描述

函数作用

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

示例

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

writeToLogEx

使用方法

在这里插入图片描述

函数作用

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

示例

// write marker with current date and time to logging file
void MarkLogFileWithTimeString(void)
{
char timeBuffer[64];
getLocalTimeString(timeBuffer);
writeToLogEx("===> %s",timeBuffer);
}

猜你喜欢

转载自blog.csdn.net/qq_42957717/article/details/121273644