Jump to content

how to "recieve" .net struct in labview


Recommended Posts

Posted

I am creating a .net DLL for a customer who will be using it in labview

The method signature that I would like is

int RequestData(ref myStruct[] data1)

The customer who might not be very familiar with .net dll's is unable to figure out a way to invoke this...

so I have been trying to figure it out using the labview community edition.

Step 1 was to just see if I could pass a "ref" struct back to Labview... and here's my dll code for that and the labview sketch...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace clusterPassing
{

    public struct myStruct            
    {

        public string myStr;

        public int myInt;

    }

    public class myClass           
    {



        public int myMethod( ref myStruct data1)   
        {
            data1.myInt = 21;
            data1.myStr = "test string";
           
            return data1.myInt;

        }





    }

}

The labview sketch is attached 

 

In the dll code if I change the input to myStruct data1 (without the ref) I am able to invoke it but once I make it ref (as shown in the code) I get an error - 1316

Question: Is there a way to allow for labview to exchange a struct and get the value back from the .net method? I have been reading up on clusters in labview but am not sure if this is possible yet...

 

 

 

labview.png

Posted

Welcome to the LAVA!

14 hours ago, jayfly said:

Is there a way to allow for labview to exchange a struct and get the value back from the .net method?

Wire your struct to a Property Node to access public properties and fields. You can set it to either read or write a value.

image.png.f7225049a47b6e64fa2d4300f79ed640.png

14 hours ago, jayfly said:

In the dll code if I change the input to myStruct data1 (without the ref) I am able to invoke it but once I make it ref (as shown in the code) I get an error - 1316

Please be careful when changing signatures. LabVIEW does not automatically detect when the type of an argument changes. You'll have to manually update all calling sites to match the new signature which can lead to bad behavior.

That said, calling by ref or by value both work. Here is a complete example for both of them:

namespace DemoLib
{
    public struct MyStruct
    {
        public string Message { get; set; }

        public int Number { get; set; }
    }
  
    public class MyClass
    {
        public string GetMessage(MyStruct data)
        {
            return data.Message;
        }

        public int GetNumber(MyStruct data)
        {
            return data.Number;
        }

        public string CreateMessageByRef(ref MyStruct data)
        {
            data.Message = "Hello from CreateMessageByRef";
            return data.Message;
        }

        public int CreateNumberByRef(ref MyStruct data)
        {
            data.Number = 42;
            return data.Number;
        }
    }
}

image.png.c36aef6f790a1c9cd070c9c8c2608824.png

Example.vi

  • Like 1
Posted

@LogMAN Thanks for the example - was able to get it working!  Yes looks like when updating the DLL only way for me to make it work was to shutdown Labview, restart and then add the DLL again otherwise it appeared to somehow get the stale copy.

 

 

Posted

Glad to hear you got it working!

The reason it doesn't update is explained in the documentation: https://www.ni.com/docs/en-US/bundle/labview/page/loading-net-assemblies.html#d62572e60

Quote

After LabVIEW loads an assembly into memory, the assembly stays in memory until you close the application instance that loaded the assembly. While an assembly is in memory, LabVIEW does not detect changes that you make to the assembly on disk. Therefore, before LabVIEW can access any changes to the assembly, you must update the assembly version in memory.

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.