WSCOM serial proxy
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 { var connection = 'ws://localhost:1311/_list'; connection { console } connection { ports = JSON; connection; if callback ; for var i=0;i<portslength;i++ var cn = portsicomName; //Fix a common name ; };}
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 10myConn.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 1myConn.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
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