10-21-2011 12:53 PM
Hi,
I am trying to handle an event from a DLL written in VB.net(2010). Below is the VB code. I can't quite figure out how to handle the event in the LabVIEW vi. I have spent a day going thru examples and other forum discussions on this and have hit a dead end. I can see that the DLL event is occurring but I am stumped on how to handle it in LabVIEW.
What the end goal will be is to receive an asynchronous packet from a serial port. In the end the DLL will collect a packet of data and then hand it off to the LabVIEW app when ready.
Files are attached for vi's and DLL(zipped).
Thanks in advance.
Imports System Imports System.Threading Imports System.IO.Ports Public Class testC Dim test As Integer = 5 Public Event NewTimeExpired(ByVal Status As Integer) Private readThread As Thread = New Thread(AddressOf Read) Delegate Sub SetTextCallback(ByVal [text] As String) Public Property outputB() As Integer Get Return test End Get Set(ByVal value As Integer) test = value End Set End Property Public Function foo() As Integer() Dim returnArray(3) As Integer returnArray(0) = test + 1 returnArray(1) = test + 2 returnArray(2) = test + 3 Return returnArray End Function Public Sub RaiseTimeExpiredEvent() RaiseEvent NewTimeExpired("Your time has run out") End Sub Public Sub New() Dim readThread As Thread = New Thread(AddressOf Read) readThread.IsBackground = True readThread.Start() End Sub Private Sub Read() While (1) test = test + 1 RaiseEvent NewTimeExpired(test) Thread.Sleep(500) End While End Sub End Class
10-21-2011 01:22 PM
Is your callback VI called? My favorite simple way to find out is to put a one-button dialog box in that VI temporarily; if it pops up, then the callback executed. Are you asking how to get data back to your main program after the callback executes, or does your callback VI not run at all? If you're trying to pass data back, one common approach is to wire a notifier, queue, or user event refnum as the User Parameter. The callback then send a notification, enqueues a value, or generates a user event, which signals to your main program that the callback ran.
10-26-2011 03:16 PM
Hey newbananas,
I've been trying to troubleshoot your VI but I can't run the dll, would you uploaded again compiled for a previous version of VB.net if possible. I'm trying to recreate your code but when I create the .net object it doesnt identifies the DLL as a .net object.
Thanks!
10-28-2011 10:37 AM
Thanks to Nathand for the suggestion on the notifier. That was what I needed.
Also thanks to Mariam for looking into this.
I have attached the completed code as an example if anyone needs it.
Attached in a zip is:
It all needs a bit of cleanup but it works.
10-28-2011 10:38 AM
One other note on the DLL is you need .NET 4.0