AsTCP connection multiple devices

My goal is to build up communication with 12 TCP/IP devices of same type. For recieving that, i created a FUB which include more or less the example tcp client from AS help. From this FUB i create and call 12 instances inside an ST program. Sometimes it works but sometimes i get the error tcpERR_INVALID_IDENT at some instances of TcpClient. Is it proper to instace an AsOpen FUB for every single connection or should i use the same FUB for all connections (all 12 connections uses the same tcp port at the plc)?

Hi,

if you need to have 12 different TCP client connections, then you can use also 12 instances of TcpOpen, in general that should be right, yes.
What do you mean exactly with 12 times using the same port? If it’s the same remote port at the 12 different server devices, that’s ok.

Which function blocks throw the error?

Best regards!

1 Like

Hi,
With “12 times using the same port” i mean the physical Eth-port on the B&R CPU.
The error is thrown by the TcpClient FUB.

Thank you

Hi,

okay got it, using the same eth port for all of the clients should not be a problem.

tcpERR_INVALID_IDENT thrown by the TcpClient function block more or less only means, that the ident delivered by TcpOpen does not (longer) exists.
So I only can propose

  • to check first if the TcpOpen function call belonging to the TcpClient call really returned 0 as status (no error from TcpOpen), and if the ident output of TcpOpen contains a non-zero number, and if this “ident-number” is the same one that is used by TcpClient later on.
  • if you call the TcpClient function block because of trying to reconnect to the server, for example because of another error thrown before by TcpWrite or TcpRead, then it could be neccessary do a TcpClose and TcpOpen before, to get a new ident (depending on the cause why the connection was broken).

As additional information:
There’s a limited number of idents available in the system, and if not all opened idents are closed before opening the next ones, the number of available idents decrease - if no more idents are available, trying to open the next one with TcpOpen should lead to TcpOpen.status = tcpERR_NOMORE_IDENTS
Reducing the number of idents can happen for example when transferring the task while ongoing development, but don’t closing open idents before transfer in _EXIT function.

To check if more idents are open than you expect, and which “ident-numbers” are in use, you could use the TcpIoctl function block with the IoControl tcpID_LIST_GET - using this is normally not needed for common AsTcp applications, but it’s interesting for example for debugging.

Best regards!

1 Like