Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra Package Web Compat #2

Open
frank-dspeed opened this issue Apr 21, 2021 · 1 comment
Open

Extra Package Web Compat #2

frank-dspeed opened this issue Apr 21, 2021 · 1 comment

Comments

@frank-dspeed
Copy link
Owner

frank-dspeed commented Apr 21, 2021

💥 Proposal

(A clear and concise description of what the proposal is.)
I will implement functions that exist on the WebSerial API on this Project as also Port the most API's of this project to WebSerial.

I want to enable Easyer Code ReUse between the both API's so that serialport and webSerialApi can be used with the same code.

Will Allow people to use node-serialport as normal with NodeJS while allowing to switch to WebSerialAPI when running in Electron or NW.JS or the Browser.

Implementation State

Adding API to node-serialport

Properties

SerialPort.readable // Read only Returns a ReadableStream for receiving data from the device connected to the port.
SerialPort.writable // Read only Returns a WritableStream for sending data to the device connected to the port.

Event handlers

SerialPort.onconnect //An event handler called when the port has connected to the device.
SerialPort.ondisconnect //An event handler called when the port has disconnected from the device.

Methods

SerialPort.getInfo() // Returns a Promise that resolves with an object containing properties of the port.
SerialPort.open() // Returns a Promise that resolves when the port is opened. By default the port is opened with 8 data bits, 1 stop bit and no parity checking.
SerialPort.setSignals() Sets control signals on the port and returns a Promise that resolves when they are set.
SerialPort.getSignals() Returns a Promise that resolves with an object containing the current state of the port's control signals.
SerialPort.close() Returns a Promise that resolves when the port closes.
SerialPort.getPorts().then((ports) // a alias of SerialPort.list()
SerialPort.requestPort({ filters: [{ usbVendorId }]}).then((ports) // a alias of SerialPort.list().then(filter)
SerialPort.pipeThrough(new TextDecoderStream()) // alias pipe()
SerialPort.pipeTo(appendStream); //alias pipe()

filters supports
usbVendorId: An unsigned short integer that identifies a USB device vendor.
usbProductId: An unsigned short integer that identiffies a USB device.

Web StreamAPI

Break Able Read maybe implement able via https://github.com/MattiasBuelens/web-streams-polyfill

const { value, done } = port.read();

Connect disconnect aliases open close?

// TODO: event.port || event.target 
navigator.serial.addEventListener("connect", (event) => {
  // TODO: Automatically open event.target or warn user a port is available.
});

navigator.serial.addEventListener("disconnect", (event) => {
  // TODO: Remove |event.target| from the UI.
  // If the serial port was opened, a stream error would be observed as well.
});

Related Issues

@frank-dspeed
Copy link
Owner Author

const readUntilClose = stream => {
    
    let done = false;
    stream.on('close', () => done = true);
    
    return () => {
        const value = stream.read();
        return Promise.resolve({ value, done });
    }
        
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant