FP_ETHERNET_CONNECTION_SET

Set an Ethernet connection

This FP instruction sets up an Ethernet connection with settings specified by sMode and sAddress in a range of user connections specified by nStartPort and nEndPort. Please ensure the suitable parameters are also set in the project navigator under System registers > Ethernet > User connections.

Parameters

Input

sMode (STRING)

Set the communication mode and connection parameters.

  • Communication mode (required parameter)

    Specify parameters for the communication mode.

    Keywords:

    • 'MEWCOM': MEWTOCOL-COM (default)

    • 'MEW7COM': MEWTOCOL7-COM

    • 'MODBUS': MODBUS-TCP

    • 'MEWDAT': MEWTOCOL-DAT

    • 'GP': Program controlled [General purpose] (only available for 16 user connections)

    • 'GP_LARGE': Program controlled [General purpose] with large capacity reception (only available for the first user connection and only on PLC types CPS4* and CPS3* version 4.32 or higher)

  • Option setting (required parameter)

    Some communication modes have an additional protocol option that can be activated. Specify whether or not to use the option for the selected communication mode.

    • 'OPTAV': The option available for the selected communication mode is activated

    • 'OPTNAV': Either there is no option available for the selected communication mode or the available option is not activated (default)

    Communication mode

    'OPTAV'

    'OPTNAV'

    MEWTOCOL-COM

    Connect with FP2 ET-LAN

    Do not connect

    MEWTOCOL7-COM

    Not available

    Not available

    MODBUS-TCP

    Not available

    Not available

    MEWTOCOL-DAT

    Connect with FP2 ET-LAN

    Do not connect

    Program controlled [General purpose]

    Do not append a special header

    Append a special header

    Program controlled [General purpose] with large capacity reception

    Do not append a special header

    Not available. If this keyword is specified, an operation error occurs.

  • Specify the type of Ethernet connection to be opened (required parameter).

    • 'CL': Client connection (default)

      For client connections, the destination unit IP address is incremented by one for each user connection from the user connection specified by nStartPort to the user connection specified by nEndPort.

    • 'SV': Server connection

      For server connections, the master unit port number is incremented by one for each user connection from the user connection specified by nStartPort to the user connection specified by nEndPort.

  • Specify the method for opening the Ethernet connection (required parameter).

    • 'AUTO': Open the connection automatically (default)

    • 'MANU': Do not open the connection automatically (instead, use the instruction FP_ETHERNET_CONNECTION_OPEN)

  • Specify the type of Ethernet communication (required parameter).

    • 'TCP': TCP/IP setting (default)

    • 'UDP': UDP/IP setting (not available for the communication mode GP_LARGE)

    Notes:

    • If you have specified UDP as the communication type, there is a difference between using FP instructions and making configuration settings in the project navigator. There is no parameter "open type" available in the project navigator. However, "open type" must be specified in the FP instructions. Use the keywords 'SV' for a slave connection and 'CL' for a master connection.

    • Do not specify UDP for the communication mode GP_LARGE because this will lead to an operation error.

  • Reset to default values

    'INITIAL': Resets all settings to the default settings

Examples:

  1. Set MEWTOCOL-COM as the communication mode, use the option to connect with FP2 ET-LAN, a client connection should be established and opened automatically, and communication type is TCP/IP: 'MEWCOM,OPTAV,CL,AUTO,TCP'

  2. Set MODBUS-TCP as the communication mode, option is not available, a server connection should be established but not opened automatically, and the communication type is UDP/IP: 'MODBUS,OPTNAV,SV,MANU,UDP'

  3. Set the communication mode to program controlled, append a special header, a server connection should be established and opened automatically, and the communication type is UDP/IP: 'GP,OPTNAV,SV,AUTO,UDP'

  4. Set the communication mode to program controlled with large capacity reception, do not append a special header, a server connection should be established but not opened automatically, and the communication type is TCP/IP: 'GP_LARGE,OPTAV,SV,MANU,TCP'

  5. When you want to reset the configuration to the default settings so that communication mode is MEWTOCOL-COM, no connection to FP2 ET-LAN, a client connection should be established and opened automatically, and communication type is TCP/IP: 'INITIAL'

sAddress (STRING)

Set the address parameters. The settings differ depending on whether you are specifying client or server connections.

For client connections, you need to specify the IP addresses and the port numbers of the destination units as well as the disconnect time for unused connections.

For server connections, you need to specify the port numbers of the master unit and the disconnect time for unused connections.

  • Specifying a client connection

    • Destination unit IP address (required parameter)

      Specify the destination unit IP address for the first user connection in the range of user connections specified by nStartPort and nEndPort. The IP address for the other user connections is set by incrementing the last block of the IP address by one. The setting for the destination port number and the disconnect time is the same for all user connections and will not be incremented.

      For an IP address, specify the keyword IPv4 or IPv6 at the beginning.

      • Syntax for IPv4: e.g. 'IPv4=111.122.133.144'

      • Syntax for IPv6: e.g. 'IPv6=1111:122:2:1555:0:0:1888'

        Please note that for IPv4 addresses there are range restrictions. For IPv4, 000.000.000.000 (0.0.0.0) cannot be specified. When an invalid IP address is specified with an instruction, there will be no operation error but the output bError will be set to TRUE. The system variable sys_iEthernetConnectionErrorCode is set to "1: Incorrect IP address is specified".

    • Destination unit port number (required parameter)

      Keyword: 'PORT'

      Syntax:'PORT=xxxxx'

      Values: 1–65535

    • Disconnect time for unused connections (required parameter)

      Keyword: 'DISCONT'

      Syntax: 'DISCONT=xxxx'

      Values: 0–4294967295ms in steps of 10ms. 0: The connection is not automatically disconnected.

    • Receive buffer starting address (optional parameter)

      This parameter is only available for FP0H C32ET/EP and FP-XH C40ET, C60ET, FP-XH C60ETF when the communication mode is set to program controlled [General purpose].

      Keyword: 'BUFTOP'

      Syntax: 'BUFTOP=xxxx'

      Values: DT0 to last possible DT

    • Size of receive buffer (optional parameter)

      This parameter is only available for FP0H C32ET/EP and FP-XH C40ET, C60ET, FP-XH C60ETF when the communication mode is set to program controlled [General purpose].

      Keyword: 'BUFSIZE'

      Syntax: 'BUFSIZE=xxxx'

      Values: 0–2048

Examples:

  1. Set destination unit address to 192.244.2.10 and destination unit port number to 9000, do not disconnect automatically even if connection is unused: 'IPv4=192.244.2.10,PORT=9000,DISCONT=0'

  2. Set destination unit address to 1222::1555:0:0:1999 and destination unit port number to 10000, disconnect automatically after connection has not been used for 30 seconds: 'IPv6=1222::1555:0:0:1999,PORT=10000,DISCONT=30000'

  3. Set destination unit address to 192.168.1.5 and destination unit port number to 4000, disconnect automatically after connection has not been used for 50 seconds, set starting address of receive buffer to DT4 and receive buffer size to 256: 'IPv4=192.168.1.5, PORT=4000, DISCONT=100, BUFTOP=DT4, BUFSIZE=256'

  • Specifying a server connection

    • Master unit port number (required parameter)

      Keyword: 'PORT'

      Syntax: 'PORT=xxxxx'

      Values: 1–65535

    • Disconnect time for unused connections (required parameter)

      Keyword: 'DISCONT'

      Syntax: 'DISCONT=xxxx'

      Values: 0–4294967295ms in steps of 10ms. 0: The connection is not automatically disconnected.

Examples:

  1. Set master unit port number to 9000, do not disconnect automatically even if connection is unused: 'PORT=9000,DISCONT=0'

  2. Set master unit port number to 10000, disconnect automatically after connection has not been used for 30 seconds: 'PORT=10000,DISCONT=30000'

  3. Set master unit port number to 11111, disconnect automatically after connection has not been used for 70 milliseconds: 'PORT=11111,DISCONT=70'

nStartPort (WORD, INT, UINT)

Set the number of the first user connection

SYS_ETHERNET_USER_CONNECTION_1SYS_ETHERNET_USER_CONNECTION_216

nEndPort (WORD, INT, UINT)

Set the number of the last user connection

SYS_ETHERNET_USER_CONNECTION_1SYS_ETHERNET_USER_CONNECTION_216

Output

bError (turns to TRUE and remains TRUE) (BOOL)
  • if an IP address is invalid

  • if the instruction is executed while the IP address is not established

When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Remarks

  • Do not change the order of keywords. Specify the keywords and their setting parameters in the order they are listed here.

  • Use a comma "," to separate a keyword and its setting from the next keyword.

  • Be sure that nStartPort £ nEndPort

  • Be sure to specify nStartPort and nEndPort so that all destination unit IP addresses (client connection) or all master unit port numbers (server connection) are inside the permissible range.

  • The maximum number for Ethernet user connections is 216.

  • If you execute the instruction when a user connection is open or a user connection is set to open automatically, an operation error occurs. However, when multiple user connections are set with the instruction, the setting changes for the user connections before the user connection in which an operation error occurs will be done. The setting changes for the user connections after the user connection in which an operation error occurs will not be done.

  • If you use this instruction for multiple client connections some of which have already been configured, an operation error occurs because user connections which have been configured for one server are bundled together and will all be opened and closed at the same time.

  • This instruction is not available in interrupt programs.

  • Both upper and lower case characters can be used. "Abcd", "ABCD" and "abcd" are synonymous.

  • Before you execute the instruction, make sure that sys_bIsEthernetInitializing is FALSE. sys_bIsEthernetInitializing turns to TRUE when the instruction is executed. When you execute the instruction while sys_bIsEthernetInitializing is TRUE, an error occurs.

  • Before you execute the instruction, make sure that sys_bIsEthernetIPAddressAssigned is TRUE. When you execute the instruction while sys_bIsEthernetIPAddressAssigned is FALSE, bError turns to TRUE and the instruction is terminated without being executed.

  • When an incorrect IP address is specified, bError is set and no operation is executed.

  • When this instruction has been executed successfully, the system variables sys_bIsCarry and sys_iEthernetConnectionErrorCode are reset.

  • This instruction does not overwrite the Ethernet configuration data stored in the PLC permanently. When the PLC has been switched off and on again, the Ethernet configuration data stored in the PLC are used again.

  • When an error occurs, check the system variable sys_iEthernetConnectionErrorCode for the error code number.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if nStartPort > nEndPort

  • if the user connection number is outside the permissible range

  • if a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if a port number is invalid

  • if the number of characters for string data exceeds 256.

  • if there is an open connection

  • if there is a connection set to open automatically

  • if one or more user connections in the range specified by nStartPort and nEndPort belong to an already existing server configuration.

  • if GP_LARGE is specified as the communication mode and OPTNAV is specified as the protocol option

  • if GP_LARGE is specified as the communication mode and UDP is specified as the Ethernet communication type

  • if GP_LARGE is specified as the communication mode and nStartPort or nEndPort is not 1

  • if the instruction is executed in an interrupt program

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if nStartPort > nEndPort

  • if the user connection number is outside the permissible range

  • if a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if a port number is invalid

  • if the number of characters for string data exceeds 256.

  • if there is an open connection

  • if there is a connection set to open automatically

  • if one or more user connections in the range specified by nStartPort and nEndPort belong to an already existing server configuration.

  • if GP_LARGE is specified as the communication mode and OPTNAV is specified as the protocol option

  • if GP_LARGE is specified as the communication mode and UDP is specified as the Ethernet communication type

  • if GP_LARGE is specified as the communication mode and nStartPort or nEndPort is not 1

  • if the instruction is executed in an interrupt program

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bSetConnection: BOOL:=FALSE;
		bOpenConnection: BOOL:=FALSE;
		bCloseConnection: BOOL:=FALSE;
	END_VAR

POU body

When the variable bSetConnection changes from FALSE to TRUE and the system variable sys_bIsEthernetInitializing is not TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_VARIN,,'GP~OPTNAV~SV~AUTO~UDP',30,2,32,4,);
B(B_VARIN,,'PORT=9000~DISCONT=0',30,3,32,5,);
B(B_VARIN,,SYS_ETHERNET_USER_CONNECTION_1,30,4,32,6,);
B(B_VARIN,,SYS_ETHERNET_USER_CONNECTION_13,30,5,32,7,);
B(B_CONTACT,,sys_bIsEthernetInitializing,15,1,17,3,N);
B(B_CONTACT,,bSetConnection,5,1,7,3,R);
B(B_VAROUT,,bError,48,2,50,4,);
B(B_F,FP_ETHERNET_CONNECTION_SET!,,32,0,48,7,,?DEN?DsMode?DsAddress?DnStartPort?DnEndPort?AENO?CbError);
L(17,2,32,2);
L(1,2,5,2);
L(7,2,15,2);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

If DF(bSetConnection) AND NOT sys_bIsEthernetInitializing Then
    FP_ETHERNET_CONNECTION_SET(sMode := 'GP,OPTNAV,SV,AUTO,UDP',
                                sAddress := 'PORT=9000,DISCONT=0,BUFTOP=DT10000,BUFSIZE=100',
                                nStartPort := SYS_ETHERNET_USER_CONNECTION_1, 
                                nEndPort := SYS_ETHERNET_USER_CONNECTION_13);
END_IF;

Modified on: 2024-03-06Feedback on this pagePanasonic hotline