0

I haven't worked a lot in labview, but I know we write c# class libraries to help our labview testing. I am writing some hardware testing through a c# class library project where I am using interfaces for various equipment we interact with (load, relays, source, etc) and an abstract class for each product so that I can implement base functionality.

Now, I haven't touched labview but my googling suggests there is no reason that labview shouldn't be able to create objects of c# classes and call instanced methods? In labVIEW terms (so I can support our labVIEW guy) how do you achieve this?

Here is a code example of the architecture I have set up.

public abstract class ClassA {
    public virtual int Test() {
        /** Do some things **/
        return 0;
    }

}

public class ClassB : ClassA {
    private IDcSource source;

    public ClassB (IDcSource source)
    {
        this.source = source;
    }

    public override int Test() {
        /** Do product specific thing **/

        source.On();
        
        return base.Test();
    }
}

public interface IDcSource {
    void On();
    void Off();
}

public class dcSource1 : IDcSource {
    private int num;
    public dcSource1 (int i) {
        this.num = i;
    }

    public void On() {
        /** Turn on **/
    }

    public void Off() {
        /** Turn on **/
    }
}

In a c# console app I would do the following, allegedly this approach doesn't work in labVIEW?

ClassB product = new ClassB(new dcSource1(1));
Console.WriteLine($"Result of test {product.Test();}");

EDIT:

Furthermore, is there any reason labVIEW can't handle classes inheriting abstract classes?

1 Answers1

1

The way to do this is to make the build target a dynamic linking library (.dll). Then all you need to do is read up a (relatively) clean application note on how to link to the dll file through labview.

You should probably refer to the section Import .NET Assembly Functions with Constructor Node (although generally its a good read).


One thing I remember (from about 7 or 8 years when I was still doing something similar), was you need to pay some attention to the type of the variables, so that they play well between C# and Labview.

NMech
  • 23,917
  • 2
  • 30
  • 72
  • Hi NMech! thank your reply. I am building the C# library as a dll but the labview guy is struggling to use it. I can't confirm but he is saying it is due to the equipment interfaces I am using. You mentioned the typing issues, do you know what this s so I can research it? – Grant Dare Feb 19 '22 at 06:39
  • Basically the type of the variable should match, but also there are special consideration when you are passing by reference (but I really can't say I remember the specifics right now). – NMech Feb 19 '22 at 08:33
  • Since you have experience; could I also ask, is there a reason labview wouldn't be ok with using classes that inherit abstract classes? – Grant Dare Feb 20 '22 at 05:05
  • I am not sure if it wouldn't support abstract classes. LabVIEW native oop does inherit from abstract classes, but the oop model is different. In any case that would be better answered in a LabVIEW forum. – NMech Feb 20 '22 at 05:54
  • @GrantDare Looks like you should rather post a question with the import of the library. Looks to me like the problem is located there. – MaestroGlanz Jan 29 '23 at 17:12