eipWriteAttrPLCopen motion icon

Function BlockClosedA function block groups an algorithm and a set of private data. It has inputs and outputs. - Ethernet/IP explicit messaging - write single attribute.

This function block sends an explicit message (UCMM) to an Ethernet/IP adapter, for writing a single CIPClosed"Common Industrial Protocol " The Common Industrial Protocol allows complete integration of control with information, multiple CIP Networks, and Internet technologies attribute.

Inputs

Snd : BOOL A rising edgeClosedA rising edge is the transition of a digital signal from low to high. It is also called positive edge on this input start the exchange. The DONE output will signal the end of exchange.
SrvIP : STRING IP address of the server (adapter) such as configured in the "Ethernet/IP Scanner" configuration.
Class : UINT Class identifier of the CIP object.
Inst : UINT Instance identifier of the CIP object.
Attr : UINT Identifier of the CIP attribute.
Size : UINT Number of bytes to write. Cannot exceed 450 bytes.
Data : array of UINT Buffer containing the data to write.

Outputs

Done : BOOL This output is TRUE during one cycle when the exchange is finished, whatever the exchange succeeded or failed. Warning, this output can be TRUE just after the call to block when starting a new exchange in case of invalid parameters.
RcvSize : UINT Actual size of the CIP attribute answered by the server. If this size if greater than the size of the DATA input array, it indicates that the value was truncated.
Err : UINT Main error report. Can be one of the following values:
0 = no error
1 = invalid input arguments
2 = system is busy (see remarks)
3 = timeout waiting for the answer (the timeout value is 3 seconds
4 = UCMM error was returned by the server
others = internal errors (reserved for technical support)
EmErr : UINT in case of a UCMM error, this is the CIP general status error code.
EmErrExt : UINT in case of a UCMM error, this is the CIP extended status error code.

Remarks

The servers (adapters) accessed by this block must be configured in the "Ethernet/IP Scanner" fieldbus configuration.

Only one explicit message (read or write) can be sent at one time to the same server. If another message is pending then you will get the error report 3 (busy) after calling the block to start a new exchange.

Consider SerializeIn and SerializeOut functions for storing data to the write buffer.

Example

// used variables
// Inst_eipWriteAttr : eipWriteAttr ;
// bWrite : BOOL ; (* request for WRITE *)
// DataWrite : ARRAY [0 .. 15] OF USINT; (* written data *)
// uiSizeWrite : UINT := UINT#16 ; (* number of bytes to read *)
// Server identification and CIP things

#define SRVIP '192.168.33.21'
#define CLASSID UINT#100
#define INSTID_WRITE UINT#2
#define ATTRID UINT#3
/////////////////////////////////////////////////////////////////////////////////////////
// requested WRITE command

if bWrite then
Inst_eipWriteAttr (bWrite, SRVIP, CLASSID, INSTID_WRITE, ATTRID,
uiSizeWrite, DataWrite);
end_if;
// WRITE answer here ?
if Inst_eipWriteAttr.Done then
// check answer
if Inst_eipWriteAttr.Err = 0 then
printf ('WRITE ok');
else
printf ('WRITE Error %lu - (UCMM Error %lu, %lu)',
any_to_dint (Inst_eipWriteAttr.Err),
any_to_dint (Inst_eipWriteAttr.EmErr),
any_to_dint (Inst_eipWriteAttr.EmErrExt));
end_if;
// reset WRITE command and block input
Inst_eipWriteAttr (false, SRVIP, CLASSID, INSTID_WRITE, ATTRID,
uiSizeWrite, DataWrite);
bWrite := false;
end_if;