|
12345678910111213141516171819202122232425262728293031323334353637 |
- 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;
|