4.5 IO Signals
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 signal value of the specified type and port. |
| Request Parameters | type : SignalType IO signal type to read index : int IO port index to read, starting from 1 |
| Return Value | int: IO signal value, 1 represents high level, 0 represents low level StatusCode: Read operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
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 signal value of the specified type and port. |
| Request Parameters | type : SignalType IO signal type to write index : int IO port index to write, starting from 1 value : double Signal value to write, 1 represents high level, 0 represents low level |
| Return Value | StatusCode: Write operation execution result |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | UI/UO signals 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 Signals
| Method Name | Signals.MultiWrite(SignalType type , List<int> ioData ) |
|---|---|
| Description | Batch write multiple DO ports with a flattened list of port/value pairs. |
| Request Parameters | type : SignalType DO only ioData : List<int> like [port1, state1, port2, state2, ...] , length must be even |
| Return Value | StatusCode: write 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 are read-only, DI/RI support single-point read only |
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 Signals
| Method Name | Signals.MultiRead(SignalType type , List<int> indexes ) |
|---|---|
| Description | Batch read multiple DO ports; returned values align with the input order. |
| Request Parameters | type : SignalType DO only indexes : List<int> ports to read, at least one index required |
| Return Value | List<int> values (ordered as input) plus StatusCode |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
| Note | Only DO supports batch read; UI/UO are read-only, DI/RI support single-point read only |
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.");
}
}