wscom

0.1.1 • Public • Published

WSCOM serial proxy

NPM Version NPM Downloads NPM Downloads Codacy Badge

WSCOM serial port proxy for ASM80.com

Installation

The prerequisite you have to meet is a functional Node.js environment. It is not complicated, it exists for all major platforms, and you can download it here: nodejs.org. During the installation, package manager called NPM is installed too.

NPM is used for install the packages and libraries. To install WSCOM itself just run a command prompt and type:

$ npm install wscom -g

Usage

$ wscom

API

$ wscom runs a daemon (service), which establish a WebSocket server on localhost:1311. It has main entry endpoint, called _list, which provides a list of available serial ports, and endpoints for each serial port.

Get ports

After connecting to ws://localhost:1311/_list caller gets a JSON object with port names. Due to differences between name conventions in Windows and macOS/Linux, the Windows port names are mangled like /null/COM1 etc.

var getPorts = function(callback) {
 
    var connection = new WebSocket('ws://localhost:1311/_list');
        connection.onerror = function(e) {
            console.log("Cannot connect to wscom",e)
            alert("WSCOM is not running. Please install <a href=https://www.npmjs.com/package/wscom>WSCOM tool</a>, run it and reload this page!")
 
        }
 
    connection.onmessage = function (e) {
        ports = JSON.parse(e.data);
        connection.close();
        if (callback) callback(ports);
 
        for (var i=0;i<ports.length;i++) {
            var cn = ports[i].comName.replace("/null/",""); //Fix a common name
            $("#comports").append("<option value='"+ports[i].comName+"'>"+cn+"</option>");
        }
    };
}

Connect to serial port

Once you have an available serial port name, you can connect through ws://localhost:1311/_port_/_params_/_speed_.

  • port is the port URL from the list (/dev/ttyusb0 or /null/com1 etc.)
  • params is "8-N-1" now, all other connection parameters are ignored in this alpha version
  • speed is the baud speed.

So e.g. ws://localhost:1311/dev/ttyusb0/8-N-1/19200

When the connection is established, the port is open and all incoming data are sent through WebSocket message.

Sending data is a little bit complex. You can decide between two forms:

  • myConn.send(JSON.stringify({"code":10})) sends a binary code 10
  • myConn.send(JSON.stringify({"key":'A'})) sends a code 65 (=ASCII code for uppercase A)

You can set DTR and CTS signals too:

  • myConn.send(JSON.stringify({"dtr":1})) sets DTR signal to 1
  • myConn.send(JSON.stringify({"cts":1})) sets CTS signal to 1

These signals sometimes work as a RESET etc.

Close port

Closing WebSocket connection closes serial port and releases it.

Support me

paypal

More info

See https://www.uelectronics.info/category/my-projects/ for more info

or http://www.asm80.com for online IDE, based on this assembler

Readme

Keywords

none

Package Sidebar

Install

npm i wscom

Weekly Downloads

4

Version

0.1.1

License

MIT

Unpacked Size

22.1 kB

Total Files

8

Last publish

Collaborators

  • adent