Page 1 of 1

Dictionary ServerConnect won't fire until KeyListener starts

Posted: Sat Mar 24, 2012 10:16 am
by MarkS
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

Re: Dictionary ServerConnect won't fire until KeyListener st

Posted: Mon Mar 26, 2012 4:13 pm
by MarkS
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