Join us today!

Read and Write CoE ...
 
Notifications
Clear all

Read and Write CoE paramaters

1 Posts
1 Users
2 Reactions
1,492 Views
TwinControls
Posts: 71
Admin
Topic starter
(@beckhoffsupport)
Member
Joined: 2 years ago

If you need to read CoE parameters from an EtherCAT Slave, you can use the FB_EcCoESdoRead function block and to write FB_EcCoESdoWrite function block can be used. The EtherCAT Slave must support 'CANopen over EtherCAT' (CoE) protocol to be able to use these function blocks. 

In this tutorial, we will read the 'Analog Input Limit 1' value of channel 2 from EL3002 2 channels analog input terminal and then write a new limit value to CoE parameter.

 Add the Tc2_EtherCAT library into the project. 

ethercatlib

Add the code below in MAIN program and build the solution. 

PROGRAM MAIN
VAR
	fbEcCoESdoRead			: FB_EcCoESdoRead;
	bReadAnalogInputLimit1  : BOOL;
	fbEcCoESdoWrite			: FB_EcCoESdoWrite;
	bWriteAnalogInputLimit1 : BOOL;
	SlaveNetID 	AT %I* 	    : T_AmsNetIdArr;			(* AMS Net ID EL3002 *)
	SlavePort  	AT %I*  	    : WORD;				(* Port number EL3002 *)
	fAnalogInputLimit1		    : REAL := 0; 				(* Analog Input Limit 1 *)
	bReadError      : BOOL;
        nReadErrId      : UDINT;
	bWriteError     : BOOL;
        nWriteErrId     : UDINT;
	tTimeout         : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR


(* Read the Analog Input Limit 1 CoE parameter *)
fbEcCoESdoRead(
	sNetId:= F_CreateAmsNetId(SlaveNetID), 
	nSlaveAddr:= SlavePort, 
	nSubIndex:= 13, (* Subindex of CoE Object *)
	nIndex:= 16#8010 , (* CoE Object Index *)
	pDstBuf:= ADR(fAnalogInputLimit1), 
	cbBufLen:= SIZEOF(fAnalogInputLimit1), 
	bExecute:= bReadAnalogInputLimit1, 
	tTimeout:= tTimeout, 
	bBusy=> , 
	bError=> bReadError, 
	nErrId=> nReadErrId, 
	cbRead=> );
	
	
(* Write to Analog Input Limit 1 CoE parameter *)
FB_EcCoESdoWrite(
	sNetId:= F_CreateAmsNetId(SlaveNetID),
	nSlaveAddr:=SlavePort ,
	nSubIndex:=13, (* Subindex of CoE Object *)
	nIndex:=16#8010 , (* CoE Object Index *)
	pSrcBuf:=ADR(fAnalogInputLimit1) ,
	cbBufLen:=SIZEOF(fAnalogInputLimit1) ,
	bExecute:= bWriteAnalogInputLimit1,(* TRUE activate writing *)
	tTimeout:= tTimeout,
	bBusy=> ,
	bError=> ,
	nErrId=> );

IF NOT FB_EcCoESdoWrite.bBusy THEN
	bWriteAnalogInputLimit1 := FALSE;
	IF NOT FB_EcCoESdoWrite.bError THEN
		(* write successful *)
        bWriteError := FALSE;
        nWriteErrId := 0;
	ELSE
		(* write failed *)
        bWriteError := FB_EcCoESdoWrite.bError;
        nWriteErrId := FB_EcCoESdoWrite.nErrId;
	END_IF
	FB_EcCoESdoWrite(bExecute := FALSE);
END_IF

 

After the build, link the SlavePort and SlaveNetID to terminal's netID and port, which located under the InfoData.AddsAddr of the terminal. 

link

 

To find the index and the subindex values of CoE object, double click on the terminal and go to 'CoE-Online' tab. Find the CoE object and note the index and subindex values. For this tutorial, 'Analog input limit 1' of channel 2 is used and the index value of this CoE object is '16#8010' and the subindex is '13' as it can be seen below: 

indexsubindex

 

Toggle the bReadAnalogInputLimit1 to read the current 'Analog input limit 1'. Set the new desired value by writing the value to fAnalogInputLimit1 variable and set the bWriteAnalogInputLimit1 variable to TRUE. You can toggle again the bReadAnalogInputLimit1 to ensure new limit is written into the CoE object. 

 

 

Reply
Share: