rapi events

stbi

Member
Licensed User
I am fiddling with RAPI, look at this code:

Sub Globals
End Sub

Sub App_Start
FormMain.Show
rapi.New1
rapi.Connect
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?
 

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.
 

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.

:sign0085:
 

Attachments

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.
 
Top