incyclist-devices 2.0.10 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,8 +15,6 @@ const utils_2 = require("../../../utils/utils");
|
|
|
15
15
|
const __1 = require("../..");
|
|
16
16
|
const ByteLength = require('@serialport/parser-byte-length');
|
|
17
17
|
const nop = () => { };
|
|
18
|
-
const TIMEOUT_START = 15000;
|
|
19
|
-
const TIMEOUT_CLOSE = 5000;
|
|
20
18
|
const TIMEOUT_SEND = 2000;
|
|
21
19
|
class Daum8008 {
|
|
22
20
|
constructor(props) {
|
|
@@ -78,7 +76,7 @@ class Daum8008 {
|
|
|
78
76
|
this.connected = true;
|
|
79
77
|
this.sp = port;
|
|
80
78
|
this.sp.on('close', this.onPortClose.bind(this));
|
|
81
|
-
this.sp.on('error',
|
|
79
|
+
this.sp.on('error', this.onPortError.bind(this));
|
|
82
80
|
return true;
|
|
83
81
|
}
|
|
84
82
|
else {
|
|
@@ -98,7 +96,10 @@ class Daum8008 {
|
|
|
98
96
|
return;
|
|
99
97
|
this.stopWorker();
|
|
100
98
|
yield this.flush();
|
|
101
|
-
|
|
99
|
+
try {
|
|
100
|
+
yield this.serial.closePort(this.portName);
|
|
101
|
+
}
|
|
102
|
+
catch (_a) { }
|
|
102
103
|
this.connected = false;
|
|
103
104
|
if (this.sp)
|
|
104
105
|
this.sp.removeAllListeners();
|
|
@@ -136,7 +137,7 @@ class Daum8008 {
|
|
|
136
137
|
if ((this.closing || this.closed) && (err.message === 'Port is not open' || err.message === 'Writing to COM port (GetOverlappedResult): Operation aborted'))
|
|
137
138
|
return;
|
|
138
139
|
const state = { opening: this.opening, connected: this.connected, closing: this.closing, closed: this.closed, busy: this.cmdBusy };
|
|
139
|
-
this.logEvent({ message: "port error:", port: this.getPort(), error: err.message,
|
|
140
|
+
this.logEvent({ message: "port error:", port: this.getPort(), error: err.message, state });
|
|
140
141
|
this.error = err;
|
|
141
142
|
this.cmdBusy = false;
|
|
142
143
|
}
|
|
@@ -176,20 +176,23 @@ class SerialInterface extends events_1.default {
|
|
|
176
176
|
openPort(path) {
|
|
177
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
178
|
this.logEvent({ message: 'opening port', path });
|
|
179
|
-
const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
|
|
180
|
-
if (!port) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
179
|
const existing = this.ports.findIndex(p => p.path === path);
|
|
184
180
|
if (existing !== -1) {
|
|
185
181
|
const port = this.ports[existing].port;
|
|
186
182
|
if (port.isOpen) {
|
|
183
|
+
this.logEvent({ message: 'opening port - port already exists', path });
|
|
187
184
|
return port;
|
|
188
185
|
}
|
|
189
186
|
else {
|
|
190
187
|
this.ports.splice(existing, 1);
|
|
191
188
|
}
|
|
192
189
|
}
|
|
190
|
+
this.logEvent({ message: 'opening port - getSerialPort()', path });
|
|
191
|
+
const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
|
|
192
|
+
if (!port) {
|
|
193
|
+
this.logEvent({ message: 'opening port - port does not exist', path });
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
193
196
|
return new Promise((resolve) => {
|
|
194
197
|
port.once('error', (err) => {
|
|
195
198
|
this.logEvent({ message: 'error', path, error: err.message || err });
|
|
@@ -216,8 +219,11 @@ class SerialInterface extends events_1.default {
|
|
|
216
219
|
if (!port.isOpen)
|
|
217
220
|
return true;
|
|
218
221
|
port.on('error', () => { });
|
|
219
|
-
|
|
220
|
-
|
|
222
|
+
try {
|
|
223
|
+
port.flush();
|
|
224
|
+
yield port.drain();
|
|
225
|
+
}
|
|
226
|
+
catch (_a) { }
|
|
221
227
|
return new Promise(resolve => {
|
|
222
228
|
port.close(err => {
|
|
223
229
|
if (!err) {
|