javascript - Nodejs: Attach Event Listener to Array If contains value -
in project have 4 objects (connectors hw decoders), synchronous. , array (queue) of strings decryption. there anyway how check if array contains values decoder objects? think can via eventemitters, don't know how.
thanks help
-update
incoming value server 64bites string, decoder returns 15 bites value. communication via serial port i'm using package serialport. know how communication 1 decoder, don't know how more (in proper way).
my code communication 1 decoder.
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 = ''; (var = 0; < hex.length; += 2) str += string.fromcharcode(parseint(hex.substr(i, 2), 16)); return str; }
Comments
Post a Comment