树莓派串口一段时间后自动停止

Raspberry serial port automatically stops after some time

我正在使用带 raspberry pi 3 的 neo 6m gps 模块,我已将它连接到串行端口 ttyAMA0 上,但它只读取很短的时间数据,然后端口自动关闭,有时数据也会损坏这会导致 gps.js 模块抛出错误。

Execution Demo screenshot.

下面是我的节点 js 脚本:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);


var file = '/dev/ttyAMA0';

const SerialPort = require('serialport');
const parsers = SerialPort.parsers;

const parser = new parsers.Readline({
  delimiter: '\r\n'
});

const port = new SerialPort(file, {
  baudRate: 9600
});

port.pipe(parser);


var GPS = require('../../gps.js');
var gps = new GPS;

gps.on('GGA', function(data) {
  io.emit('position', data);
  console.log("Latitiude :", data.lat);
  console.log("Longitude :", data.lon);
});

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/maps.html');
});

http.listen(3000, function() {

  console.log('listening on *:3000');
});

port.on('data', function(data) {    
  gps.updatePartial(data);
});

process.on('unhandledRejection', function (reason, p) {
  //I just caught an unhandled promise rejection, since we already have fallback handler for unhandled errors (see below), let throw and let him handle that
  console.log("=============");
  console.log(reason);
  console.log("=============");
  return;
});

process.on('rejectionHandled', () => {});

process.on('uncaughtException', function (error) {
    console.log(error);
});

port.on('close', function(data) {

  console.log("Port closed");
  console.log(port.binding);

    });

Output screenshot

我通过重新安装 raspbian 解决了问题,OS 由于某种原因关闭了端口