I am trying to make a Modbus TCP server run only on IF3 port of a PLC and i face the following:
A part of the code is using the “TcpOpen” function block. When the “pIfAddr” is set to “0” then the Modbus server opens on both PLC ports (IF2&IF3) and i can connect with my client.
When i try to use a pointer to the respective port (“ADR(‘IF2’)”) or (ADR(‘IF3.ETH’) then the “TcpOpen” fails to listen to the ports. The function block seems to be running but i am unable to connect.
My setup is the following:
PLC: CP0484
Modbus client: QModMaster.
The IF3 port is configured as “Powerlink V2” with “Ethernet communication” activated.
I know that it’s not intuitive from the parameter name, but I believe that you need to point pIfAddr to IP address of the Ethernet interface, not the interface address:
The AS Help indicates the pIFAddr should be the IP address of the interface you wish to listen on. So you need to provide it a STRING with ‘192.168.251.10’ and not ‘IF3.ETH.’
I assume you have an X20HB8815 on your PLK network to tunnel your ModbusTCP traffic. Otherwise the ModbusTCP communication will interfere with the PLK network.
As others have already stated, you need to provide a pointer to a STRING variable containing your interface’s IP address.
Example:
Setting the pointer to zero as you have done will open it to every interface, not just IF3.
I believe you could also use a function block from AsARCfg to get the IP address of your device and then pass that into the TCP Open if you prefer to pass the device name rather than a hardcoded string.