var SerialPort = require("serialport"); class AsicMiner { constructor(dev, baud) { this.ready = false; this.error = null; this._onready = []; this._port = new SerialPort(dev, { baudRate: baud }); this._port.on("error", msg => { this.error = msg; this._onready.forEach(x => x()); }); this._port.on("open", () => { this.ready = true; this._onready.forEach(x => x()); }); this._port.on("data", d => { console.log("From "+dev+": "+d); }); } wait() { return new Promise((resolve, reject) => { if (this.ready) return resolve(); this._onready.push(resolve); }); } } module.exports = AsicMiner;