jay
jay

Reputation: 21

how to "receive" .net struct in labview

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

The labview sketch

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...

Upvotes: 0

Views: 68

Answers (1)

jay
jay

Reputation: 21

So I was able to figure it out - finally - looks like Labview documentation goes out of it's way to make things complicated :-(. I kept seeing answers about clusters etc but it seems you just need to instantiate the struct object, pass that along and then read it.

Also when you rebuild the DLL is Labview is open there is no way to refresh the DLL you need to exit Labview and reload the project - I think this was part of my issue...

Anyways here's the modified DLL and also the accompanying Labview Sketch - in case it helps someone out...

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,ref int myIntParam)    
        {
            data1.myInt = 21;
            data1.myStr = "test string";
            myIntParam = 5;
            return data1.myInt;

        }


        public int arrayMethod(ref myStruct[] dataArr)
        {

            dataArr[0].myInt = 0;
            dataArr[0].myStr = "Zero";

            dataArr[1].myInt = 1;
            dataArr[1].myStr = "One";

            return dataArr.Length;
        }



    }

}
 

Updated Labview Sketch

Upvotes: 1

Related Questions