跳到内容 跳到主导航 跳到页脚

电动门能力

介绍

通过 API 可以控制电动门的开关,以及查询电动门的状态。API 需要使用 9.7 及以上的release 库

打开或者关闭电动门

注意:发送开关门命令前,最好查询下当前电门状态,在电动门非运行状态,执行开关门操作;电动门运行状态值:Definition.CAN_DOOR_STATUS_RUNNING,详见“查询仓门状态”指令。在发送开关门指令后,立即调用查下状态接口,会获取不到状态,建议参照下面注册监听,在仓门开、关状态发生变化后,会在监听里响应。

RobotApi.getInstance().setElectricDoorCtrl(0, doorCmd, new CommandListener() {
    @Override
    public void onResult(int result, String message, String extraData) {
        super.onResult(result, message, extraData);
        Log.d(TAG, "setElectricDoorCtrl result:" + result + " message:" + message);
        if (result == 1 && TextUtils.equals(message, Definition.SUCCEED)) {
            Log.d(TAG, "onResult: The electric door is controlled successfully");
        } else {
            Log.d(TAG, "onResult: The electric door is controlled failed");
        }
    }
});

doorCmd参数:

Definition.CAN_DOOR_DOOR1_DOOR2_OPEN 打开上面仓门

Definition.CAN_DOOR_DOOR1_DOOR2_CLOSE 关闭上面仓门

Definition.CAN_DOOR_DOOR3_DOOR4_OPEN 打开下面仓门

Definition.CAN_DOOR_DOOR3_DOOR4_CLOSE 关闭下面仓门

Definition.CAN_DOOR_ALL_OPEN 打开所有仓门(调试指令非必要不建议使用)

Definition.CAN_DOOR_ALL_CLOSE 关闭所有仓门(调试指令非必要不建议使用)

注册仓门状态监听

注册电动门状态监听,获取电动门状态,根据自己业务在需要地方注册
当电动门状态发生变化时,会回调onStatusUpdate方法,例如调用开门、关门指令后,电动门状态会发生变化
如果需要在任意时机获取电动门状态,可以调用getElectricDoorStatus方法

//listener 的处理,参考getElectricDoorStatus方法中处理
RobotApi.getInstance().registerStatusListener(Definition.STATUS_CAN_ELECTRIC_DOOR_CTRL, statusListener);

移除仓门监听

在不需要电门状态时候,移除监听,防止内存泄漏

RobotApi.getInstance().unregisterStatusListener(statusListener);

主动查询仓门状态

在任意时机都可以调用该方法查询仓门状态

RobotApi.getInstance().getElectricDoorStatus(0, new CommandListener() {
            @Override
            public void onResult(int result, String message, String extraData) {
                super.onResult(result, message, extraData);
                Log.d(TAG, "getElectricDoorStatus result:" + result + " message:" + message);
                if (result == 1 && !TextUtils.isEmpty(message)) {
                    CanElectricDoorBean doorBean = GsonUtil.fromJson(message, CanElectricDoorBean.class);
                    //door1和 door2是上面的两扇仓门,door3和door4是下面的两扇仓门
                    //上仓门的状态
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor2() ==                                                                                 Definition.CAN_DOOR_STATUS_RUNNING) {
                        Log.d(TAG, "upper door is running");
                        //当仓门正在运动时,不要执行开关门指令
                    }
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_OPEN) {
                        Log.d(TAG, "upper door is open");
                    }
                    if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_CLOSE) {
                        Log.d(TAG, "upper door is close");
                    }
                    //下仓门的状态
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_RUNNING) {
                        Log.d(TAG, "lower door is running");
                        //当仓门正在运动时,不要执行开关门指令
                    }
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_OPEN) {
                        Log.d(TAG, "lower door is open");
                    }
                    if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_CLOSE) {
                        Log.d(TAG, "lower door is close");
                    }

                    //门的堵转状态,开门、关门时可能会出现堵转
                    //关门时,被堵
                    if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
                        Log.d(TAG, "upper door is block and bounce");
                    }
                    if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
                        Log.d(TAG, "lower door is block and bounce");
                    }
                    //开门时,被堵
                    if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
                        Log.d(TAG, "upper door is blocking stop");
                    }
                    if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
                        Log.d(TAG, "lower door is blocking stop");
                    }
                } else {
                    Log.d(TAG, "getElectricDoorStatus onResult: Failure to get status");
                }
            }
        });

状态说明:

Definition.CAN_DOOR_STATUS_RUNNING:电动门正在执行任务

Definition.CAN_DOOR_STATUS_OPEN:仓门打开

Definition.CAN_DOOR_STATUS_CLOSE:仓门关闭

Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE:关门时候被堵(出现该情况,移除阻挡物后重试)

Definition.CAN_DOOR_STATUS_BLOCKING_STOP:开门时候被堵(出现该情况,移除阻挡物后重试)

使用说明:

上仓门分为两扇门,返回为 door1 和 door2;下仓门为两扇门,返回 door3 和 door4。

查询上仓门状态可以同时判断 door1 和 door2 状态,查询下仓门状态可以同时判断 door3 和 door4 状态;

在使用打开或者关闭仓门命令后,立即去查询,此时仓门正在打开或者关闭,得不到预期的已经打开或者已经关闭状态,需要延迟一定时间查询。

具体使用参考 Demo

豹小秘豹小秘2mini招财豹招财豹Pro豹小秘DP豹小递Pro

这篇文章是否有帮助?

0