CNCT
(FB)
FUNCTION_BLOCK CNCT
Note
In case of inactivity, which means there are no read-/write-services transfered on the established connection, the connection may be aborted by the IO subsystem (e.g. after 20 sec.)
Note
The CNCT function block defines a connection to a slot or subslot of a Field Device and returns a handle via the ID output. This connection establishes an Application Relationship (AR) to the Field Device. If another connection and handle is needed to the same Field Device the existing AR may be used.
Code-Example: establish a Supervisor connection
PROGRAM PLC_PRG
VAR
cnct : CommFB.CNCT;
startConnect : BOOL; //establish a Supervisor connection
rdrec : CommFB.RDREC;
loadData : BOOL;
buffer : ARRAY[0..255] OF BYTE;
END_VAR
cnct.D_ADDR.SYSTEM := CommfB.IO_SYSTEM_TYPE.PROFINET_IO;
cnct.D_ADDR.PN.D.STATIONNAME := 'pnDevice';
cnct.D_ADDR.PN.D.VENDOR := 16#011D; //get this data from GSDML or DCP_Identify / Scan
cnct.D_ADDR.PN.D.DEVICE := 16#02EE;
cnct.D_ADDR.PN.D.INSTANCE := 0;
cnct.D_ADDR.PN.SLOT := 0;
cnct.D_ADDR.PN.SUBSLOT := 1;
cnct.REQ := startConnect;
cnct();
IF(cnct.VALID) THEN
loadData := TRUE;
ELSIF(cnct.ERROR) THEN
//re-connect, if connection timed out
startConnect := (cnct.STATUS = CommFB.ErrorCode.TIMEOUT);
END_IF
// Read Diagnosis-Data
rdrec.REQ := loadData;
rdrec.ID := cnct.ID;
rdrec.INDEX := TO_INT(ProfinetCommon.DiagnosisRecordIndex.Device);
rdrec.MLEN := TO_INT(SIZEOF(buffer));
rdrec.RECORD := ADR(buffer);
rdrec();
IF(rdrec.REQ) THEN
IF(rdrec.VALID) THEN
loadData := FALSE;
startConnect := FALSE; //Release connection
END_IF
END_IF
rdrec.REQ := rdrec.BUSY;
- InOut:
Scope
Name
Type
Initial
Comment
Input
REQ
BOOL
Start Request
D_ADDR
Data structure to define the address of a slot of a PROFIBUS DP-slave or a subslot of a PROFINET IO Device
Output
VALID
BOOL
Connection is valid
ERROR
BOOL
Error detected
BUSY
BOOL
FB is busy
STATUS
DWORD
Last detected status
ID
DWORD
Constants.INVALID_ID
Identifier of a PROFIBUS DP-slave or a subslot of a PROFINET IO Device. Use for RDREC or WRREC (Class 2 / Supervisor Access)