4.5 IO Signals
Overview
The Signals class provides a unified read/write interface for controller I/O, including:
- Digital/analog input and output operations
- Batch I/O operations
With Signals , you can:
- Read current signal states
- Batch write DO/RO/GO ports
- Integrate grippers, sensors, and production-line devices
4.5.1 Reading the Value of a Specified Type and Port IO
| Method Name | Signals.Read(SignalType type , int index ) |
|---|---|
| Description | Reads the IO value of the specified type and port (supports DI/DO/UI/UO/RI/RO/GI/GO/TAI/TDI/TDO/AI/AO). |
| Request Parameters | type : SignalType IO type to read index : int IO port index, starting from 1 |
| Return Value | int: IO value, 1 represents high level, 0 represents low level StatusCode: Operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | UI/UO can only be read, not written |
Example Code
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class ReadSignal
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "连接成功/Successfully connected.");
if (code != StatusCode.OK)
{
return code;
}
try
{
// [ZH] 设置IO信号类型和索引
// [EN] Set IO signal type and index
SignalType type = SignalType.DI;
int index = 1;
// [ZH] 读取指定类型指定端口IO的值
// [EN] Read specified type and port IO value
int res;
(res, code) = controller.Signals.Read(type, index);
if (code == StatusCode.OK)
{
Console.WriteLine("读取IO信号成功/Read Signal Success");
Console.WriteLine($"{type}:{index} 的值为/has value {res}");
Console.WriteLine($"信号状态/Signal Status: {(res == 1 ? "高电平/High Level" : "低电平/Low Level")}");
}
else
{
Console.WriteLine($"读取IO信号失败/Read Signal Failed: {code.GetDescription()}");
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.5.2 Writing the Value of a Specified Type and Port IO
| Method Name | Signals.Write(SignalType type , int index , double value ) |
|---|---|
| Description | Writes the IO value of the specified type and port, currently only supports DO/RO/GO/TDO/AO. |
| Request Parameters | type : SignalType IO type to write index : int IO port index, starting from 1 value : double IO value (DO/RO/TDO only allow 0 or 1; GO is integer; AO is floating-point analog) |
| Return Value | StatusCode: Operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | UI/UO can only be read, not written |
Example Code
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class WriteSignal
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "连接成功/Successfully connected.");
if (code != StatusCode.OK)
{
return code;
}
try
{
// [ZH] 设置IO信号类型、索引和值
// [EN] Set IO signal type, index and value
SignalType type = SignalType.DO;
int index = 1;
int value = 1;
// [ZH] 写指定类型指定端口IO的值
// [EN] Write specified type and port IO value
code = controller.Signals.Write(type, index, value);
if (code == StatusCode.OK)
{
Console.WriteLine("写入IO信号成功/Write Signal Success");
Console.WriteLine($"{type}:{index} 设置为/set to value {value}");
Console.WriteLine($"信号状态/Signal Status: {(value == 1 ? "高电平/High Level" : "低电平/Low Level")}");
}
else
{
Console.WriteLine($"写入IO信号失败/Write Signal Failed: {code.GetDescription()}");
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.5.3 Batch Write DO (Digital Output) Signals
| Method Name | Signals.MultiWrite(SignalType type , List<int> ioData ) |
|---|---|
| Description | Batch write DO (Digital Output) signals. |
| Request Parameters | type : SignalType IO type to write (DO only) ioData : List<int> Port number and port value list (e.g., [port1, state1, port2, state2]; length must be even and greater than 0) |
| Return Value | StatusCode: Operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | Only DO supports batch write; UI/UO do not support writing, DI/RI only support single-point read |
Example Code
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class Test
{
public static async Task Main()
{
string controllerIP = "10.27.1.254";
Arm controller = new Arm(controllerIP);
StatusCode code = await controller.Connect();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "Successfully connected.");
// Batch write DO1=1, DO2=0
code = controller.Signals.MultiWrite(SignalType.DO, new List<int> { 1, 1, 2, 0 });
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "MultiWrite Success");
code = controller.Disconnect();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "Successfully disconnected.");
}
}4.5.4 Batch Read DO (Digital Output) Port Values
| Method Name | Signals.MultiRead(SignalType type , List<int> indexes ) |
|---|---|
| Description | Batch read DO (Digital Output) port values. |
| Request Parameters | type : SignalType IO type to read (DO only) indexes : List<int> Port number list (cannot be empty) |
| Return Value | List<int>: Port value list (order consistent with input) StatusCode: Operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | Only DO supports batch read; UI/UO do not support writing, DI/RI only support single-point read |
Example Code
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class Test
{
public static async Task Main()
{
string controllerIP = "10.27.1.254";
Arm controller = new Arm(controllerIP);
StatusCode code = await controller.Connect();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "Successfully connected.");
// Batch read DO1, DO2
(List<int> values, StatusCode readCode) = controller.Signals.MultiRead(SignalType.DO, new List<int> { 1, 2 });
if (readCode == StatusCode.OK)
{
Console.WriteLine($"MultiRead Success: DO1={values[0]}, DO2={values[1]}");
}
code = controller.Disconnect();
Console.WriteLine(code != StatusCode.OK ? code.GetDescription() : "Successfully disconnected.");
}
}