npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-serialport-client

v0.0.8

Published

Remote Serialport Client

Downloads

6

Readme

Remote-Serialport

Intro

This is a repository for remote proxying of serial ports.

It is a simple server-client architecture where the server is connected to the serial port and the client connects to the server to read and write to the serial port.

And then, when the client connects to the server, the server will create a virtual serial port on the client side, and the client can read and write to the virtual serial port.

the operation will sync to the server and the server will read and write to the physical serial port.

This Project is divided into two parts:

  1. Remote-Serialport-Server
    • Control Host Physical Serial Port, and virtualize it to the network or IPC.
      • Milestone
        • [ ] Web Socket
        • [ ] Nodejs IPC
        • [ ] Electron utility IPC
  2. Remote-Serialport-Client
    • Connect to the server and read and write to the serial port.
      • Milestone
        • [ ] Web Socket
        • [ ] Nodejs IPC
        • [ ] Electron utility IPC

Why Remote-Serialport

You can also make one yourself But some people have done it, why not just use the kit?

A little bit of history

In the future, maybe we will merge client and server repo into one repo.

Features

  • [ ] Remote Serial Port Protocol ▶
    • [x] Web Socket ▶
      • [x] Connect To Socket Server
      • [x] Socket NameSpace Parser for Serial Port
    • [ ] Inter Process Communication (In planning)
  • [x] Read from serial port ▶
  • [ ] Write to serial port
    • [ ] Web Socket
      • [ ] Write to Serial Port
    • [ ] Inter Process Communication
      • [ ] Write to Serial Port
  • [ ] Others
    • [ ] Security
      • [ ] Web Socket Security
        • [ ] Connect to server with authentication
        • [ ] Connect to server with encryption
      • [ ] Inter Process Communication Security
        • [ ] Message Encryption
        • [ ] Memory Protection
        • [ ] Message Authentication
      • [ ] Architecture
        • [ ] Copy-On-Write Architecture
        • [ ] Multi-Access Architecture

Usage

Server


const { RemoteSerialportServer } = require("node-serialport-server");

const server_options = {
    cors: {
        allowedHeaders: ["*"],
        origin: "*",
        methods: ["GET", "POST", "PUT", "DELETE"]
    }
};

const server = new RemoteSerialportServer(server_options, 17991);
server.listen();

server.of().on("connection", (socket) => {
    socket.port.on("data", (data) => {
        // You can transfer before sending the data
        socket.emit("serialport_packet", data); // Send the data to the client
    });
});


Client

Usual Usage

const { RemoteSerialportClient } = require("node-serialport-client");
const { ByteLengthParser } = require("serialport");

const RSC = new RemoteSerialportClient("ws://localhost:17991"); // Initialize the client with the server address

// In windows
const client = RSC.connect("/COM5", { baudRate: 115200 }); // Connect to the server and get the port

// In linux
const client_linux = RSC.connect("/dev/ttyUSB0", { baudRate: 115200 }); // Connect to the server and get the port

// Mapping remote port COM5 to local port COM17
const serialport = client.create_port("COM17").get_port({
    baudRate: 115200,
    autoOpen: true
});

const parser = serialport.pipe(new ByteLengthParser({ length: 30 }));

parser.on("data", (data) => {
    console.log(data);
});

With Modbus-Serial

const { RemoteSerialportClient } = require("node-serialport-client");;
const ModbusRTU = require("modbus-serial");

const RSC = new RemoteSerialportClient("ws://localhost:17991"); // Initialize the client with the server address

// In windows
const client = RSC.connect("/COM5", { baudRate: 115200 }); // Connect to the server and get the port

// In linux
const client_linux = RSC.connect("/dev/ttyUSB0", { baudRate: 115200 }); // Connect to the server and get the port

// Mapping remote port COM5 to local port COM17
const port = client.create_port("COM17");

// There has two ways to create a modbus client

// first way
// create an empty modbus client
const client = new ModbusRTU();
// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 });


// or you can use the second way

// the second way
const client = new ModbusMaster(port.get_port({ baudRate: 9600 }));

client.setID(1)
client.readHoldingRegisters(3, 2).then((data) => {
    console.log(data)
}).catch((error) => {
    console.log(error)
})