RequestSlaveState
Requests an EtherCAT slave to go into the specified EtherCAT state. For example, if the state is Op, and your requested state is PreOp, the slave will change the state to Op -> SafeOp -> PreOp. If the state is Init and your requested state is Op, the slave will change the state to Init -> PreOp -> SafeOp -> Op.
Syntax
KsCommandStatus RequestSlaveState(
int SlaveId,
EthercatState State
);
Parameters
SlaveId: the slave index. This index value is automatically assigned by the KINGSTAR master when the EtherCAT network starts, based on the physical connection order. The first device connected directly to the master is assigned Index 0, followed by Index 1, Index 2, and so on. These indexes remain consistent within the slave array even if devices are added, removed, or reconnected. Please refer to the use cases in HotConnect, Repair, and Restart for more details.
State: the requested EtherCAT state. See the EthercatState type.
Return value
Returns the KsCommandStatus structure.
Remarks
- Both EtherCAT master and slave need to be in one of the supported states.
- It is not possible to request the EtherCAT state that is higher than the master state. For further details about which states the master supports, see RequestState.
Usable EtherCAT states
ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP
Example
SlaveStatus sStatus = { 0 };
nRet = GetSlaveById(0, &sStatus);
if (nRet == errNoError)
{
if (sStatus.State != ecatOffline) {
// You can follow the EtherCAT state diagram, or just enter the desired state.
// Switch to Init
WaitForCommand(3, TRUE, RequestSlaveState(0, ecatInit));
// Operate the slave in Init state
// Switch to Bootstrap
WaitForCommand(3, TRUE, RequestSlaveState(0, ecatBoot));
// Operate the slave in Bootstrap state
// Switch back to original state
WaitForCommand(3, TRUE, RequestSlaveState(0, sStatus.State));
}
}
Requirements
| RT | Win32 | |
|---|---|---|
| Minimum supported version | 4.0 | 4.0 |
| Header | ksapi.h | ksapi.h |
| Library | KsApi_Rtss.lib | KsApi.lib |
See also