Skip to content

Close TCP Port

Hello.
Is it possible to program a command to close (close, not block) a tcp port, when an error condition is detected?
Let me explain in more detail. I want that when an error condition is detected, to program the PLCnext Engineering to send an order to close a tcp port.

Comments

  • Hello Carflomi,
    forcing the input ACTIVATE to False at the TLS_Socket_2 to false will trigger the shutdown of the socket.
    This can be manualy done through the Engineer.
    I dont know what error condition you are talking about but the engineer is usually not connected during production phase.


    So you maybe want not the Engineer but your Aplication itself to shutdown communication in case of error?

    There are multiple possibilities
    1. If the error is an Errorcode in your IEC Application e.g. an output at some FB simply process that Output to reset your Sockets FB.
    2. If it is an Exception you could use a Event Task to reset that port.
    Depending on the severity of the exception that will work or you will have to wait for the Operatingsystem timeout of the socket before binding the same port again.

    kind regards,
    Oliver
  • Thanks Olivier.

    As you say, my application, should close the Sockets, in case of error.

    In my case, it is a Modbus library FB, there are situations in which port 502 is blocked (the signal MB_TCP_Server.xError:=True) and although I restart the block (signal MB_TCP_Server.xActive:= False and then pass the signal MB_TCP_Server. xActive:= True), when I activate the block again the signal MB_TCP_Server.xError:=True, so I want to use another method to force to close the port, so in this case your suggestion to use TLS_Socket_2, I think it is not applicable, the truth is that I do not know how to act in this case.

    Translated with www.DeepL.com/Translator (free version)
  • Hello Carflomi,

    The TLS_Socket_2 FB is used by the library you are using as well.
    I will forward this request to the developer of that library.
    It should be possible to shutdown the socket correctly so that the next reactivation will be successfull.
    To find out what exactly causes the behavior you describe we need to know how to reproduce this error.
    What error codes do you recieve?
    How do you usually reach this issue?
    What version of the Modbus TCP Library are you using?
    Which FW Version has your PLC.

    kind regards,
    Oliver
  • edited January 2022
    Hello.
    I have solved my problem using a trick.
    I explain the sequence:



    1. there are situations where MB_TCP_Server, detects that there is no connection (MB_TCP_Server.xConnected=False) in this case, there is a mechanism that activates, deactivates the block until get the MB_TCP_Server has connected (MB_TCP_Server.xConnected=True).

    2. There are situations when MB_TCP_Server, detects error (MB_TCP_Server.xError=True), in this case, there is a mechanism that activates, deactivates the block until getting the correct connection (MB_TCP_Server.xConnected=True and MB_TCP_Server.xError=False), the connection is established after about 60 seconds.

    3. There are situations where MB_TCP_Serve does not detect that there is no connection (MB_TCP_Server.xConnected=True, but the Modbus client equipment is not operative), in this situation what I have had to do is to force the PLC to deactivate the block, so that the mechanism of point 1, starts to work, The described in this point implies that I must force the disconnection every certain time (for example every 2 minutes).

    In this way I make sure that there is always a connection with the Modbus client.
  • Hello Carflomi,

    good to hear that it works for you now and thank you for sharing your work.
    I forwarded it to the developers anyway as feedback.
    Maybe there will be a updated reset functionality in a future version.

    kind regards,
    Oliver
This discussion has been closed.