问题
我正在尝试调用 CAPL 通用函数(在我的例子中是 timeNowNS),但我不知道这是否可行。
我在用什么?
我正在使用 Python 3.7 和 Vector CANoe 11.0。
连接是使用 .NET CANoe API 完成的。 这就是我访问 DLL 的方式。
import clr
sys.path.append("C:\Program Files\Vector CANoe 11.0\Exec64") # path to CANoe DLL Files
clr.AddReference('Vector.CANoe.Interop') # add reference to .NET DLL file
import CANoe # import namespace from DLL file
我尝试了什么?
我成功打开了 CANoe 仿真,开始了测量,并且我可以访问信号、环境变量和系统变量。
然后我创建了 CAPL 对象并尝试使用 GetFunction 方法来获取 CAPLFunction 对象以便调用它。
def begin_can(self, sCfgFile, fPrjInitFunc = None):
self.open_can()
self.load_can_configuration(sCfgFile)
self.start_can_measurement(fPrjInitFunc)
def open_can(self):
self.mCANoeApp = CANoe.Application()
self.mCANoeMeasurement = CANoe.Measurement(self.mCANoeApp.Measurement)
self.mCANoeEnv = CANoe.Environment(self.mCANoeApp.Environment)
self.mCANoeBus = CANoe.Bus(self.mCANoeApp.get_Bus("CAN"))
self.mCANoeSys = CANoe.System(self.mCANoeApp.System)
self.mCANoeNamespaces = CANoe.Namespaces(self.mCANoeSys.Namespaces)
self.mCANoeCAPL = CANoe.CAPL(self.mCANoeApp.CAPL)
self.mCANoeCAPL.Compile()
def getFunction(self):
function1 = self.mCANoeCAPL.GetFunction('timeNowNS')
# here I tried also CANoe.CAPLFunction(self.mCANoeCAPL.GetFunction('timeNowNS'))
# but i got attribute error: doesn't exist or something like that
result = function1.Call()
预期结果
我应该使用此函数获取当前模拟时间。
实际结果
使用上面的代码我得到:
**COMException**: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at CANoe.ICAPL5.GetFunction(String Name)
我尝试了不同的代码变体,但没有成功。
有没有可能是硬件问题? 我是否应该在 CANoe Simulation 中进行一些设置?
如果您需要更多信息,请问我!提前致谢
更新:我在添加 CAPL block 后添加了我的测量设置的照片
请您参考如下方法:
您必须编写一个调用 timeNowNS 的 CAPL 函数。然后可以按照您实现的方式从 Python 调用此 CAPL 函数。
GetFunction 仅适用于(用户编写的)CAPL 函数。您不能直接调用 CAPL 内在函数(即内置 CAPL 函数)。
将其放入 CAPL 文件中:
int MyFunc()
{
return timeNowNS();
}
然后从 Python 中这样调用:
def getFunction(self):
function1 = self.mCANoeCAPL.GetFunction('MyFunc')
result = function1.Call()
