3.7 IoSignals IO Class
Overview
Signals handles single-point and batch IO read/write operations. After Arm is connected, access the instance through arm.ioSignals ; no separate initialization is required. The SDK groups digital signals, group signals, and analog signals under SignalType .
Supported Scope
| Interface | Supported Scope |
|---|---|
Read | Supports all SignalType values |
Write integer overload | Supports only DO , RO , GO , TDO |
Write floating-point overload | Supports only AO |
MultiRead | Supports only DO |
MultiWrite | Supports only DO |
Port Number Scope
- Pass the controller-side port number.
3.7.1 Read Single IO
Read(SignalType type, int32_t index) -> std::pair<Float64, STATUS_CODE>| Item | Description |
|---|---|
| Description | Reads one IO channel. Digital, group, and analog signals all return Float64 |
| Request Parameters | type : SignalType signal type (DI/DO/UI/UO/RI/RO/GI/GO/TAI/TDI/TDO/AI/AO) index : int32_t port number |
| Return Value | Float64: value read from the signal STATUS_CODE: function execution result |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
3.7.2 Write Single Digital Signal
Write(SignalType type, int32_t index, int32_t value) -> STATUS_CODE| Item | Description |
|---|---|
| Description | Writes one digital signal or integer group signal |
| Request Parameters | type : SignalType signal type (only DO/RO/GO/TDO are supported) index : int32_t port number value : int32_t value to write |
| Return Value | STATUS_CODE: function execution result |
| Notes | Unsupported signal types return UNSUPPORTED_SIGNAL_TYPE |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
3.7.3 Write Single Analog Signal
Write(SignalType type, int32_t index, Float64 value) -> STATUS_CODE| Item | Description |
|---|---|
| Description | Writes one analog signal; only used for AO |
| Request Parameters | type : SignalType signal type (only AO is supported) index : int32_t port number value : Float64 value to write |
| Return Value | STATUS_CODE: function execution result |
| Notes | Unsupported signal types return UNSUPPORTED_SIGNAL_TYPE |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
3.7.4 Batch Read
MultiRead(SignalType type, const std::vector<int32_t>& portList) -> std::pair<std::vector<int32_t>, STATUS_CODE>| Item | Description |
|---|---|
| Description | Batch-reads IO; only DO is supported |
| Request Parameters | type : SignalType signal type (only DO is supported) portList : std::vector<int32_t> port number list |
| Return Value | std::vector<int32_t>: values read, in the same order as portList STATUS_CODE: function execution result |
| Notes | Unsupported signal types return UNSUPPORTED_SIGNAL_TYPE ; an empty portList returns INVALID_PARAMETER |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
3.7.5 Batch Write
MultiWrite(SignalType type, const std::vector<int32_t>& ioList) -> STATUS_CODE| Item | Description |
|---|---|
| Description | Batch-writes IO. The flat parameter format is [port1, value1, port2, value2, ...] ; only DO is supported |
| Request Parameters | type : SignalType signal type (only DO is supported) ioList : std::vector<int32_t> flattened port/value list |
| Return Value | STATUS_CODE: function execution result |
| Notes | Unsupported signal types return UNSUPPORTED_SIGNAL_TYPE ; an empty ioList or an odd number of elements returns INVALID_PARAMETER |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
Flat Parameter Format
ioList alternates port numbers and values:
// Write DO[0]=1, DO[1]=0, DO[2]=1
std::vector<int32_t> ioList = {0, 1, 1, 0, 2, 1};
// Equivalent to [port0, value0, port1, value1, port2, value2]3.7.6 Trigger IO at Time Intervals
TriggerIOWithIntervals(int32_t inPort, const std::vector<int32_t>& intervals, const std::vector<int32_t>& outPorts, int32_t pulseDuration) -> STATUS_CODE| Item | Description |
|---|---|
| Description | After the input is triggered, drives multiple output ports at the specified intervals |
| Request Parameters | inPort : int32_t input port number intervals : std::vector<int32_t> trigger interval list, in milliseconds outPorts : std::vector<int32_t> output port number list pulseDuration : int32_t pulse duration, in milliseconds |
| Return Value | STATUS_CODE: function execution result |
| Compatible Robot Software Versions | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
Parameter Constraints
intervalsmust not be empty.outPortsmust not be empty.pulseDurationmust be greater than0.
Trigger Logic
When the specified input port inPort is triggered, the output ports in outPorts are driven in sequence according to the intervals defined in intervals . Each output pulse lasts pulseDuration milliseconds.
Minimal Call Example
#include <iostream> // Standard output stream for printing IO read results
#include <vector> // std::vector for batch IO port lists
#include "arm_api.h" // Arm entry point; after connection, signal APIs are accessed through arm.ioSignals
#include "status_code.h" // STATUS_CODE for checking SDK call results
int main()
{
Arm arm;
STATUS_CODE connectRet = arm.Connect("192.168.110.2", "");
if (connectRet != STATUS_CODE::OK) {
return 1;
}
auto [di0, diRet] = arm.ioSignals.Read(SignalType::DI, 0);
if (diRet != STATUS_CODE::OK) {
return 1;
}
std::cout << "DI[0]=" << di0 << "\n";
auto [doBatch, multiRet] = arm.ioSignals.MultiRead(
SignalType::DO,
std::vector<int32_t>{0, 1, 2}
);
if (multiRet != STATUS_CODE::OK) {
return 1;
}
std::cout << "batch_count=" << doBatch.size() << "\n";
// STATUS_CODE writeRet = arm.ioSignals.Write(SignalType::DO, 0, 1);
// STATUS_CODE multiWriteRet = arm.ioSignals.MultiWrite(
// SignalType::DO,
// std::vector<int32_t>{0, 1, 1, 0, 2, 1}
// );
return 0;
}Scenario Examples
The snippets below cover read, write, and pulse-trigger scenarios. They assume the arm object from the minimal example is already connected. Writing IO or triggering IO changes controller outputs; run these calls only after checking the site conditions.
Read Single and Batch IO
auto [singleValue, readRet] = arm.ioSignals.Read(SignalType::DI, 0);
auto [batchValues, multiReadRet] = arm.ioSignals.MultiRead(SignalType::DO, std::vector<int32_t>{0, 1, 2});
if (readRet == STATUS_CODE::OK && multiReadRet == STATUS_CODE::OK) {
std::cout << "DI[0]=" << singleValue << " batch_count=" << batchValues.size() << "\n";
}Write Digital and Analog Signals
// STATUS_CODE writeIntRet = arm.ioSignals.Write(SignalType::DO, 0, 1);
// STATUS_CODE writeFloatRet = arm.ioSignals.Write(SignalType::AO, 0, Float64{1.0});
// STATUS_CODE multiWriteRet = arm.ioSignals.MultiWrite(SignalType::DO, std::vector<int32_t>{0, 1, 1, 0});Trigger IO at Time Intervals
std::vector<int32_t> intervals = {100, 200};
std::vector<int32_t> values = {0, 1};
// STATUS_CODE triggerRet = arm.ioSignals.TriggerIOWithIntervals(0, intervals, values, 50);Example code:
#include "query_signals/run.h"
#include "write_signals/run.h"
int main(void)
{
// [ZH] 默认只调用一个门面方法;如需体验其他接口,请把下一行替换成下面任意一行。
// [EN] The main function calls only one facade by default. Replace the next line with any line below to try other APIs.
return RunSignalsBasicQuerySignals();
// return RunSignalsBasicWriteSignals();
}#include <stdio.h>
extern "C" {
#include "c_arm_api.h"
}
int main(void)
{
// [ZH] 本示例直接在源码中写死连接地址,不解析命令行参数。
// [EN] This example hard-codes the connection addresses in the source code and does not parse command-line arguments.
// [ZH] 创建并连接 SDK 句柄。
// [EN] Create the SDK handle and connect to the robot.
ArmHandle* handle = Arm_Create();
if (handle == NULL) {
printf("[c99_signals] 创建句柄失败 / Failed to create the handle\n");
return 1;
}
int ret = Arm_Connect(handle, "10.27.1.2", "10.27.1.102");
if (ret != 0) {
printf("[c99_signals] 连接失败 / Connect failed, 状态码 / Status code: %d\n", ret);
Arm_Destroy(handle);
return 1;
}
printf("[c99_signals] 机器人连接成功 / Robot connected successfully\n");
// [ZH] 读取单路信号与批量信号。
// [EN] Read a single signal and a batch of signals.
double diValue = 0.0;
int ports[2] = {0, 1};
int values[2] = {0, 0};
size_t outCount = 0U;
ret = Arm_Signals_Read(handle, ARM_SIGNAL_DI, 0, &diValue);
printf("[c99_signals] Read 状态码 / Read status code: %d, DI[0]=%.6f\n", ret, diValue);
ret = Arm_Signals_MultiRead(handle, ARM_SIGNAL_DI, ports, 2U, values, 2U, &outCount);
printf("[c99_signals] MultiRead 状态码 / MultiRead status code: %d, 数量 / Count: %zu, 值 / Values: [%d, %d]\n",
ret,
outCount,
values[0],
values[1]);
// [ZH] 顺序执行全部写接口。
// [EN] Execute all write APIs in sequence.
ret = Arm_Signals_WriteInt(handle, ARM_SIGNAL_DO, 1, 1);
printf("[c99_signals] WriteInt 状态码 / WriteInt status code: %d\n", ret);
ret = Arm_Signals_WriteFloat(handle, ARM_SIGNAL_AO, 1, 1.5);
printf("[c99_signals] WriteFloat 状态码 / WriteFloat status code: %d\n", ret);
int ioList[4] = {4, 1, 6, 0};
ret = Arm_Signals_MultiWrite(handle, ARM_SIGNAL_DO, ioList, 4U);
printf("[c99_signals] MultiWrite 状态码 / MultiWrite status code: %d\n", ret);
int intervals[2] = {100, 200};
int outPorts[2] = {4, 5};
ret = Arm_Signals_TriggerIOWithIntervals(handle, 1, intervals, 2U, outPorts, 2U, 60);
printf("[c99_signals] TriggerIOWithIntervals 状态码 / TriggerIOWithIntervals status code: %d\n", ret);
// [ZH] 断开连接并销毁句柄。
// [EN] Disconnect and destroy the handle.
Arm_Disconnect(handle);
Arm_Destroy(handle);
printf("[c99_signals] 示例结束 / Example finished\n");
return 0;
}