@signalk/streams 5.1.0 → 5.1.1
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.
- package/package.json +1 -1
- package/serialport.js +24 -34
package/package.json
CHANGED
package/serialport.js
CHANGED
|
@@ -148,44 +148,34 @@ SerialStream.prototype.start = function () {
|
|
|
148
148
|
)
|
|
149
149
|
|
|
150
150
|
let pendingWrites = 0
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
: [
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
stdOutEvents.forEach((event) => {
|
|
158
|
-
const onDrain = () => {
|
|
159
|
-
pendingWrites--
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
that.options.app.on(event, (d) => {
|
|
163
|
-
if (pendingWrites > that.maxPendingWrites) {
|
|
164
|
-
that.debug('Buffer overflow, not writing:' + d)
|
|
165
|
-
return
|
|
151
|
+
const stdOutEvent = this.options.toStdout
|
|
152
|
+
if (stdOutEvent) {
|
|
153
|
+
;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach((event) => {
|
|
154
|
+
const onDrain = () => {
|
|
155
|
+
pendingWrites--
|
|
166
156
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
that.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
|
|
158
|
+
that.options.app.on(event, (d) => {
|
|
159
|
+
if (pendingWrites > that.maxPendingWrites) {
|
|
160
|
+
that.debug('Buffer overflow, not writing:' + d)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
that.debug('Writing:' + d)
|
|
164
|
+
if (isBuffer(d)) {
|
|
165
|
+
that.serial.write(d)
|
|
166
|
+
} else {
|
|
167
|
+
that.serial.write(d + '\r\n')
|
|
168
|
+
}
|
|
169
|
+
setImmediate(() => {
|
|
170
|
+
that.options.app.emit('connectionwrite', {
|
|
171
|
+
providerId: that.options.providerId
|
|
172
|
+
})
|
|
176
173
|
})
|
|
174
|
+
pendingWrites++
|
|
175
|
+
that.serial.drain(onDrain)
|
|
177
176
|
})
|
|
178
|
-
pendingWrites++
|
|
179
|
-
that.serial.drain(onDrain)
|
|
180
177
|
})
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
this.options.app.emitPropertyValue('serialport', {
|
|
184
|
-
id: this.options.providerId,
|
|
185
|
-
eventNames: {
|
|
186
|
-
toStdout: standardOutEventName
|
|
187
|
-
}
|
|
188
|
-
})
|
|
178
|
+
}
|
|
189
179
|
}
|
|
190
180
|
|
|
191
181
|
SerialStream.prototype.end = function () {
|