SetConfiguredIoCount

配置模拟 I/O 模组的数量。模拟 I/O 的数量取决于有多少给定值超过实际的硬体数量,若给定值大于实际 I/O 的数量,KINGSTAR 会显示所有实际轴与模拟轴。例如,有五个实际 I/O 而给定值为七,则会显示五个实际 I/O 及两个模拟 I/O;若给定值小于或等于实际 I/O 的数量,KINGSTAR 会显示所有实际 I/O 的数量,而无模拟 I/O。

语法

KsError SetConfiguredIoCount(
     int Count
);

参数

Count:模拟 I/O 模组的数量。最大值为 256。

回传值

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

备注

此函式只可在模拟 I/O 模组使用,模拟 I/O 模组必须先使用 SetConfiguredIoCount 建立后,才可用 ConfigureIo 配置,此函式必须在 Create 后及 Start 前呼叫。一旦连结建立,模拟 I/O 即无法修改。

可用的 EtherCAT 状态

ecatOffline

范例

复制
/////////////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates how to configure simulated hardware
// in KINGSTAR subsystem. Please be aware that if any actual hardware
// detected in the bus scan procedure the configuration will be replaced
// by automated configuration.
//
/////////////////////////////////////////////////////////////////////////

#define AXIS_COUNT  2
#define IO_COUNT    3

// Variable declaration
KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
SubsystemStatus Subsystem = { ecatOffline, ecatOffline, 0, 0, 0, {ecatOffline}, {ecatOffline}, {axisOffline} };
int axesCount = 0, ioCount = 0;

// Link to the KINGSTAR subsystem
nRet = Create(0, 0);

nRet = SetConfiguredAxesCount(AXIS_COUNT);
nRet = SetConfiguredIoCount(IO_COUNT);

for (int i = 0; i < AXIS_COUNT; i++)
{
    SlaveStatus axisDefinition = { "Simulated Axis", 0 };
    
    // Assign resolution for the simulated axes
    nRet = ConfigureAxis(0, axisDefinition, 131072);
}

for (int i = 0; i < IO_COUNT; i++)
{
    SlaveStatus simulatedIo = { "Simulated IO", 0 };
    
    // Assign input length for the simulated IOs
    simulatedIo.InputLength = 32;
    nRet = ConfigureIo(i, simulatedIo);
}

// By setting the timeout to a short interval and abort Start() on timeout,
// KINGSTAR subsystem will stop scanning for real hardware and start with
// the simulated hardware instead.
Command = WaitForCommand(2, TRUE, Start());

// Get the configured hardware count. It can be used by another KINGSTAR application process.
nRet = GetConfiguredAxesCount(&axesCount);
nRet = GetConfiguredIoCount(&ioCount);

使用需求

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

参见

ConfigureIo

GetConfiguredIoCount