调硬件开门

调硬件开门

    Eapp.this.kaimen = function (name, cmds) {
        if (typeof cmds == "string") {
            cmds = [cmds];
        }

        JsBridge.require("SerialPort").open({
                name: name,
                stop_bits: 1,
                baud_rate: 9600,
                data_bits: 8,
                parity: "none", //odd even
            },
            function (ret) {
                for (var i = 0; i < cmds.length; i++) {
                    setTimeout(
                        function () {
                            JsBridge.require("SerialPort").write({
                                    id: this.sid,
                                    data: cmds[this.i],
                                    data_type: "hex",
                                },
                                function (a, b) {
                                    console.log(arguments);
                                }
                            );
                        }.bind({
                            i: i,
                            sid: ret.id
                        }),
                        i === 0 ? 10 : (i * 200)
                    );
                }
            }
        );
    };

  

posted @ 2020-10-09 09:53  野鹤亦闲云  阅读(102)  评论(0编辑  收藏  举报