1.8.4 • Published 12 months ago

faster-serialport v1.8.4

Weekly downloads
2
License
MIT
Repository
github
Last release
12 months ago

Faster SerialPort

This is a stripped down, more performant version of node-serialport. Actually works normally with Electron.

Currently only supports windows and mac.

API

import FasterSerialPort from "faster-serialport";

const deviceInfos = await FasterSerialPort.list();

const deviceInfo = deviceInfos.filter(d => 
    d.path.indexOf(search) === -1 ||
    d.manufacturer.indexOf(search) === -1 ||
    d.serialNumber.indexOf(search) === -1 ||
    d.pnpId.indexOf(search) === -1 ||
    d.locationId.indexOf(search) === -1 ||
    d.vendorId.indexOf(search) === -1 ||
    d.productId.indexOf(search) === -1
)[0];

const device = new FasterSerialPort(deviceInfo.path, {
    autoOpen: false,
    baudRate: 9600,
    dataBits: 8,
    parity: "none",
    stopBits: 1,
});

await device.open();

device.setTimeout(500); // return prematurely from any operation that takes longer than 500ms

function writeData() {
    const data = Buffer...

    // blocks until write has finished or timeout expires. 
    // If timeout expires, will throw in format "Timeout writing to port: %d of %d bytes written"
    await device.write(data); 
}

function waitForKnownDataSize() {
    
    // blocks until the number of bytes specified are read or the timeout expires.
    // If timeout expires, will return what ever data has been read. 
    // Will not throw if timeout expires
    const data = await device.read(256); 
    if(data.length !== 256) throw new Error("missing data");
}


function pollForAnyData() {
    device.setTimeout(10);
    
    while(true) {
        const data = await device.read(256);

        if(data.length > 0) {
            device.setTimeout(500);
            return data;
        }
    }
}

Credits

This package would not be possible without the folks over at node-serialport. This started out as a fork of their package and has morphed into something new.

Known Issues

Electron on Windows: Some actions fail within the first 5 seconds.

Reloading the page via location.reload() or location = "/" fixes this issue.

Electron: Error: Could not locate the bindings file. Tried:...

  1. Ensure you have electron-builder setup correctly.

e.g. package.json

{
     "scripts": {
        "postinstall": "electron-builder install-app-deps",
     }
}
  1. Symbolicly link <project-root>/prebuilds/<platform>/<target>.node => build/Release/faster-serial-port.node (fixes electron issue with bindings root issue)

Dev

npm install -g prebuildify node-gyp yarn
brew install gcc
1.8.4

12 months ago

1.8.3

1 year ago

1.8.2

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.7.3

2 years ago

1.7.10

2 years ago

1.7.9

2 years ago

1.7.8

2 years ago

1.7.7

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.2

2 years ago

1.6.5

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.8

3 years ago

1.2.9

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago