CANoe-CAPL读文件

1. 简述

开发BootLoader,实现OTA升级和CAN刷写功能,CAN刷写使用CANoe实现。CANoe可以打开二进制文件和文本文档。

官方参考API:
file:///D:/VectorCANoe15/Help01/CANoeCANalyzerHTML5/CANoeCANalyzer.htm#Topics/CAPLFunctions/Other/CAPLfunctionsGeneralOverview.htm

官方参考代码:
file:///D:/VectorCANoe15/Help01/CANoeCANalyzerHTML5/CANoeCANalyzer.htm#Topics/CAPLFunctions/Other/Functions/CAPLfunctionsExapmleFileFunctions.htm

1

2. 使用

这里以部分函数为例,具体参考官方API文档。

/* openFileRead-打开文件进行读访问 */
dword openFileRead (char filename[], dword mode); // form 1
dword openFileRead (char filename[], dword mode, dword fileEncoding); // form 2

参数:
filename: 文件名
mode: 0-以文本方式打开; 1-以二进制方式打开
返回值:
文件句柄: 0-发生错误
/* fileClose -关闭文件 */
long fileClose (dword fileHandle);
/* fileGetString-从指定文件读取字符串 */
long fileGetString (char buff[], long buffsize, dword fileHandle);
参数:
buff: 用于读出的字符串缓冲区
buffsize: 字符串长度
fileHandle: 文件句柄

3. 代码

/*@!Encoding:936*/
includes
{
  
}

variables
{

}

on preStart
{
  write("ECU1");
}

on start
{
  dword fileHandle;
  char buffer[64];
  
  fileHandle = openFileRead("capl.txt", 0); 
  if (fileHandle != 0) 
  {
    while (fileGetString(buffer,9,fileHandle) !=0) //读取8个字符串
    {
      write("%s", buffer);
    }
  }
  fileClose (fileHandle);
}

读取8个字符串为什么参数为9?
Characters are read until the end of line is reached or the number of read characters is equal to buffsize -1.
The end of line is marked either.
读取字符,直到到达行尾,或者读取的字符数等于buffsize -1。

4. 测试

1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lljwork2021

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值