Nodejs:附加事件监听器到数组如果包含值

在我的项目中,我有四个对象(硬件解码器的连接器),显然是同步的。 和我得到解密的string数组(队列)。 有无论如何如何检查数组是否包含解码器对象的一些值? 我想我可以通过EventEmitters来完成,但我不知道如何。

感谢帮助

-Update

来自另一台服务器的传入值是64位string,解码器返回15位值。 对于通过串口进行通讯,我使用了这个SerialPort封装。 我知道如何与一个解码器进行通信,但不知道如何与更多(以适当的方式)。

我的代码与一个解码器通信。

var SerialPort = require('serialport'); var ports = []; ports.push( {device: new SerialPort('/dev/cu.usbmodem1411', { autoOpen: false }), enable: true}); ports.push( {device: new SerialPort('/dev/cu.usbmodem1421', { autoOpen: false }), enable: true}); //id: incoming encrypted value module.exports.decryption = function (id, callback) { ports[0].enable = false; var idArray = []; idArray[0] = id.slice(0, 16); idArray[1] = id.slice(16, 32); idArray[2] = id.slice(32, 48); idArray[3] = id.slice(48, 64); ports[0].device.open(function (err) { if (err) { return console.log('Error opening port: ', err.message); } port[0].device.write('d01'); let index = 0; var buffer = setInterval(function () { port[0].device.write(idArray[index]); if (index === idArray.length - 1) clearInterval(buffer); index++; }, 1); }); ports[0].device.on('data', function (data) { callback( hex2a(data.toString('ascii'))); ports[0].device.close(function (response) { console.log("device disconnected") },function (error) { }); ports[0].enable = true; }); }; function hex2a(hexx) { var hex = hexx.toString();//force conversion var str = ''; for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); return str; }