Baby-LIN不使用ldf文件进行测试

原文链接: https://mp.weixin.qq.com/s/Vmdi0OQjaye6BVTYFQuDSw

BabyLIN设备搭配功能强大的sdf文件使用虽然很方便,但有些测试的场合也需要LIN设备支持一些简单方便的测试手段,同样我们的BabyLIN设备也能满足这样的要求。下面将以一个测试为例,按照步骤叙述测试的方法。

下面会提供两种方法:1.使用LINworks中的SimpleMenu软件;2.使用二次开发进行编程(C语言例程)。它们的思路都是相近的。

第一步:在SimpleMenu软件中,首先需要按照下图要求,打开LIN通道的Channelshell。

第二步:在channelshell中输入两行指令。

mon_init 10417 1//初始化,10417为需要使用的波特率,可以更改。

mon_on 0xC0000000 1//过滤器,将接收全部帧的内容。

 第三步:将需要的帧或帧头发送到LIN总线。

//发送单帧,checksum为enhanced类型,ID为0x03,长度为4,内容为0x01 0x02 0x03 0x04

inject 0x02 0x03 4 [1 2 3 4] 0 0

//发送帧头,checksum为enhanced类型,ID为0x00,长度为4

inject 0x06 0x00 4 [] 0 0

如图可以看到发送的指令和总线上的实际情况。由于被测件从被唤醒到进入工作状态需要一定的启动时间,所以开始的时候第一帧是没有收到内容的。

通过以上的步骤就可以完成简单的收发内容,也不需要ldf和配置sdf文件。

C程序示例如下,方便阅读已经删掉了错误处理的部分:

#include <stdio.h>

#include "BabyLINCAN.h"

#include "windows.h"

void main(int argc, char* argv[])

{

         int major, minor;

         const char* version;

         int rc;

         int size;

         BLC_PORTINFO portInfo;

         BL_HANDLE blHandle;

         BL_HANDLE chHandle;

         BLC_FRAME framedata;

         // get BabyLIN DLL version

         BLC_getVersion(&major, &minor);

         version = BLC_getVersionString();

         printf("v%d.%d, %s\n", major, minor, version);

         // get an available BabyLIN

         size = 1;

         rc = BLC_getBabyLinPorts(&portInfo, &size);

         // open connection to BabyLIN

         blHandle = BLC_open(portInfo.portNr);

         printf("Opened BabyLIN found\n");

         //get channel handle

         chHandle = BLC_getChannelHandle(blHandle, 1);

         // start monitor mode

         rc = BLC_sendCommand(chHandle, "mon_init 10417 1");

         rc = BLC_sendCommand(chHandle, "mon_on 0xC0000000 1");

         for (int i = 0; i < 5; i++)

         {

                   Sleep(200);

                   // send frame

                   rc = BLC_sendCommand(chHandle, "inject 0x06 0x00 4 [] 0 0");               

                   //read frame

                   rc = BLC_getNextFrame(chHandle, &framedata);

                   if (rc != BL_OK)

                   {

                            printf("Could not get data. BLC_getNextFrame: %d\n", rc);

                            continue;

                   }

                   printf("ID:0x%02x  data: ", framedata.frameId);

                   for (size_t i = 0; i < framedata.lenOfData; i++)

                   {

                            printf("0x%02x ", framedata.frameData[i]);

                   }

                   printf("\n");

         }

         rc = BLC_close(blHandle);

}

本文转自虹科汽车电子微信公众号“虹科汽车电子”

猜你喜欢

转载自blog.csdn.net/HongkeTraining/article/details/100663421
今日推荐