VFlash的自动化和自定义动作

一、automation 自动化

官方示例路径:C:\Users\Public\Documents\Vector\vFlash\10\Examples\Automation\vFlashAutomation

使用 VFlash Automation 需要有能刷写成功的工程。在 VFlash 中将工程保存为 Pack&Go 工程,文件后缀名为 .vflashpack

二、custom actions 自定义动作

官方示例路径:C:\Users\Public\Documents\Vector\vFlash\10\Examples\CustomActions

  1. 根据上方参考地址,或者参考下图找到官方示例
    在这里插入图片描述
  2. CustomActionAttributes 示例工程为例,首先将该工程下的CDD文件替换为自己实际使用的CDD文件
    在这里插入图片描述
  3. 主要关注Execute 函数的实现,该函数实现的内容即为 Pre Action 或者 Post Action 执行的内容
    在这里插入图片描述
  4. 获取可发送诊断请求的ECU对象
// Get ECU object to which diagnostic requests can be sent
Ecu ecu = Application.GetEcu();
  1. 发送诊断请求
using (Request request = ecu.CreateRequest("ExtendedDiagnosticSession_Start"))
{
  request.Send();
}
  1. 读取DID
 private static string ReadSoftwareVersionFromEcu(Ecu ecu)
 {
// ---------------------------------------------------------
// Service: Software_Version_Read (Signature: [0x] 22 F1 89)
// ---------------------------------------------------------
{
  using (Request request = ecu.CreateRequest("Software_Version_Read"))
  {
    // Send the request
    SendResult result = request.Send();
    if (result.Status == SendStatus.Ok)
    {
      // Get the response
      using (Response response = result.Response)
      {
        if (response != null && response.IsPositive)
        {
          // Get parameter "SoftwareVersion" from response
          Parameter softwareVersionParam = response.GetParameter("SoftwareVersion");
          if (softwareVersionParam != null)
          {
            return softwareVersionParam.Value.ToString(); // parameter value: "1.0.0"
          }
        }
      }
    }
  }
}}

常用方法

  • controlHandle.SkipFlashing = true;:跳过刷写

如何选择要发送的诊断请求

当要发送诊断请求时,需要调用ecu.CreateRequest("ExtendedDiagnosticSession_Start"),传入的参数为字符串,而字符串则代表了我们需要发送的诊断请求。

字符串主要分为两部分:Name_Supported Service
在这里插入图片描述
字符串中不能有空格,当Name中包含空格时,使用下划线
当调用 response.GetParameter("SoftwareVersion") 时,同样字符串中不能有空格,当Name中包含空格时,需要删除空格

CustomActionValueList 作用

在一个 vFlash 项目中,自定义操作值列表CustomActionValueList的标识符应该是唯一的。
用户可以通过 VFlash 设置其值,例如创建如下标识符:

[CustomActionValueList("Skip flashing if voltage is low", new[] { "Yes", "No" }, DefaultSelection = "No" ]

在这里插入图片描述

// 获取值
customActionConfig.CustomActionValueListContainer.GetCustomActionValueList("Skip flashing if voltage is low").Selection;

Pre Action和Post Action之间交换信息

通过 CustomActionAttribute需要注意的是,在 PreAction.cs中定义后,在PostAction.cs 不能重复定义,否则会导致不能获得 PreAction.cs 设置的值。

[CustomActionAttribute("Type Identifier", CustomActionAttributeType.AsciiString, VisibleInUi = true)]

VisibleInUi = true 表示在 VFlash 窗口中显示
在这里插入图片描述

// 获取信息
string cATypeIdentifier = customActionConfig.CustomActionAttributeContainer.GetCustomActionAttribute("Type Identifier").ToString();
// 打印信息
Output.WriteLine(cATypeIdentifier);
// 修改信息
customActionConfig.CustomActionAttributeContainer.GetCustomActionAttribute("Type Identifier").Set("demo");
// 获取信息
cATypeIdentifier = customActionConfig.CustomActionAttributeContainer.GetCustomActionAttribute("Type Identifier").ToString();
// 打印信息
Output.WriteLine(cATypeIdentifier);

CreateRequest 和 GetParameter 函数的参数说明

最好CDD中命名不能使用特殊字符,避免使用空格

1.CreateRequest 的参数

CreateRequest 函数的参数主要看 CDD的这个位置:
在这里插入图片描述

1.1 $10 Service
如果命名中带空格的话需要 删除空格

using (Request request = ecu.CreateRequest("ExtendedDiagnosticSession_Start"))
{
    result = request.Send();
}

在这里插入图片描述

1.2 $22 Service
如果命名中带空格的话需要 替换为下划线

using (Request request = ecu.CreateRequest("Serial_Number_Read"))
{
    result = request.Send();
}

在这里插入图片描述
1.3 $31 Service
如果命名中带空格的话需要 替换为下划线
如果Supported Service命名中带空格的话需要 删除空格

using (Request request = ecu.CreateRequest("HV_DeactivateDisable_Read"))
{
    result = request.Send();
}

using (Request request = ecu.CreateRequest("HV_DeactivateDisable_RequestResults"))
{
    result = request.Send();
}

在这里插入图片描述

2.GetParameter 的参数

GetParameter 函数的参数主要看 CDD的这个位置:
在这里插入图片描述
另外根据配置的Date Type不同,获取的返回值类型也不同,可能是int型,也可能是 string
在这里插入图片描述

2.1 $22 Service

Parameter thresholdVoltageParam = response.GetParameter("SerialNumber");
if (thresholdVoltageParam != null)
    {
        return thresholdVoltageParam.Value.ToString();
}

2.1 $31 Service

Parameter HVStatus = response.GetParameter("HVState");
if (HVStatus != null)
{
    // 获取返回值的数组类型 HVStatus.Value.GetBytes()
    if (HVStatus.Value.GetBytes()[0] == 0x01)
    {
        return 1;
    }
}

提示:如何打印软件中变量

1.使用 Output.WriteLine("string"); 但是该函数只能打印 String 类型,显示信息在如下界面

在这里插入图片描述

2.使用 Report.WriteLine(" Channel Type: {0}", channelType); ,其打印信息将在 vflash 的 report中显示,report 首先要 enable
在这里插入图片描述

提示:自定义报文发送

1. 自定义报文内容

SendResult result;
int res_len; // 响应PDU的数组长度
var a = new byte[] {0x10, 0x03 };
using (Request request = ecu.CreateRequest(a)) {
    result = request.Send();
}
if (result.Status == SendStatus.Ok) {
    // Get the response
    using (Response response = result.Response) {
        if (response != null && response.IsPositive) {
            res_len = response.Pdu.Length;
            var res = new byte[res_len];
            // Pdu 里面的内容为报文响应值,例如:50 03 00 32 00 C3
            for (int i = 0; i < res_len; i++) {
                res[i] = response.Pdu[i];
                Report.WriteLine(" Channel Type: {0}", res[i]);
            }
        }
    }
}

2.自定义报文ID等
参考官方demo():C:\Users\Public\Documents\Vector\vFlash\10\Examples\CustomActions\RawCANMessageSending

提示:visual studio 关闭自动调整代码格式

依次点击“工具——选项——文本编辑器——C#(选择对应语言)——代码样式——格式设置”,在“格式设置中进行相应设置
在这里插入图片描述

报错:无法打开源文件 Windows.h stdio.h conio.h

依次点击“项目——配置属性——C/C++——常规”,在“附加包含目录”中加入.h文件所在的文件夹路径
在这里插入图片描述

报错:找不到 Windows SDK 版本 10.0.17763.0

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值