如何以编程方式在信号模式下使用raspistill?

时间:2016-10-02 17:41:29

标签: javascript node.js raspbian raspberry-pi2

我正在尝试使用Raspberry Pi,相机和raspistill实用程序。 下面是在Node.js下执行的JavaScript代码片段。这段代码的想法是以“信号”模式启动Raspistill程序,缓存子进程,并在每次调用sendSnapshot函数时向其发送'USR1'信号。我希望Raspisill将快照数据输出到stdout,我想将该数据写入http响应流。但是,on('data')不会被调用。我的代码出了什么问题?

private static raspistill = null;

public sendSnapshot(httpResponse: stream.Writable) {
    if (!Camera.raspistill) {
        console.log(this.getTimestamp() + 'Starting...');
        Camera.raspistill = spawn('raspistill', ['-w', '640', '-h', '480', '-q', '5', '-o', '-', '-n', '-t', '0', '-s']);  
    }

    Camera.raspistill.stdout.on('data', (data) => {
        httpResponse.write(data, 'base64');
    });
    Camera.raspistill.stdout.on('close', (code) => {
        console.log(this.getTimestamp() + 'Closed...');
        httpResponse.end();
    });
    Camera.raspistill.kill('SIGUSR1');
}

0 个答案:

没有答案