LabView:如何使用“调用方法”将参数传递给 .NET 方法六?
我有一个用 C++ 编写的 .NET 类库。 “public ref class MyClass”定义了一个方法“MyMethod”,它采用两个 System::Int32 参数。
首先是 MyClass,然后是我的问题:
namespace MyNetAssembly {
public ref class MyClassThatDoesStuff
{
public:
MyClassThatDoesStuff();
void MyMethod(System::Int32^ number1, System::Int32^ number2);
property System::Int32 MyProperty{
int get (){
return *_result;
}
void set(System::Int32 value){
}
}
private:
int^ _result;
};
}
这是 cpp 代码:
MyNetAssembly::MyClassThatDoesStuff::MyClassThatDoesStuff()
{
*_result = 0;
}
void MyNetAssembly::MyClassThatDoesStuff::MyMethod(System::Int32^ number1, System::Int32^ number2)
{
*_result =(*number1 + *number2) * 100;
}
当我使用“构造函数节点”vi 从 LabView 8.5 加载此程序集时。然后,我尝试使用“Invoke Method”vi 调用 MyMethod(),我将方法的参数设为“ValuteType”,而不是“Int32”,因为我希望直接与 LabView 常量和控件一起使用。相反,当我通过右键单击参数的连接器创建常量时,我得到“.NET 对象”!
请问,如何让LabView识别参数类型?
注意:我尝试将参数从 System::Int32^ number1
更改为 System::Int32 number1
。这也没有帮助。
I have a .NET class library that I wrote in C++. "public ref class MyClass" defines a method "MyMethod" that takes two System::Int32 parameters.
Here is MyClass first then my question:
namespace MyNetAssembly {
public ref class MyClassThatDoesStuff
{
public:
MyClassThatDoesStuff();
void MyMethod(System::Int32^ number1, System::Int32^ number2);
property System::Int32 MyProperty{
int get (){
return *_result;
}
void set(System::Int32 value){
}
}
private:
int^ _result;
};
}
Here is the cpp code:
MyNetAssembly::MyClassThatDoesStuff::MyClassThatDoesStuff()
{
*_result = 0;
}
void MyNetAssembly::MyClassThatDoesStuff::MyMethod(System::Int32^ number1, System::Int32^ number2)
{
*_result =(*number1 + *number2) * 100;
}
When I load this assembly from LabView 8.5 using "Constructor Node" vi. Then, I try to invoke MyMethod() using an "Invoke Method" vi, I get the parameters to the method to be of "ValuteType" and not "Int32" as I expect to use directly with LabView constants and controls. Rather, when I create a constant by right clicking on the connector for the parameter, I get ".NET Object"!
Please, How can I get LabView to recognize parameter types?
Note: I tried to change parameters from System::Int32^ number1
to System::Int32 number1
. That did not help either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我明白了!显然,vi 文件本身发生了一些有趣的事情。如果存在定义了程序集的 .NET 构造函数节点,则在 Visual Studio 中重建程序集并更新构造函数节点不会对导入的方法签名产生影响。因此,
MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
是看不到的。因此,对我有用的是:
MyMethode
这里是对我有用的方法定义:当您重建 .NET 程序集时,LabView 让您感觉它已经完全更新了自身,这可能会令人困惑。
感谢所有提供帮助的人。我希望我的回答对使用 .NET 和 LabView 的其他人有所帮助。
I think I figured it out! Apparently, there is something funny happens within the vi file itself. If there is a .NET Constructor Node with an assembly defined, then rebuilding the assembly in Visual Studio and updating the Constructor Node does not have an effect over imported method signatures. Therefore,
MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
was no were to be seen.So, what worked for me is the following:
MyMethode
here is the method definition that worked for me:I think the "ValueType" term I saw in LabView means that it requires a value type for Int32.
It can be confusing when LabView have you under the impression that it has completely updated itself when you rebuild your .NET Assembly.
Thanks to everyone who helped. I hope my answer is helpful to anyone else who is working with .NET and LabView.