08-14-2008 11:04 AM
08-14-2008 02:24 PM
08-14-2008 03:17 PM - edited 08-14-2008 03:18 PM
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
08-15-2008 09:34 AM
11-01-2011 02:35 PM - edited 11-01-2011 02:40 PM
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.
11-02-2011 05:19 PM
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
11-03-2011 05:43 AM
Travis:
The link you supplied references LabWindows/CVI. Is the same true for LabVIEW?
11-03-2011 01:55 PM
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
11-03-2011 02:36 PM
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...
11-03-2011 03:46 PM
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