LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.Net Event Handling

I am using Labview 8.0. I have 2 simple C# classes which I wish to use to learn how to link the
.Net events with Labview. I have found some examples but do not understand them fully when
using with custom .Net DLLs.
 
Class CreatingEventClass.dll creates my event and delegate.
    public class MyEventArgs : EventArgs{
        public string m_id;
    }
    public delegate void MyHandler(object sender, MyEventArgs e);
    public class CreatingEventClass{
        public event MyHandler Clicker;
        public CreatingEventClass()
        {}
        public void InvokeMe(){
            MyEventArgs mea = new MyEventArgs();
            mea.m_id = "I am Event Arg";
            Clicker.Invoke(this,mea);
        }
    }
ClassRegisteringEvent.dll creates,registers and invokes the CreatingEventClass
    public class RegisteringEvents{
        private string myvalue;
        public string Anyvalue{
            get{
                return myvalue;
            }
            set{
                something = myvalue;
            }
        }
        private void MyFunction(object sender, MyEventArgs e){
            Console.WriteLine("I am Invoked : " + e.m_id);
        }
        public RegisteringEvents(){
            CreatingEventClass.CreatingEventClass CEC = new CreatingEventClass.CreatingEventClass();
            CEC.Clicker += new MyHandler1(MyFunction);
            CEC.InvokeMe();           
        }
      
    }
I have tried to link A.vi to the Register Event Callback in the RegisteringEvents.vi but it seems
that the connection type is incompatible. How would I link or make it so that when the event is
fired the string box is changed. I have zipped up both the dlls and vis that i used.
 
0 Kudos
Message 1 of 6
(3,343 Views)
hi there
 
i don't have 8.0 so you have to listen to my words:
 
connect the .NET refnum to the "event source" terminal of the "Reg event callback" function, then right click on the "VI ref" terminal and then "Create callback VI". the terminals of the callback vi have to match exactly, so this is the most convenient way to create such a callback vi. save this vi as your "A.vi".
 
Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 6
(3,337 Views)
That's for the tip Chris. I have managed to get the Callback event object created. However I am still stuck on trying to get my string indicator to update itself when the event is fired.
I was expecting the string indicator to show "I am Event Arg".
 
Could anybody please show me how would I link and update the string indicator with the callback from the dll.
0 Kudos
Message 3 of 6
(3,301 Views)
Hi Jumpingjack,
 
I added a dialog box to Clicker Event Callback.vi and did not see the box pop up when running Registering Events.vi.  Please verify that the event is firing.  Under what circumstances does the event fire?
0 Kudos
Message 4 of 6
(3,272 Views)
Hi Jumpingjack,

Based off your C# code, it looks like you need to call the InvokeMe method in order to have the Clicker event fire. Your example is very similar to our example program entitled ".NET Event Callback for DataWatcher.vi" located in the NI Example Finder under Communicating with External Applications >> .NET. My guess is that eventually the user will press some button which will call the InvokeMe method which in turn fires the Clicker event.

Just make a call to the InvokeMe method and your event will fire.

Best Regards,
Jonathan N.
National Instruments
Message 5 of 6
(3,262 Views)
Thanks. Got it working now
0 Kudos
Message 6 of 6
(3,244 Views)