在CANoe和VC.net相结合---入门(1)

入门学习,备忘录

 

通过C/C++调用 CCL.cpp函数接口,生成dll文件。

在canoe中运行dll文件

1.在vs2015中新建VC.net工程

2.将Vector\CANoe\Sample Configurations 12.0.75\Programming\C_Library\CCL文件复制vs工程

3.配置VS工程

在CANoe和VC.net相结合---入门(1)

 

4.在vs工程中加入小程序测试

功能:ID自增测试&输出固定ID

#include"../CCL/CCL.h"
#include"../User_HEAD/uesr_head.h" //自定义头文件

uint16 gTimerID_IdADD;//设置timer ID
uint16 gTimerID_Stand0x400;


//cclTimerCreate形参为 void *func (long long time, int timerID)
void  userOnTimeIdAdd(long long time, int timerID)
{
    uint8 CANchannel = 1;  //设置can 通道
    uint16 id = 0x00;
    uint16 flags = 0;
    int16 dlc = 8;
    uint8 data[8] = { 0x40,0x02,0x00,0x00,0x00,0x00,0x00,0x00 };
    int16 rc;
    static uint16 count = 0x00;

    count = count + 1;
    if (count > 0x7FF)
    {
        count = 0x00;
    }
    id = id + count;//实现ID的递加操作
    if (id >= 0x7FF)
    {
        id = 0x00;
        cclWrite("userOnTimeIdAdd`s  id > 0x7FF! ");
    }
    rc = cclCanOutputMessage(CANchannel,id,flags,dlc,data);//类似capl中的output()
    rc = cclTimerSet(gTimerID_IdADD,cclTimeMilliseconds(2));//设置定时器
}

void  userOnTimeStand0x400(long long time, int timerID)
{
    uint8 CANchannel = 2;  //设置can 通道
    uint16 id = cclCanMakeStandardIdentifier(0x400);
    uint16 flags = 0;
    int16 dlc = 8;
    uint8 data[8] = { 0x40,0x02,0x00,0x00,0x00,0x00,0x00,0x00 };
    int16 rc;
    
    rc = cclCanOutputMessage(CANchannel, id, flags, dlc, data);//类似capl中的output()
    rc = cclTimerSet(gTimerID_Stand0x400, cclTimeMilliseconds(100));//设置定时器
}

void  userPreStart()
{
    cclWrite("Now userPreStart is beging.......");
    gTimerID_IdADD = cclTimerCreate(&userOnTimeIdAdd); //创建自定义定时器1
    gTimerID_Stand0x400 = cclTimerCreate(&userOnTimeStand0x400);//创建自定义定时器2
}

void userStart()
{
    cclWrite("Now userStart is beging......");
    uint16 rc;
    rc = cclTimerSet(gTimerID_IdADD,cclTimeMilliseconds(2)); //启动定时器
    rc = cclTimerSet(gTimerID_Stand0x400,cclTimeMilliseconds(100)); //启动自定义定时器
}
/******************************************************************/
//该函数是CCL库的入口函数,暂且当做main函数吧
//
//注意函数名字母大小写
/*****************************************************************/
void cclOnDllLoad()
{
     //调用preStart函数
    cclSetMeasurementPreStartHandler(userPreStart); //传入自定义预初始化函数。和capl的prestar函数一样
    //调用Start函数
    cclSetMeasurementStartHandler(userStart); //传入自定初始化函数。capl的start函数
}

5.配置canoe

在CANoe和VC.net相结合---入门(1)

6.运行结果

在CANoe和VC.net相结合---入门(1)