IO Systems like PROFIBUS DP and PROFINET IO use different address concepts.
This results in different functions or function parameters to identify a Field Device, a slot or subslot inside a Field Device.
In order to provide an uniform interface for the use with different types of IO communication subsystems, all Communication Function Blocks hide the address concept of the specific IO Systems.
The Function Blocks use an abstract ''ID'', a handle of data type DWORD, to uniquely identify a Profibus-Module or a Profinet-Submodule within an application.
Therefore an application program is able to use the Communication Function Blocks without knowledge of the explicit hardware configuration (e.g. the MAC address or Station-Name of a Field Device or the slot-position of a module).
This way an application or library can be developed without dependencies to hardware configuration data such as a specific IO-Driver or an addressing method.
There are different methods, generic and more specific ones, to generate an ID for identifying a Profibus/Profinet device:
The actual value of ID should never be manipulated or created, only use the IDs created from theses sources described here. The value of ID can differ depending on the project structure or the driver version !
The input parameter ID of the Communication Function Blocks addresses one slot of a DP-slave or a DP-slave (Slot 0).
This handle may be generated by using one of the following functions:
ID: Conversion of a physical address of a DP-slave to the handle
ADDR: Conversion of a handle to the physical address of a DP-slave
SLOT_ID: Addressing a slot of a DP-slave
The input parameter ID of the Communication Function Blocks addresses a Profinet-Submodule.
A Profinet Module is just a container for at least one submodule. IO-Data and Parameters are always assigned to a submodule.
The shortest way to get the ID of a submodule is to call the GetID()-method of the Profinet-Slave function block which is generated for each Profinet-Slave device:
Code-Example: ID with GetID() - method
PROGRAM PLC_PRG
VAR
ID : DWORD := CommFB.Constants.INVALID_ID;
END_VAR
ID := PNSlave.GetID(API := 0, SLOT := 1, SUBSLOT = 1); // get ID of 1. module
A generic way for obtaining an CommFB-ID is by calling the method IDevice.GetDeviceInfo().
For an underlying Profinet/Profibus slave or module, the generic DEVICE_INFO structure, which is returned by this method, contains the unique CommFB-ID:
Code-Example: ID with generic Device Diagnosis
FUNCTION ListStationnames : DINT
VAR_IN_OUT
controller : DED.IDevice;
END_VAR
VAR
i : DINT;
childDevice : DED.IDevice;
deviceInfo : DED.DEVICE_INFO;
convertID : CommFB.ID_TO_ADDR;
pnAddress : CommFB.ADDR_TYPE;
stationName : STRING;
END_VAR
FOR i := 0 TO TO_DINT(controller.ChildNodeCount - 1) DO
childDevice := DED.INode_TO_IDevice(controller.GetChild(TO_UDINT(i)));
IF(childDevice <> 0 AND_THEN childDevice.GetDeviceInfo(deviceInfo) = DED.ERROR.NO_ERROR) THEN
convertID(EN := TRUE, ID := deviceInfo.idSystem, ADDR := pnAddress);
IF(convertID.ENO) THEN
IF(pnAddress.SYSTEM = CommFB.IO_SYSTEM_TYPE.PROFINET_IO) THEN
//we have a valid Profinet Address:
stationName := pnAddress.PN.D.STATIONNAME;
END_IF
END_IF
END_IF
END_FOR
For some use cases it may be necessary to use native PROFIBUS DP and PROFINET IO addressing.
These function blocks can be used for obtaining an ID to a native, protocol specific address and vice versa (see examples in the function block's description)
The handle may be generated by local means of the PLC or its configuration system or may be generated by using one of the following functions:
ADDR_TO_ID: Conversion of a address of a PROFINET IO Device to the handle
ID_TO_ADDR: Conversion of a handle to the address of a PROFINET IO Device
InOut: |
|