Author Topic: TIPConnection.IsConnected Problems  (Read 618 times)

shaffin

  • Newbie
  • *
  • Posts: 10
    • View Profile
TIPConnection.IsConnected Problems
« on: December 30, 2018, 19:23:28 »
Hello,

I am using the Pascal API's in Delphi. I noticed that when I program:

Conn: TIPConnection;

Conn := TIPConnection.Create;
Conn.Connect('127.0.0.1', 4223);

The above does not throw an exception even when the StepperBrick is not plugged in via USB! It always return "true" when performing a Conn.IsConnected()

Is there any premise behind this or is it something more????

Thanks,
Shaffin.

shaffin

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: TIPConnection.IsConnected Problems
« Reply #1 on: December 30, 2018, 19:45:21 »
I believe I answered my own question that the reason I am getting a success back is the fact that the Brickd is responding to the connection and not the brick!

Would it be too much as for a helper function in the brick api such as

TStepperBrick.Available(UID)?

Thanks,
Shaffin.

remotecontrol

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
Re: TIPConnection.IsConnected Problems
« Reply #2 on: December 31, 2018, 12:14:49 »
There is an enumeration API for the connection and this returns the connected UIDs and device types.

First introduction how to use enumeration is here
https://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Rugged/Tutorial.html#tutorial-rugged-approach

And you can read the Pascal API doc (I don't use Pascal, so I have no sample).

shaffin

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: TIPConnection.IsConnected Problems
« Reply #3 on: January 02, 2019, 02:32:48 »
I have tried using thatand have seen some inconsistent behaviour at best.

When I use enumerate I notice that every so often it times out unless I specifically call Sleep(250) after I make a call to enumerate!

Has anyone else seen this behaviour?

remotecontrol

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
Re: TIPConnection.IsConnected Problems
« Reply #4 on: January 03, 2019, 15:11:35 »
The call to ipcon_enumerate triggers callbacks and it depends on what you're doing in the callback.

You should only update internal structures in the callback.
The main thread should wait some time so that the callbacks are done and everything is updated.

the "while (true)" from the sample is just an outline - don't use it exactly that way without wait times, this would consume 100% CPU !

remotecontrol

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
Re: TIPConnection.IsConnected Problems
« Reply #5 on: January 03, 2019, 15:17:48 »
To make it more precise:
I trigger the enumerate callback, then wait 250ms and check how many devices are listed in my internal structures meanwhile; not enough => wait again.

If there are not enough devices after for example 2 seconds I abort, there is something wrong.

The enumeration is normally done quite fast (below 0.5 seconds).