Menu

Readline 解析器

注释:可以自定义换行符,遇到换行符时发送,默认为’\r\n’,对应ASCII为0D 0A;但目前打hex日志时为乱码

new Readline(options?)

A transform stream that emits data after a newline delimiter is received. To use the Readline parser, provide a delimiter (defaults to \n). Data is emitted as string controllable by the encoding option (defaults to utf8).

Arguments

  • options.delimiter?: string delimiter to use
  • options.encoding?: string text encoding for the stream

例子

const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
const port = new SerialPort('/dev/tty-usbserial1')

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

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