【问题标题】:"exit" event is thrown after board is "ready"板子“准备好”后引发“退出”事件
【发布时间】:2016-11-27 20:22:39
【问题描述】:

我正在尝试控制插入我的树莓派 2 的 3 个 LED,我安装了 johnny-5 来做到这一点。
我不认为这与问题有关,但安装 johnny-5 时出现了一个小错误,如帖子末尾所述。

我有一个由 angular-fullstack 生成的简单代码,它在启用 johnny-5 之前工作(我可以按按钮调用服务器端,我在客户端得到答案,一切都很好)

然后我像这样添加 johnny-5 ():

'use strict'

var Raspi = require("raspi-io");
var five = require("johnny-five");
var raspi_io = new Raspi();
var board = new five.Board({
 io: raspi_io // if I comment this line, server won't stop, but then I can't access my led, which is the goal of raspi-io...
});

board.on("ready", () => {
    console.log("Board ready !");
});

当我运行 sudo grunt serve 时会得到这些日志:

董事会准备就绪!
Express 服务器在 9000 上侦听,处于开发模式
KO:(调试日志)在 repl.js (johnny-5) 中检测到退出信号
1469358904063 董事会闭幕
停止 Express 服务器
等待完成!

然后,我可以看到板子“就绪”事件已被触发,所以看起来不错。但是随后,董事会关闭了,服务器也关闭了,我不明白为什么。我添加了尽可能多的日志,但看不到“退出”事件的触发位置。我被困在这里(在 johnny-5 的 repl.js 中):

  this.cmd = cmd;
  this.context = cmd.context;

  cmd.on("exit", function() {
    // this is the triggered event, can't find where the cmd.exit is triggered...
    state.board.emit("exit");
    state.board.warn("Board", "Closing.");
    process.nextTick(process.reallyExit);
  });

另外,我注意到“闪烁”在 LED 上不起作用(如果我在就绪函数中使用它们),无论我设置什么参数...

版本和安装:

npm -v
3.8.6
nodejs -v
5.11.1

并以这种方式安装 johnny-5:

sudo npm install johnny-5 raspi-io --save
npm WARN 可选 跳过失败的可选依赖项 /chokidar/fsevents:
npm WARN notsup 与您的操作系统或架构不兼容:fsevents@1.0.14 npm WARN karma-phantomjs-launcher@1.0.0 需要 phantomjs-prebuilt@>=1.9 的对等点,但没有安装。

当我尝试安装 fsevents(或 phantomjs-prebuilt)时:

sudo npm install fsevents --save
npm 错误! notsup 与您的操作系统或架构不兼容:fsevents@1.0.14
npm 错误! notsup 有效操作系统:darwin
npm 错误! notsup 有效拱门:任何
npm 错误! notsup 实际操作系统:linux
npm 错误! notsup 实际拱门:arm

问题:

有人知道为什么服务器停止了吗?

【问题讨论】:

  • 也许“板”对象以某种方式被杀死,这可以解释“退出”事件,但没有理由......(或者我可能遗漏了一些东西......)

标签: node.js raspberry-pi2 angular-fullstack johnny-five


【解决方案1】:

如果有人遇到此问题,请尝试:

 const board = new five.Board({
        repl: false,
        port: 'COM3'
    });

【讨论】:

    猜你喜欢
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    相关资源
    最近更新 更多