LabView:如何使用“调用方法”将参数传递给 .NET 方法六?

发布于 2024-09-29 17:44:28 字数 1179 浏览 0 评论 0原文

我有一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭水袖舞倾城 2024-10-06 17:44:28

我想我明白了!显然,vi 文件本身发生了一些有趣的事情。如果存在定义了程序集的 .NET 构造函数节点,则在 Visual Studio 中重建程序集并更新构造函数节点不会对导入的方法签名产生影响。因此,MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str) 是看不到的。

因此,对我有用的是:

  1. 我从 vi 中删除了 *Constructor Node* 和 *Invoke Node*,然后保存。
  2. 要将整数值传递给 MyMethode 这里是对我有用的方法定义:
    MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
    
    我认为我在 LabView 中看到的“ValueType”术语意味着它需要 Int32 的值类型。

当您重建 .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:

  1. I deleted *Constructor Node* and *Invoke Node* from vi, then saved.
  2. To pass integer values to MyMethode here is the method definition that worked for me:
    MyMethod(System::Int32 number1, System::Int32 number2, System::String^ str)
    

    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文