Skip to content

4.8 报警信息

4.8.1 获取最严重的一条报警

方法名Alarm.GetTopAlarm()
描述获取当前最严重的一条报警信息
请求参数无参数
返回值string: 报警信息字符串
StatusCode: 获取操作执行结果
兼容的机器人软件版本协作 (Copper): v7.5.0.0+
工业 (Bronze): v7.5.0.0+

示例代码

Alarm/GetTopAlarm.cs
cs
using Agilebot.IR;
using Agilebot.IR.Types;

public class GetTopAlarm
{
    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] 获取最严重的一条报警
            // [EN] Get the most severe alarm
            string topError;
            (topError, code) = controller.Alarm.GetTopAlarm();
            if (code == StatusCode.OK)
            {
                Console.WriteLine("获取最严重报警成功/Get Top Alarm Success");
                if (string.IsNullOrEmpty(topError))
                {
                    Console.WriteLine("当前无报警/No current alarms");
                }
                else
                {
                    Console.WriteLine($"最严重报警/Most Severe Alarm: {topError}");
                }
            }
            else
            {
                Console.WriteLine($"获取最严重报警失败/Get Top Alarm 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.8.2 获取所有的活动的报警

方法名Alarm.GetAllActiveAlarms()
描述获取所有当前活动的报警信息
请求参数无参数
返回值List<string>: 报警信息列表
StatusCode: 获取操作执行结果
兼容的机器人软件版本协作 (Copper): v7.5.0.0+
工业 (Bronze): v7.5.0.0+

示例代码

Alarm/GetAllActiveAlarms.cs
cs
using Agilebot.IR;
using Agilebot.IR.Types;

public class GetAllActiveAlarms
{
    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] 获取所有的活动的报警
            // [EN] Get all active alarms
            List<string> errors;
            (errors, code) = controller.Alarm.GetAllActiveAlarms();
            if (code == StatusCode.OK)
            {
                Console.WriteLine("获取所有活动报警成功/Get All Active Alarm Success");
                Console.WriteLine($"活动报警数量/Active Alarm Count: {errors.Count}");

                if (errors.Count == 0)
                {
                    Console.WriteLine("当前无活动报警/No active alarms");
                }
                else
                {
                    Console.WriteLine("活动报警列表/Active Alarm List:");
                    for (int i = 0; i < errors.Count; i++)
                    {
                        Console.WriteLine($"  {i + 1}. {errors[i]}");
                    }
                }
            }
            else
            {
                Console.WriteLine($"获取所有活动报警失败/Get All Active Alarm 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.8.3 复位错误

方法名Alarm.ResetAlarms()
描述复位错误
请求参数无参数
返回值StatusCode: 函数执行结果
兼容的机器人软件版本协作 (Copper): v7.5.0.0+
工业 (Bronze): v7.5.0.0+