首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >C ++ noob需要帮助在C ++中使用CANoe COM服务器代码使用Visual Studio 2015发送总线消息(为清晰起见而编辑)[暂停]

C ++ noob需要帮助在C ++中使用CANoe COM服务器代码使用Visual Studio 2015发送总线消息(为清晰起见而编辑)[暂停]
EN

Stack Overflow用户
提问于 2018-09-21 00:41:14
回答 1查看 0关注 0票数 0

我正在编写一个必须使用C ++的概念证明,而我却陷入了半途工作代码的困境。我已经看过AN-AND-1-117和CANoe的在线文档。它们只有VB.NET和C#而不是C ++的例子。

该代码应该:1。启动CANoe 2.加载特定的.cfg文件3.在CANoe内启动测量(例如闪电)4。将特定值写入特定消息::仅在两条支持的总线之一上发出信号。

我不知道如何完成4)。通过无耻地利用来自meler和Tomas项目的代码1)-3)工作(非常感谢!!!)。

我的第一个想法是反映代码如何为“measure”命令工作

代码语言:javascript
复制
CComQIPtr<IMeasurement> measure; // Pointer to the Message Object
CComPtr<IDispatch> measureDisp; // Pointer to the Measurement Object to start and stop CANoe's simulation

我不确定哪一个使用CComQIPtr或ComPtr。

当我尝试配置指针时,还需要许多不同的Bus选项。有巴士,IBus,巴士......

代码语言:javascript
复制
#import "C:\Program Files (x86)\Vector CANoe 8.1\Exec32\COMdev\CANoe.tlb" 
//importing CANoe type library
#include <atlbase.h> //COM Server methods
#include <iostream>
#include <Windows.h>

using namespace CANoe;
using namespace std;

int _tmain(int argc, _TCHAR* argv[]){
/* b) Define variables  */
CComPtr<IApplication> pApp = NULL; // Pointer to the Application Object
CComQIPtr<IMeasurement> measure; // Pointer to the Message Object
CComPtr<IDispatch> measureDisp; // Pointer to the Measurement Object to start and stop CANoe's simulation
//
/*I need to define a .Bus Object to control the signals that already exist*/
/*  Here are the Bus variables. */
CComQIPtr<IBus> bus= NULL; //following the model for measure
CComPtr<IDispatch> busDisp;
/**/
CLSID clsid;  //globally unique identifier that identifies a COM class object
//IID iid; // right now not used
HRESULT result; //results of COM functions
DOUBLE doorStatus; //Sets the value of the Door Status
doorStatus = 2;
/* Initialization of COM library and look for errors: */
if (FAILED(CoInitialize(NULL)))
{
    cerr << "Initialization COM Library error" << endl;
    system("pause");
    return 1;
}
if ((result = CLSIDFromProgID(L"CANoe.Application", &clsid)) != S_OK) //looks like a Windows call
{
    cerr << "Problem with opening application" << endl;
    system("pause");
    return 2;
}
    /* c) Now to actually open CANoe*/
result = pApp.CoCreateInstance(clsid);  //Opening CANoe Application

/*Since CANoe is already "primed" to open the correct configuration. The above line launches CANoe 
if (result != S_OK)
    cout << "pApp fault" << endl;



// d) Start the measurement -- This does work to start and stop the measurement
pApp->get_Measurement(&measureDisp);
    measure = measureDisp;
measure->Start();

// e)
/*Now to change a signal in CANoe viaBus object
I modeled these commands to mirror the syntax of measure
*/
pApp->get_Bus(Bus); // I don't have the correct syntax for this.


cout << "CANoe running" << endl;
system("pause");
measure->Stop();
}
EN

回答 1

Stack Overflow用户

发布于 2018-09-21 09:42:26

如果您查看您看到的文档,从应用程序获取总线需要总线名称。然后返回值是实现IBus接口的对象。

所以电话应该是这样的:

代码语言:javascript
复制
pApp->get_Bus(L"CAN1", &busDisp);

busDisp然后可以将现有代码分配给bus您,并且可以调用方法IBus

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档