Menu

Delimiter 解析器

注释:Delimiter【定界符】意思是遇到某个字符时才把buffer中的数据发给程序,比如设为’a’,那么用字符发送时遇到’a’即发送,用hex发送时遇到61(‘a’的ASCII码)时发送;注:官方例子中’\n’字符用串口工具字符发送没生效,但用hex发送其ASCII码(0A)和在node.js项目中可以生效

new Delimiter(options: { delimiter: string | Buffer | number[] })

A transform stream that emits data each time a byte sequence is received. To use the Delimiter parser, provide a delimiter as a string, buffer, or array of bytes. Runs in O(n) time.

Arguments

  • options.delimiter: string|Buffer|number[] The delimiter on which to split incoming data.
const SerialPort = require('serialport')
const Delimiter = require('@serialport/parser-delimiter')
const port = new SerialPort('/dev/tty-usbserial1')

const parser = port.pipe(new Delimiter({ delimiter: '\n' }))
parser.on('data', console.log) // emits data after every '\n'
上一篇 下一篇
讨论数量: 0

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