[英]Unhandled ''error'' event in Node.JS
我正在嘗試通過node.js激活RFID閱讀器,然后將標簽發送回去。
效果很好。 它讀取標簽,用ID響應,然后將ID發送到ping節點客戶端。
但是,每次node.JS程序從RFID標簽中拾取一組數據后,在發送后都會關閉,並顯示以下錯誤:
events.js:72
throw er; // Unhandled 'error' event
^
Error: EBADF, read
這將導致節點進程始終退出。 這可能是什么問題?
我的代碼如下;
// Socket.io server details
var io = require('socket.io').listen(3000);
// Serialport plugin declared and made a serialport variable
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
// Variable containing technical USB port details
var serialPort = new SerialPort("/dev/ttyUSB0",
{baudrate: 2400, parser: serialport.parsers.readline("\n")},
false); // this is the openImmediately flag [default is true]
io.sockets.on('connection', function (socket) {
console.log('user connected');
socket.on('ping', function (data) {
serialPort.open(function () {
// Open notification
console.log('open');
//Start listening
serialPort.on('data', function(data) {
// If content is empty, filter out
if (data.trim() !== '') {
line = data;
//Execute function again, get tag, handle tag and end process
serialPort.close(function () {
console.log('De uiteindelijke tag is ' + data);
console.log('Ping received with data: ' + data);
socket.emit('pong', data);
console.log('closing');
});
console.log('hallo');
}
});
});
});
});
添加一個偵聽器以處理串行端口中的錯誤,例如以下代碼:
serialPort.on('error', function(error) {
console.log('The error: '+error);
//...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.