PageSourceSearch

https://serialport.io/assets/js/2d964cda.49243384.js

js serialport.io collected 2026-10-03 23:55:47 UTC 4,579 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkserialport_website=self.webpackChunkserialport_website||[]).push([[6348],{3905:(e,r,t)=>{t.d(r,{Zo:()=>c,kt:()=>f});var a=t(7294);function n(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);r&&(a=a.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,a)}return t}function s(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?o(Object(t),!0).forEach((function(r){n(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function i(e,r){if(null==e)return{};var t,a,n=function(e,r){if(null==e)return{};var t,a,n={},o=Object.keys(e);for(a=0;a<o.length;a++)t=o[a],r.indexOf(t)>=0||(n[t]=e[t]);return n}(e,r);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)t=o[a],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(n[t]=e[t])}return n}var p=a.createContext({}),l=function(e){var r=a.useContext(p),t=r;return e&&(t="function"==typeof e?e(r):s(s({},r),e)),t},c=function(e){var r=l(e.components);return a.createElement(p.Provider,{value:r},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var r=e.children;return a.createElement(a.Fragment,{},r)}},m=a.forwardRef((function(e,r){var t=e.components,n=e.mdxType,o=e.originalType,p=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),u=l(t),m=n,f=u["".concat(p,".").concat(m)]||u[m]||d[m]||o;return t?a.createElement(f,s(s({ref:r},c),{},{components:t})):a.createElement(f,s({ref:r},c))}));function f(e,r){var t=arguments,n=r&&r.mdxType;if("string"==typeof e||n){var o=t.length,s=new Array(o);s[0]=m;var i={};for(var p in r)hasOwnProperty.call(r,p)&&(i[p]=r[p]);i.originalType=e,i[u]="string"==typeof e?e:n,s[1]=i;for(var l=2;l<o;l++)s[l]=t[l];return a.createElement.apply(null,s)}return a.createElement.apply(null,t)}m.displayName="MDXCreateElement"},497:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>p,contentTitle:()=>s,default:()=>d,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var a=t(7462),n=(t(7294),t(3905));const o={id:"api-parsers-overview",title:"What are Parsers?"},s=void 0,i={unversionedId:"api-parsers-overview",id:"version-7.x.x/api-parsers-overview",title:"What are Parsers?",description:"Parsers are collection of transform streams to processes incoming data",source:"@site/versioned_docs/version-7.x.x/api-parsers-overview.md",sourceDirName:".",slug:"/api-parsers-overview",permalink:"/docs/7.x.x/api-parsers-overview",draft:!1,editUrl:"https://github.com/serialport/website/edit/master/versioned_docs/version-7.x.x/api-parsers-overview.md",tags:[],version:"7.x.x",lastUpdatedBy:"Francis Gulotta",lastUpdatedAt:1731036255,formattedLastUpdatedAt:"Nov 8, 2024",frontMatter:{id:"api-parsers-overview",title:"What are Parsers?"},sidebar:"version-7.x.x/guides",previous:{title:"Stream Interface",permalink:"/docs/7.x.x/api-stream"},next:{title:"ByteLength Parser",permalink:"/docs/7.x.x/api-parser-byte-length"}},p={},l=[{value:"Example",id:"example",level:2}],c={toc:l},u="wrapper";function d(e){let{components:r,...t}=e;return(0,n.kt)(u,(0,a.Z)({},c,t,{components:r,mdxType:"MDXLayout"}),(0,n.kt)("p",null,"Parsers are collection of transform streams to processes incoming data"),(0,n.kt)("p",null,"The default ",(0,n.kt)("inlineCode",{parentName:"p"},"Parsers")," are ",(0,n.kt)("a",{parentName:"p",href:"https://nodejs.org/api/stream.html#stream_class_stream_transform"},"Transform streams")," that process incoming data. To use the parsers, you must create them and then pipe the Serialport to the parser. Be careful to only write to the SerialPort object and not the parser."),(0,n.kt)("h2",{id:"example"},"Example"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const SerialPort = require('serialport')\nconst Readline = require('@serialport/parser-readline')\nconst port = new SerialPort('/dev/tty-usbseri
1al1')\nconst parser = new Readline()\nport.pipe(parser)\nparser.on('data', console.log)\nport.write('ROBOT PLEASE RESPOND\\n')\n")),(0,n.kt)("p",null,"Creating the parser and piping can be shortened to"),(0,n.kt)("pre",null,(0,n.kt)("code",{parentName:"pre",className:"language-js"},"const parser = port.pipe(new Readline());\n")))}d.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.