问题描述
我正在尝试为 node-seriaport 编写自定义解析器。 (编辑:Like in this question)当我通过管道将 serialPort 流传输到它时,我得到:
TypeError [ERR_INVALID_ARG_TYPE]: The "emitter" argument must be an instance of EventEmitter. Received type string ('unpipe')
代码如下:
var stream = require('stream')
class Parser extends stream.Transform {
constructor() {
super()
this.incomingData = Buffer.alloc(0)
}
_transform(chunk,encoding,cb) {
// chunk is the incoming buffer here
this.incomingData = Buffer.concat([this.incomingData,chunk])
const packet = this.parseBuffer()
this.emit('data',packet)
cb()
}
_flush(cb) {
this.parseBuffer()
this.incomingData = Buffer.alloc(0)
cb()
}
...
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)