FP_IPV4_SET_ADDRESS

Set IP address using IPv4 protocol

This FP instruction sets up a connection to the IP address specified by sAddress via internet protocol V4.

Parameters

Input

sAddress (STRING)
  • IPv4 address (required parameter)

    Keyword: IP

  • Netmask (optional parameter)

    Keyword: MASK

  • Gateway (optional parameter)

    Keyword: GWIP

    Specify "0" when the default gateway is not to be used.

Examples:
  1. Set the IP address to 192.168.1.5, use netmask 255.255.255.0 and the gateway 192.168.1.1: 'IP=192.168.1.5,MASK=255.255.255.0,GWIP=192.168.1.1'

  2. Set the IP address to 192.168.1.5, do not use a netmask, use the gateway 192.168.1.1: 'IP=192.168.1.5,,GWIP=192.168.1.1'

Output

bError (BOOL)
  • if a timeout of the connection is exceeded

  • if an IP address is invalid

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

Remarks

  • It is recommended to execute this instruction only once at the startup of PLC. Do not execute it repeatedly.

  • It takes three seconds or longer to complete initialization.

  • The number of characters for string data must not exceed 256.

  • This instruction is not available in interrupt programs.

  • Ensure the string at sAddress does not contain any blanks. Use comma as separator character only.

  • IPv4 address is mandatory. Netmask and gateway can be omitted.

  • A part of parameters can be omitted. The settings are not changed when parameters are omitted partially.

  • Upper and lower case characters can be used for specifying keywords.

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

  • 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, check if the system variable sys_bIsEthernetIPAddressAssigned is TRUE. If it is FALSE when executing the instruction, an error occurs.

  • The instruction can only be executed when sys_bIsEthernetCableNotConnected is FALSE.

  • 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 a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if the instruction is executed in an interrupt program

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

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if a value specified for a parameter is outside the permissible range.

  • if the same keyword is specified more than once

  • if the instruction is executed in an interrupt program

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

sys_bIsCarry (turns to TRUE for one scan)
  • if the instruction is executed with an incorrect IP address, netmask, gateway or a combination of incorrect IP addresses sys_iEthernetConnectionErrorCode is set to the corresponding error code (1–4).

  • if the instruction is executed while the Ethernet cable is disconnected. sys_iEthernetConnectionErrorCode is set to "10: Ethernet cable disconnected".

  • if the instruction is executed during the initialization of Ethernet, sys_iEthernetConnectionErrorCode is set to "11: Ethernet is being initialized".

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
		bSetIpv4Address: BOOL:=FALSE;
		bGetConnection: BOOL:=FALSE;
		bGetMac: BOOL:=FALSE;
		dutIPv4Connection: FP_IPv4_CONNECTION_DUT;
		dutIPv4MAC: FP_IPv4_MAC_DUT;
	END_VAR

POU body

This example sets the Ethernet connection parameters specified by s_Address. Please ensure the suitable parameters are also set in the project navigator under System registers > Ethernet > IP addresses. When bGetConnection is set to TRUE, the connection parameters are entered into the DUT FP_IPv4_CONNECTION_DUT. When bGetMac is set to TRUE, the parameters of the MAC address are entered into the DUT FP_IPv4_MAC_DUT.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_CONTACT,,bSetIpv4Address,4,2,6,4,R);
B(B_CONTACT,,sys_bIsEthernetInitializing,15,2,17,4,N);
B(B_F,FP_IPV4_SET_ADDRESS!,,31,1,43,5,,?DEN?DsAddress?AENO?CbError);
B(B_VARIN,,'IP=192.168.1.5~MASK=255.255.255.0~GWIP=192.168.1.1',29,3,31,5,);
B(B_VAROUT,,bError,43,3,45,5,);
L(1,0,1,5);
L(1,3,4,3);
L(6,3,15,3);
L(17,3,31,3);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 4 ;
        NETWORK_BODY
B(B_CONTACT,,bGetConnection,4,1,6,3,);
B(B_F,FP_IPV4_GET_CONNECTION!,,31,0,45,4,,?DEN?DnPort?AENO?CdutIPv4Connection);
B(B_VAROUT,,dutIPv4Connection,45,2,47,4,);
L(1,0,1,4);
L(1,2,4,2);
L(6,2,31,2);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 4 ;
        NETWORK_BODY
B(B_CONTACT,,bGetMac,4,1,6,3,);
B(B_F,FP_IPV4_GET_MAC!,,31,0,41,4,,?DEN?AENO?CdutIPv4MAC);
B(B_VAROUT,,dutIPv4MAC,41,2,43,4,);
L(1,0,1,4);
L(1,2,4,2);
L(6,2,31,2);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF DF(bSetIpv4Address) AND not(sys_bIsEthernetInitializing) then
    FP_IPV4_SET_ADDRESS(sAddress := 'IP=192.168.1.5,MASK=255.255.255.0,GWIP=192.168.1.1',
				bError => bError);
END_IF;
IF (bGetConnection) then
    FP_IPV4_GET_CONNECTION(nPort := SYS_ETHERNET_USER_CONNECTION_2, dutIPv4Connection => dutIPv4Connection);
END_IF;
IF (bGetMac) then
    FP_IPV4_GET_MAC(dutIPv4MAC => dutIPv4MAC);
END_IF;

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