LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NET Delegate

I'm wondering if anyone has found a way to create a delegate constructor in LabVIEW. I read a post awhile ago saying delegates could be used but only in certain situations. Looking at the NET Event Callback for DataWatcher in LabVIEW examples, there is a public delegate called "EventHappenedDelegate". The inputs for the constructor are "object" (System.Object) and "method" (System.IntPtr). If it is possible to create a delegate constructor, what would you input for these two inputs?
Message 1 of 10
(5,649 Views)
I'm not sure I understand what you're trying to accomplish. Why do you need to instantiate the delegate? A delegate isn't like a class. What are you trying to do?
0 Kudos
Message 2 of 10
(5,635 Views)

Alright, let me try to explain in full what I'm trying to do, it's not really related to the DataWatcher example except it involvers delegates. I have been given some DLL's, an API for them, and some example code. Here is a snippett of the example code I'm trying to convert to LabVIEW:

 public void ReadData()

{

Device b = new Device()
;

//Get addresses we're interested in

 ushort[] addresses = new ushort[] {(ushort)(RegisterAddress.NITRxBytes),

(ushort)(RegisterAddress.NITTxBytes),(

ushort)(RegisterAddress.NITRxBufferOverflowErrors)};

subscriptionID = b.Subscribe(addresses, 5, new DataArrivedEventHandler(UpdateData));

}

 

private void UpdateData(object sender, DataArrivedEventArgs e)

{

Console.WriteLine("Inspector: source (" + e.Source.ToString() + ") changed to " + e.Value.ToString());

}

 

You can see that the method b.Subscribe requires a DataArrivedEventHandler, which is a delegate to the UpdateData method. The UpdateData method I will actually customize so that the data is read into LabVIEW, instead of being written to the console like it is now. So when I create a constructor for the DataArrivedEventHandler, which is input into the Subscribe method, it has the two inputs I spoke of in the first post, "object" and "method", which I'm lost as to what to do with. Should I create my UpdateData method in C#, create a DLL, and make a constructor from that in LabVIEW? I'm not so sure from there what to put into "object" and "method".

 

Michael

Message Edited by miguelc on 08-14-2008 03:18 PM
Message 3 of 10
(5,631 Views)
It seems that you are trying to use delegates in the "raw" form - in other words delegates to methods. As far as I know, up to LabVIEW 8.2 you cannot do this in LabVIEW. I have no idea if this has changed with 8.5 or 8.6. If you can have the class register the delegate via an event then you can do it that way.
Message 4 of 10
(5,620 Views)

Does anyone know if this has changed?  I'm running into a similar problem with a .NET implementation of WinPcap.  I have a delegate which is used to notify when a packet is received.  I want to register it as a callback, but LabVIEW doesn't understand how to connect to it.

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 5 of 10
(4,946 Views)

Hi Joe,

 

For versions of LV 8.5 and greater there is some more support for .NET events and delegates. Here you can find some documentation about that upgrade:  http://digital.ni.com/public.nsf/allkb/346E949235C54BA086257234005607E0?OpenDocument. However, LV Register Event Callback can only generate correct callback VIs when the arguments of .NET delegate are of primitive data types, e.g., string, double, etc.

 

I hope you find this information useful.

 

Regards,

Travis Ann Nylin

Customer Education Product Marketing Manager
National Instruments
0 Kudos
Message 6 of 10
(4,916 Views)

Travis:

 

The link you supplied references LabWindows/CVI.  Is the same true for LabVIEW?

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 7 of 10
(4,908 Views)

Hi Joe,

 

You are right, and I'm sorry about that wrong link. There have been some updates since versions of LV before 8.5. However,  LabVIEW still doesn't support delegates in the raw form. This document, http://zone.ni.com/reference/en-XX/help/371361D-01/lvcomm/reg_event_callback/, describes the functionality of Register Event Callback.  LV Register Event Callback can only generate correct callback VIs when the arguments of .NET delegate are of primitive data types, e.g., string, double, etc. Also, there is a discussion forum thread that talks more about this and even has an example. http://forums.ni.com/t5/LabVIEW/Does-LabVIEW-8-support-use-of-net-deligates/td-p/437124 

 

Once again, sorry for the wrong link and I hope this helps. 

 

Regards,

Travis Ann

 

Customer Education Product Marketing Manager
National Instruments
Message 8 of 10
(4,900 Views)

Travis Ann:

 

The last link above that you provided is one that I have not read.

 

I guess I need to go find a C# developer to put a wrapper around the delegate to make it into an event that I can capture in LabVIEW...

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 9 of 10
(4,896 Views)

Hey Joe,

 

It sounds like you are on the right track. Give that a read and let us know if you have anymore issues.

 

Regards,

Travis Ann

Customer Education Product Marketing Manager
National Instruments
0 Kudos
Message 10 of 10
(4,886 Views)