FB_EcPhysicalReadCmd
The function block FB_EcPhysicalReadCmd sends an EtherCAT read command (FPRD, APRD, BRD) to a specific slave or to all EtherCAT slaves(Broadcast). This command can be sent by the PLC to read out a register or the DPRAM of an EtherCAT Slave Controller.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId;
adp : UINT;
ado : UINT;
len : UDINT;
eType : E_EcAdressingType := eAdressingType_Fixed;
pDstBuf : DWORD;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
sNetId: This is a string that contains the AMS network identifier of the EtherCAT master device.
adp: This value defines which EtherCAT slave is addressed by this command. Which slave is addressed by this value depends on the addressing type defined by eType:
eType | Description |
---|---|
eAdressingType_Fixed | The slave is addressed by its configured EtherCAT address. The EtherCAT addresses of all slaves can be read out with FB_EcGetAllSlaveAddr. |
eAdressingType_AutoInc | The slave is addressed by its position in the bus. The first slave has an address of 0(adp=0) and the adp of all following slaves is decremented by one.
|
eAdressingType_BroadCAST | All slaves are addressed by this command. The value adp can be set to 0. |
ado: Physical memory(DPRAM) or register one wants to read out.
len: Count of bytes to read.
eType: Depending on the value of eType different EtherCAT commands are sent:
eType | Command |
---|---|
eAdressingType_Fixed | Configured Address Physical Read ( FPRD) |
eAdressingType_AutoInc | Auto Increment Physical Read ( APRD) |
eAdressingType_BroadCAST | Broadcast Read ( BRD) |
The individual commands only differ in how the slaves are addressed (see adp).
pDestBuf:The address (pointer) of the receive buffer.
bExecute: The block is activated by a rising edge at this input.
tTimeout: Maximum time allowed for the execution of the function block.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
wkc : UINT;
END_VAR
bBusy: This output is set when the function block is activated and remains set until an acknowledgement is received.
bError: This output is set up after the bBusy output has been reset if there has been an error in transmission of the command.
nErrId: Supplies the ADS error code associated with the most recently executed command if the bError output is set.
wkc: The working counter is incremented by 1 for each EtherCAT slave that is addressed by this command. If only on EherCAT slave is addressed by this command, the working counter will be 1.
Sample for an implementation in ST:
PROGRAM TEST_PhysicalReadCmd
VAR
fbReadCmd : FB_EcPhysicalReadCmd;
bExecute : BOOL;
value : UINT;
adp : UINT:=16#3E9;
ado : UINT:=16#1100;
eType : E_EcAdressingType := eAdressingType_Fixed;
sNetId : T_AmsNetId:='192.168.1.5.3.1';
wkc : UINT;
bError : BOOL;
nErrId : UDINT;
END_VAR
fbReadCmd (sNetId:=sNetID, ado:=ado, adp:=adp, eType:=eType, LEN := SIZEOF(value), pDstBuf:=ADR(value), bExecute:=bExecute);
wkc := fbReadCmd.wkc;
bError:=fbReadCmd.bError;
nErrId:=fbReadCmd.nErrId;
Requirements
Development Environment | Target System | PLC Libraries to include |
---|---|---|
TwinCAT v2.10.0 Build >= 1314 or higher | PC or CX (x86) | TcEtherCAT.Lib |
TwinCAT v2.10.0 Build >= 1314 or higher | CX (ARM) |