-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathhelper.js
More file actions
40 lines (35 loc) · 1015 Bytes
/
helper.js
File metadata and controls
40 lines (35 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* global require: false, module */
const events = require("events"),
util = require("util");
class FakeSerialPort extends events.EventEmitter {
constructor() {
super ();
this.bytesWritten = [];
this.flushed = false;
this.isOpen = true;
this.pipeDestination = undefined;
}
write(buffer, callback) {
// Must use array concatenation to handle recording multiple packets
this.bytesWritten = this.bytesWritten.concat(buffer);
if (callback && typeof callback === "function") {
callback();
}
};
pipe(destination) {
this.pipeDestination = destination;
}
flush(callback) {
this.flushed = true;
if (callback && typeof callback === "function") {
callback();
}
};
close(callback) {
this.isOpen = false;
if (callback && typeof callback === "function") {
callback();
}
};
}
module.exports = FakeSerialPort;