serialport-bindings-webserial
v0.2.3
Published
WebSerial bindings for serialport.
Downloads
19
Readme
SUMMARY
WebSerial bindings for serialport module.
INSTALL
- Install module:
npm i serialport-bindings-webserial
- Import a module into your code:
import { SerialPortStream } from '@serialport/stream'; import { WebSerialBinding } from 'serialport-bindings-webserial';
EXAMPLES
List available and paired ports:
let ports = await WebSerialBinding.list(); console.log(ports);
Open any port:
The browser will show pop-up with all available ports.
let port = await new SerialPortStream({ binding: WebSerialBinding, path: 'webserial://any', baudRate: 115200 });
Open any port with custom options for SerialPort.open:
The browser will show pop-up with all available ports.
let webSerialOpenOptions = { bufferSize: 4 * 1024 // https://developer.mozilla.org/en-US/docs/Web/API/SerialPort/open#buffersize }; let port = await new SerialPortStream({ binding: WebSerialBinding, path: 'webserial://any', baudRate: 115200, webSerialOpenOptions });
Open any port with filters:
The browser will show pop-up with all available ports which fit the requested filter.
let webSerialRequestOptions = { filters: [{ usbVendorId: 0x067B, usbProductId: 0x2303 }] }; let port = await new SerialPortStream({ binding: WebSerialBinding, path: 'webserial://any', baudRate: 115200, webSerialRequestOptions });
Open with native SerialPort:
You can open a port using reference to the native SerialPort object.
let webSerialPort = await navigator.requestPort({}); let port = new SerialPortStream({ binding: WebSerialBinding, path: 'webserial://any', baudRate: 115200, webSerialPort });
Open port by virtual path:
let ports = await WebSerialBinding.list(); let port = new SerialPortStream({ binding: WebSerialBinding, path: ports[0].path, // for example: webserial://usb0 baudRate: 115200, });
NOTES
You need something like vite-plugin-node-polyfills
or node-stdlib-browser
for using the serialport
module in the browser.