Discussion:
NET Delegate
(too old to reply)
miguelc
2008-08-14 16:10:08 UTC
Permalink
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?


NET Event Callback for DataWatcher.vi:
http://forums.ni.com/ni/attachments/ni/170/349329/1/NET Event Callback for DataWatcher.vi
smercurio_fc
2008-08-14 19:40:07 UTC
Permalink
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?
miguelc
2008-08-14 20:40:06 UTC
Permalink
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". MichaelMessage Edited by miguelc on 08-14-2008 03:18 PM
smercurio_fc
2008-08-15 14:40:23 UTC
Permalink
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.
Continue reading on narkive:
Loading...