CANoe中使用CAPL函数接口调用Vflash文件

Posted 蚂蚁小兵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CANoe中使用CAPL函数接口调用Vflash文件相关的知识,希望对你有一定的参考价值。

  • CAPL中集成了下面那么多调用vFlash的相关函数,其实实际用到的,可能就三五个函数

  • 使用这些函数接口必须要在测试模块里面加载VFLASHNODELAYER.DLL

  • Vector官方有Demo可以学习: C:\\Users\\Public\\Documents\\Vector\\vFlash\\8\\Examples\\vFlash with CANoe\\vFlashViaNodeLayer

  • 打开之后,CANoe和Vflash的通道都配置一样(这个工程需要真实总线环境,simulation不行)

  • 直接运行测试用例,可以看到Trace有数据,测试pass

  • 为什么即使没接真实的件,他也能有报文和刷写呢?因为simulation中它模拟节点做了应答
  • Demo中的测试用例呢,就调用了"vFlash\\Utilities.cin"中的 TestWaitForvFlashPackReprogrammed函数就完成了刷写

  • 再看下TestWaitForvFlashPackReprogrammed函数按照下面步骤完成的刷写
  • TestWaitForvFlashInitialized:初始化vFlash
  • TestWaitForvFlashProjectLoaded :加载.vflashPack工程
  • TestWaitForvFlashProjectLoaded :开始刷写
  • TestWaitForvFlashProjectUnloaded:卸载工程文件
  • TestWaitForvFlashDeinitialized:xxx
// Performs all necessary steps to reprogram the passed vFlashPack
// This function will wait until reprogramming has completed (it cannot be used in a simulation node)
enum vFlashStatusCode TestWaitForvFlashPackReprogrammed(char flashpack[])

// Test functions are only available in test modules!
#if TEST_NODE
  enum vFlashStatusCode lastStatusCode;
  enum vFlashStatusCode resultCode;
  char errorText[gkMaxErrorTextLength];
  int hasProjectLoaded = 1;

  if (!ProcessPathName(flashpack)) 
    snprintf(errorText, gkMaxErrorTextLength, "FATAL ERROR: No path to flashpack given!");
    write(errorText);   
    TestStepFail("TestWaitForvFlashInitialized", errorText);
    return FR_FileNotFound; 
  
  
  //----- Initialize vFlash Library -----
  lastStatusCode = resultCode = (enum vFlashStatusCode) TestWaitForvFlashInitialized();
  if (lastStatusCode != Success)
  
    TestWaitForvFlashLastErrorMessage(errorText, 1024);
    snprintf(errorText, gkMaxErrorTextLength, "vFlash initialization error: %s", errorText);
    write(errorText);
    TestStepFail("TestWaitForvFlashInitialized", errorText);
    return resultCode;
  
  else
  
    TestStepPass("TestWaitForvFlashInitialized", "vFlash initialized successfully");
  
  
  
  // from here on, return statements are not possible, because we have to call the "teardown" methods as well!
  // ==> how much complicated want we to be...
  
  //----- Load Project ----
  lastStatusCode = resultCode = (enum vFlashStatusCode) TestWaitForvFlashProjectLoaded(_gFlashpack);
  if (lastStatusCode != Success)
  
    hasProjectLoaded = 0;
    TestWaitForvFlashLastErrorMessage(errorText, 1024);
    snprintf(errorText, gkMaxErrorTextLength, "vFlash load project error: %s", errorText);
    write(errorText);
    TestStepFail("TestWaitForvFlashProjectLoaded", errorText);
  
  else
  
    TestStepPass("TestWaitForvFlashProjectLoaded", "Successfully loaded project: %s", _gFlashpack);
  
  
  
  //----- Activate Network
  // Activation of this function call is only required in case of flashing a FlexRay ECU 
  // and vFlash has to do Network Management
  if (lastStatusCode == Success)
  
    lastStatusCode = resultCode = (enum vFlashStatusCode) TestWaitForvFlashNetworkActivated();
    if (lastStatusCode != Success)
    
      TestWaitForvFlashLastErrorMessage(errorText, 1024);
      snprintf(errorText, gkMaxErrorTextLength, "vFlash activate network error: %s", errorText);
      TestStepFail("TestWaitForvFlashNetworkActivated", errorText);
      write(errorText);
    
    else
    
      TestStepPass("TestWaitForvFlashNetworkActivated", "Network activated successfully");
    
  
  
  
  //----- Start Reprogramming ----
  if (lastStatusCode == Success)
  
    lastStatusCode = resultCode = (enum vFlashStatusCode) TestWaitForvFlashReprogrammed();
    if (lastStatusCode != Success)
    
      TestWaitForvFlashLastErrorMessage(errorText, 1024);
      snprintf(errorText, gkMaxErrorTextLength, "vFlash reprogramming error: %s", errorText);
      TestStepFail("TestWaitForvFlashReprogrammed", errorText);
      write(errorText);
    
    else
    
      TestStepPass("TestWaitForvFlashReprogrammed", "ECU reprogrammed successful");
    
  

  
  //----- Unload Project ----
  if (hasProjectLoaded)
  
    lastStatusCode = (enum vFlashStatusCode) TestWaitForvFlashProjectUnloaded();
    if (lastStatusCode != Success)
        
      TestWaitForvFlashLastErrorMessage(errorText, 1024);
      snprintf(errorText, gkMaxErrorTextLength, "vFlash unload project error: %s", errorText);
      TestStepFail("TestWaitForvFlashProjectUnloaded", errorText);
      write(errorText);
    
    else
    
      TestStepPass("TestWaitForvFlashProjectUnloaded", "Project unloaded successfully");
       
  
  
  
  //----- Deinitialize vFlash Library ----
  lastStatusCode = (enum vFlashStatusCode) TestWaitForvFlashDeinitialized();
  if (lastStatusCode != Success)
  
    TestWaitForvFlashLastErrorMessage(errorText, 1024);
    snprintf(errorText, gkMaxErrorTextLength, "vFlash deinitialization error: %s", errorText);
    TestStepFail("TestWaitForvFlashDeinitialized", errorText);
    write(errorText);
  
  else
  
    TestStepPass("TestWaitForvFlashDeinitialized", "vFlash deinitialized successfully");
  
    
  return resultCode; // last result is of TestWaitForvFlashReprogrammed; result of Unload/Deinitialize ignored
#else // simulation node
  write( "ERROR: the function TestWaitForvFlashPackReprogrammed is only available in a test module!");
  return TestFunctionInSimulationCalled;
#endif // TEST_NODE

  • 如果想要刷写自己的vFlash文件,简单的话就是把 gFlashpack给个自己文件的路径即可;想要集成在自己工程中用的话,要引用 #include "vFlash\\Utilities.cin",调用 TestWaitForvFlashPackReprogrammed函数即可。

  • 自己调用的时候,别忘了要在测试模块中加载下面的DLL

🌎总结

  • 🚩要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!

  • 🚩如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。

以上是关于CANoe中使用CAPL函数接口调用Vflash文件的主要内容,如果未能解决你的问题,请参考以下文章

vFlash软件简介

如何在CANoe中访问内部计时器?

CANoe中使用CAPL刷写流程详解(Trace图解)(CAN总线)

CAPL脚本中 getSignal和 setSignal 函数的封装,看完本节足够适应所有测试场景

XML调用 CAPL Test Function

CAPL函数 Test Node中TestWait xxx 常用函数