GetStatus

获取 EtherCAT 连结的状态。使用此函式来看连结建立的时间,连结建立后,即可存取 I/O 与伺服器模组的数量。

语法

KsError GetStatus(
     SubsystemStatus* Status,
     SubsystemDiagnostics* Diagnostics
);

参数

Status:显示 EtherCAT 连结状态的 SubsystemStatus 结构指标。

Diagnostics:显示 EtherCAT 从站状态之诊断资讯的 SubsystemDiagnostics 结构指标。

回传值

如果此函式执行成功,会回传 errNoError,否则会传回错误码。如需更多有关错误码的资讯,请参阅 KsError 清单。

可用的 EtherCAT 状态

ecatOffline, ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP

范例

复制
//////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates a basic flow of how to link to
// KINGSTAR subsystem and use the APIs to configure subsystem and
// control the EtherCAT network and motion devices.
//
//////////////////////////////////////////////////////////////////

KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
SubsystemStatus Subsystem = { ecatOffline, ecatOffline, 0, 0, 0, {ecatOffline}, {ecatOffline}, {axisOffline} };

// Link to the KINGSTAR subsystem.
// If the KINGSTAR subsystem does not exist, it would create a new KINGSTAR subsystem.
// You have to call this API first before you use other KINGSTAR functions.
nRet = Create(0, 0);

// Check if the subsystem is started.
// A new KINGSTAR subsystem is not started by default.
nRet = GetStatus(&Subsystem, NULL);
if (Subsystem.State == ecatOP)
{
    RtPrintf("Subsystem already started: %x\n", nRet);
}
else if (nRet == errNoError && Subsystem.State == ecatOffline)
{
    // When the subsystem state is ecatOffline, you can use below APIs to configure settings:
    //
    // Subsystem Configuration APIs
    // Axis Variable APIs
    // AddModuleConfiguration()
    // RemoveModuleConfiguration()
    // SetConfigurationAxseCount()
    // SetConfigurationIoCount()
    //
    // If you just want to use the default setting, skip this part and start the subsystem.

    // Start the subsystem. It would change the subsystem state to ecatOP.
    // This function is asynchronous so the network is not started yet when it returns.
    // Use WaitForCommand() for synchronization.
    Command = WaitForCommand(30, TRUE, Start());
}

// Now the subsystem state is ecatOP, you can use below APIs to control the subsystem and devices:
//
// Subsystem Control
// Slave Control
// Axis Control
// IO Control
// Heartbeat
// COM API
// Motion API
//
// You can also change the subsystem state or slave state.
// Please check "Usable EtherCAT states" section and the API pages to find out
// which functions you can use in different states.

// Stop the EtherCAT network before destroying KINGSTAR Subsystem or before re-configuration.
Command = WaitForCommand(5, FALSE, Stop());
if (Command.Error)
{
    RtPrintf("Stop Failed: %d\n", Command.ErrorId);
}

// Terminates the KINGSTAR Subsystem if there is no other application connected to it.
nRet = Destroy();
if (nRet != errNoError)
{
    RtPrintf("Destroy Failed: %x\n", nRet);
}

使用需求

  RT Win32
最低支援版本 4.0 4.0
标头档 ksapi.h ksapi.h
程式库 KsApi_Rtss.lib KsApi.lib

参见

GetIOByIndex

GetSlaveById

GetStatusEx

RequestSlaveState

RequestState