Dictionary ServerConnect won't fire until KeyListener starts

Supporting Visual Studio on Windows
MarkS
Phidgetly
Posts: 39
Joined: Sat May 15, 2010 8:37 am
Location: Southeast Pennsylvania USA
Contact:

Dictionary ServerConnect won't fire until KeyListener starts

Postby MarkS » Sat Mar 24, 2012 10:16 am

I'm having a bit of trouble with the dictionary in VB.NET. I can't seem to get the ServerConnect event to fire unless I start a KeyListener first.

Here's what I started with and expected to work:

Code: Select all

Class PhidgetDictionaryTest

    Public WithEvents phDict As New Phidgets.Dictionary
    Public WithEvents phListen As New Phidgets.KeyListener(phDict, "*")

    Public Sub New()

        InitializeComponent()

        Try
            phDict.open("PhidgetWS")
        Catch ex As Phidgets.PhidgetException
            MsgBox("Phidget Exception")
        End Try
    End Sub

    Public Sub phDict_Connect(ByVal sender As Object, ByVal e As Phidgets.Events.ServerConnectEventArgs) Handles phDict.ServerConnect
        phListen.start()
    End Sub

    Private Sub phListen_KeyChange(ByVal sender As Object, ByVal e As Phidgets.Events.KeyEventArgs) Handles phListen.KeyChange
      ' key change event handler code goes here
    End Sub

End Class

Even single-stepping thru the code, the ServerConnect event never fired, so the KeyListener never activated. So I added a "wait for attachment" loop then started the KeyListener, and immediately thereafter the ServerConnect event fired. But shouldn't the ServerConnect event fire when phDict.AttachedToServer goes True?

Here's the code that "works":

Code: Select all

Class PhidgetDictionaryTest

    Public WithEvents phDict As New Phidgets.Dictionary
    Public WithEvents phListen As New Phidgets.KeyListener(phDict, "BMAC/*")
    Public WithEvents timer As New Stopwatch

    Public Sub New()
        InitializeComponent()
        ' Open the dictionary
        Try
         timer.Start()
         phDict.open("PhidgetWS")
           While timer.Elapsed.TotalSeconds < 10 And Not phDict.AttachedToServer
         ' Just wait for a while
            End While
            phListen.start()
        Catch ex As Phidgets.PhidgetException
            MsgBox("Phidget Exception")
        End Try
    End Sub

    Public Sub phDict_Connect(ByVal sender As Object, ByVal e As Phidgets.Events.ServerConnectEventArgs) Handles phDict.ServerConnect
      ' used to have phListen.start() here
    End Sub

    Private Sub phListen_KeyChange(ByVal sender As Object, ByVal e As Phidgets.Events.KeyEventArgs) Handles phListen.KeyChange
      ' key change event handler code goes here
    End Sub

End Class

Any thoughts on what I might be doing wrong? I'm running Win7 64-bit with VB Express 2010.

Thanks,
Mark

MarkS
Phidgetly
Posts: 39
Joined: Sat May 15, 2010 8:37 am
Location: Southeast Pennsylvania USA
Contact:

Re: Dictionary ServerConnect won't fire until KeyListener st

Postby MarkS » Mon Mar 26, 2012 4:13 pm

Well, not sure what I did but it seems to be working correctly now. I'll just chalk this one up to a PEBKAC error - Problem Exists Between Keyboard And Chair. :lol:

Cheers,
Mark


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 1 guest