LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event from VB.net DLL

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

 

Download All
0 Kudos
Message 1 of 5
(4,170 Views)

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.

0 Kudos
Message 2 of 5
(4,168 Views)

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!

Miriam
Field Applications Engineer
NI Colombia
CLD
0 Kudos
Message 3 of 5
(4,141 Views)

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:

  • visual basic dll that grabs data from a serial port, finds a pre-defined packet structure, looks for errors, and then hands it off to the lab veiw application by triggering an event to say the packet is ready.
  • labview vi that demonstrates handling an event from a DLL.

 

It all needs a bit of cleanup but it works.

 

 

 

0 Kudos
Message 4 of 5
(4,124 Views)

One other note on the DLL is you need .NET 4.0

0 Kudos
Message 5 of 5
(4,122 Views)