0

I have a program in Delphi 6 which connects to an industrial device (2d barcode scanner), using TCP/IP on a specific port. The scanner socket is not connected all the time, only when operator performs a certain operation. At that time, I would like to connect to the scanner, or show that it's offline (example: someone could have taken the cable out).

I have

IDScannerConnection: TIdTelnet;

Assuming connection is not available - wrong IP setting, cable out, wrong port, ... : If I just do IDScannerConnection.connect; Windows will freeze the program until it times out, which is several long seconds. Even inside a try/except.

I have tried the procedure here but it does not register if connection is available.

So, what's the best approach ? Connection to said device is using Telnet, to get an even when data is available. I can run a console program externally if I have to. In general I am fairly flexible around solutions, as long as operator does not experience a long timeout.

Unfortunately I am stuck in D6 and Indy9, can't upgrade these at the moment.

MyICQ
  • 987
  • 1
  • 9
  • 25
  • 1
    Move the Telnet connection to a separate thread, this way you will not block the gui when you try to make the connection. Make sure not to put GUI related code in the telnet connection thread, use simple window messages to inform the gui. – whosrdaddy Mar 29 '21 at 21:23
  • 1
    "*use simple window messages to inform the gui*" - there are many different ways to communication across thread boundaries. Windows/thread messages is not the only way. For instance, `TThread.Synchronize()` can be used instead. Also note that `Connect()` has an optional `ATimeout` parameter in Indy9. When used with `TIdAntiFreeze`, `Connect()` *can* be called in the main UI thread, though I don't recommend doing that, but it is an option. – Remy Lebeau Mar 29 '21 at 22:25

0 Answers0