Get_Attribute_Single (FB)

FUNCTION_BLOCK Get_Attribute_Single EXTENDS BaseService

Use this function block for querying the attribute of a specific instance of a CIP object.

Note

Data received and send needs to be swapped. See parent folder.

(* CIP Data type for string with a length of max. 64 chars *)
TYPE STRING64 :
STRUCT
   uiLength   : UINT;
   sString    : STRING(63);
END_STRUCT
END_TYPE

PROGRAM PLC_PRG
VAR
    strHostnameToGet   : STRING64;
    getAttributeSingle : ENIP.Get_Attribute_Single ;
    udiReceivedData    : UDINT;
END_VAR

getAttributeSingle(
    xExecute:= ,
    itfEtherNetIPDevice:= EtherNetIP_Adapter,    (* instance of the device (instance is found in the I/O Mapping of the device) *)
    eClass:= ENIP.CIPClass.TCPIPInterfaceObject, (* cip class which contains the desired attribute *)
    dwInstance:= 1,                              (* value of 0 is class level, range from 1..x is instance level *)
    wAttribute:= 6,                              (* attribute no. 6 of the tcp/ip interface object is the Hostname (CIP Spec. Vol.2 Chapter 5-3.3.2.6)*)
    pData:= ADR(strHostnameToGet),               (* data buffer *)
    udiDataSize:= SIZEOF(strHostnameToGet),      (* size of the data buffer *)
    xDone=> ,
    xBusy=> ,
    xError=> ,
    eError=> ,
    udiReceivedDataSize=> udiReceivedData );     (* if the request was successful, udiReceivedData contains the number of bytes which have been received *)
    ;
InOut:

Scope

Name

Type

Comment

Inherited from

Input

itfEtherNetIPDevice

IEtherNetIPService

EtherNet/IP Device which implements the EtherNet/IP Services interface

BaseService

eClass

CIPClass

Class which shall perform the service

BaseService

dwInstance

DWORD

Instance which shall perform the service (0: Class level, 1..x: Instance level)

BaseService

Output

eError

ERROR

Error (0-255: CIP Error; 256-x: Library Error)

BaseService

Input

wAttribute

WORD

Attribute to get

pData

POINTER TO BYTE

Data buffer

udiDataSize

UDINT

Size of buffer

Output

udiReceivedDataSize

UDINT

Size of the received data