Menu

ByteLength 解析器

注释:大概意思是定义了一个长度为length字节的buffer,串口收到数据后先放到buffer中,放满了才发送给程序,超出的部分等buffer发送清空后继续放入

new ByteLength(options)

Emit data every number of bytes.

A transform stream that emits data as a buffer after a specific number of bytes are received. Runs in O(n) time.

Arguments

  • options.length: number the number of bytes to be emitted on each data event

例子

const SerialPort = require('serialport')
const ByteLength = require('@serialport/parser-byte-length')
const port = new SerialPort('/dev/tty-usbserial1')

const parser = port.pipe(new ByteLength({length: 8}))
parser.on('data', console.log) // will have 8 bytes per data event
上一篇 下一篇
讨论数量: 0

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
刻意练习,每日精进。
~
点赞
225
浏览
0
讨论