EthercatSlaveImpl
- Namespace
- ZPlatform
- Extends
- Inherited Properties
- Inherited Methods
- Implements
The function block implements the most common commands that are needed by a developer when communicating with a EtherCAT slave device.
- The object contains variables that have to be linked to Process Data Objects (PDO) and will fail if PDOs are not linked correctly
- When starting, this function block is in its Booting state. Here, the object tries to gather information about the slave devices identity and (optional) set an initial state for the slave device. If this is not possible or fails for any reason (e.g. incorrect linking, the device is not connected, ...) the object transitions into BootingError. If everything is ok, the object transitions into its Idle state.
- While the object is idle, it continously monitors if the requested state (FB_init (optional) or RequestStateAsync) differs from the actual state of the device. If it differs, it transitions for at least 1 cycle to an Error state that can be polled externally. Also, the object automatically reads the mailbox of the Ethercat Slave device and append its content to its ErrorMessage.
- While in idle state, the object accepts external state requests by calls to RequestStateAsync.
This implementation is a wrapper around the following TwinCAT function blocks.
By extending from PlatformAdapterObject error codes that are returned by these function blocks are returned nicely as strings and follow Beckhoff's specification in regard to error codes.
Note that this object comes with an initial booting phase that requires some cycles to execute. So initially this object is busy and to be more specific the object is in its Booting state when creating this object.
FUNCTION_BLOCK EthercatSlaveImpl EXTENDS ZPlatform.PlatformAdapterManagedObject IMPLEMENTS ZCore.IManagedObject, ZCore.IObject, ZCore.IBootable, ZCore.IError
Constructor
FB_init
When constructing this object an optional initial state of the EtherCAT slave device can be provided.
If initialState <> 0
, the object tries to set the appropriate state during the Booting phase of the object.
METHOD FB_init (
bInitRetains : BOOL,
bInCopyCode : BOOL,
parent : ZCore.IManagedObject,
initialState : ZCore.EthercatSlaveState) : BOOL
Inputs
bInitRetains
BOOLif TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode
BOOLif TRUE, the instance afterwards gets moved into the copy code (online change)
parent
IManagedObjectInterface to the ManagedObject that is the parent of this object
initialState
EthercatSlaveState(optional) State that is set during boot, set to 0 if the default settings should be used
Returns
- BOOL
Properties
BootingHints
Suggests when the Cyclic method should be called during the booting phase of the application
It is best to call the cyclic method of this object in every PLC cycle so monitoring works even during booting
PROPERTY BootingHints : ZCore.ManagedObjectBootingHintFlags
Property Value
Simulation
This property can be used at any time to switch the ethercat slave from simulated mode to physical mode. Whenever the nominal flag changes, the instance will get busy and run its Booting sequence. This even works if the slave is in BootingError.
PROPERTY Simulation : BOOL
Property Value
- BOOL
Methods
Cyclic
This method should be called every cycle to enable this class to operate. For details see EthercatSlaveImpl.
METHOD Cyclic ()
EthercatStateDecoded
This method converts the dev and link state of an EtherCAT slave device to human readable text. The Ethercat State Flags can be retrieved by calling the EthercatSateFlags method.
EthercatStateDecoded(16#0101); // return 'INIT; Slave not present;'
EthercatStateDecoded(ZCore.EthercatSlaveStateFlags.PreOp OR ZCore.EthercatSlaveStateFlags.InitializationCommandsError); // return 'PREOP; Initialization error occurred; '
METHOD EthercatStateDecoded (
state : WORD) : ZCore.ZString
Inputs
Returns
EthercatStateFlags
This method returns the state of the EtherCAT slave device in a flags enum. This means that several bits of the returned value can be on or off at once. If simulated, the returned value is always the requested state that is set either in FB_init or with RequestStateAsync).
METHOD EthercatStateFlags () : ZCore.EthercatSlaveStateFlags
Returns
Link
This method returns a pointer to the internal EthercatSlaveInput datatype that is linked to Process Data Objects (PDOs). The method returns a pointer that requires implicit knowledge of the underlying data structure! This is required for providing a platform-independent solution. For instance, TwinCAT and Codesys, while similar, do not share the same workflow when linking to PDOs.
METHOD Link () : ZCore.ZPointer
Returns
Name
This method returns the name that has been passed with the SetName method concatenated with the string '| EthercatSlave' and the identifier of the object. The later is obtained in the booting sequence when reading the EtherCAT slave device's identity. If simulated, the identifier 'Simulated' is used.
ethercatSlave.SetSimulated(FALSE);
ethercatSlave.SetName('Slave1');
ethercatSlave.Name(); // returns 'Slave1 | EthercatSlave (Simulated) '
The name that is passed here is considered when logging is activated.
METHOD Name () : ZCore.ZString
Returns
RequestStateAsync
Use this method to switch the ethercat slave device into any state. If
the object is busy while the method is called, the startToken
that is passed will inform about this and the
actual request will not be performed. EthercatSlaveImpl can only perform 1 task at a given time, this includes booting.
If a special state should be set during booting, please use the parameter in FB_init.
METHOD RequestStateAsync (
startToken : ZCore.IStartToken,
state : ZCore.EthercatSlaveState)
Inputs
startToken
IStartToken(optional) object to check if the method was executed successfully - may be 0
state
EthercatSlaveStaterequested ethercat state in which this function block should switch to
SetLink
Calling this method in TwinCAT has no effect, in- and output variables of the object is directly linked in the IDE.
METHOD SetLink (
linkPtr : ZCore.ZPointer)
Inputs
linkPtr
ZPointerPointer to an external link variable -> not used on Twincat systems
SetLogger
Use this function to enable logging for this EthercatSlaveImpl instance.
If no Logging Instance is given here (logger=0
), logging is deactivated.
METHOD SetLogger (
logger : ZCore.ILogger)
Inputs
logger
ILoggerinterface to a Zeugwerk compatible logger instance
SetName
This method can be used to give a name to the Ethercat slave instance, which is useful if logging is used. Note that the name that is passed is prefixed with ' | EthercatSlave'. Also the getter Name appends more details to this instance (i.e. the ethercat slave device's identifier).
METHOD SetName (
name : ZCore.ZString)
Inputs
name
ZStringName of the EthercatSlave Instance, usually the name of the device which is connected on the Ethercat fieldbus
SetSimulation
This method can be used at any time to switch the ethercat slave from simulated mode to physical mode. Whenever the nominal flag changes, the instance will get busy and run its Booting sequence. This even works if the slave is in BootingError.
METHOD SetSimulation (
on : BOOL)
Inputs
SetTimeout
Sets the timeout values for communicating with the EtherCAT slave device. If any command takes longer than this timeout to execute, an error will be thrown and can be signaled with Error. If no user specific Timeout is set, the default Timeout set in DefaultTimeout is used.
METHOD FINAL SetTimeout (
timeout : LREAL)
Inputs
WcState
The method returns the state of the working counter for the ethercat slave device whose Process Data Objects are mapped to this instance. It is an easy way to find out if data is sent and received correctly to the device. If any error occurs, this objects additionally transitions into its error state (for at least 1 cycle) and ErrorMessage can be used to retrieve informations about the error.
METHOD WcState () : BOOL
Returns
- BOOL