Reputation: 43
I am working on a project that requires real-time data acquisition from the serial port. Data flow is really fast and it's basically a list of points measured in real time. I am working with serialport in order to handle the communication part, socket.io to communicate with the client (A web page that contains a chart where points should be plotted). When I send 1 point per second, it works fine but when the data flow is fast (like 1 point/10ms) node.js shows this error:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit
My question is:Is there a solution to handle such a fast flow in real-time? My first thoughts where about using a producer consumer algorithm and a queue to collect data from serial port. What I would like to know if there is more optimized solutions.
The scenario is like this:
Node:js: GET_VALUE
Microcontroller: 1234
Node:js: GET_VALUE
Microcontroller: 5678
My code:
function readFromUART() {
chosenPort.write(cmdGetValue, function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
});
console.log('NODE: GATHER DATA');
parser.on('data', function(data){
console.log(data);
This function is called every X ms
setInterval(readFromUART, 1000);
Upvotes: 1
Views: 1125
Reputation: 43
I found a solution. It's better to use eventemitter3 rather than eventemmiter. It has high performance in real-time applications.
var EventEmitter = require('eventemitter3');
var eventEmitter = new EventEmitter();
Upvotes: 0