我正在编写一个必须使用C ++的概念证明,而我却陷入了半途工作代码的困境。我已经看过AN-AND-1-117和CANoe的在线文档。它们只有VB.NET和C#而不是C ++的例子。
该代码应该:1。启动CANoe 2.加载特定的.cfg文件3.在CANoe内启动测量(例如闪电)4。将特定值写入特定消息::仅在两条支持的总线之一上发出信号。
我不知道如何完成4)。通过无耻地利用来自meler和Tomas项目的代码1)-3)工作(非常感谢!!!)。
我的第一个想法是反映代码如何为“measure”命令工作
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,巴士......
#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();
}
发布于 2018-09-21 09:42:26
如果您查看您看到的文档,从应用程序获取总线需要总线名称。然后返回值是实现IBus接口的对象。
所以电话应该是这样的:
pApp->get_Bus(L"CAN1", &busDisp);
busDisp
然后可以将现有代码分配给bus
您,并且可以调用方法IBus
。
https://stackoverflow.com/questions/-100002706
复制相似问题