rapi events

Discussion in 'Questions (Windows Mobile)' started by stbi, Oct 18, 2007.

  1. stbi

    stbi Member Licensed User

    I am fiddling with RAPI, look at this code:

    Sub Globals
    End Sub

    Sub App_Start
    End Sub

    Sub rapi_Connected
    Msgbox("PDA connected")
    End Sub

    Sub rapi_Disconnected
    Msgbox("PDA not connected")
    End Sub

    I allways get the disconnect event, but never the connect event. What's wrong?
  2. agraham

    agraham Expert Licensed User

    I cut and pasted your code and the same happens on my system. I get the Disconnected event but not the Connected event.

    I use an Axim X30 connecting to Vista and Windows Mobile Device Center 6.1.
  3. agraham

    agraham Expert Licensed User

    I think that you - like me - have misunderstood how this works. I expected to run the program then connect the device then get the Connected event, it doesn't seem to work like that!

    The device needs to have established a connection with the PC BEFORE the "rapi.connect" code is executed. Look at the example with a timeout in the overview of the help. Make the timeout large. Running the program then connecting the device never gives a Connect event. However connecting the device THEN running the program gives both events.
  4. stbi

    stbi Member Licensed User

    Agraham, thank you. I agree with you that the connect event ist only fired when you are trying to connect with the rapi.connect method.

    But now I am totally confused ... I try to connect periodically by a timer event ... now I get a connect event even when the device is physically disconnected :sign0137: Please have a look at my attached example.

    I am creating a file sync program, but this connect event is driving me nuts.


    Attached Files:

  5. agraham

    agraham Expert Licensed User

    I get the same effect when running your code from the IDE but I think that you are calling Rapi.connect too often. Slow the timer down to 5 seconds and the behaviour changes. However I think that repeated calls of Rapi.Connect are dangerous as I have crashed both the IDE and a separately compiled exe of your code by disconnecting and reconnecting the device.

    It seems that it is best to treat Rapi.Connect as a "one-off deal". You only call it once per "run" of an application and it either connects or doesn't.

    If you start the application without the device connected Rapi.Connect will not connect after the device is connected.

    If you start the application with the device connected then Rapi.Connect will give a connect event and a disconnect event when the device is disconnected. Further (not too frequent!) calls to Rapi.Connect don't reconnect and can cause a hang if the device is reconnected.

    A further consideration is that under the IDE it is the IDE that is seen to have issued the Rapi.Connect call so once a program under development has connected you have to exit the IDE and restart to connect again.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice