Issues with serialport

On a raspberry pi:

server.js runs but keeps throwing the following error:

Jan 23 01:43:57 lasercnc systemd[1]: Started LaserWeb4 server.
Jan 23 01:43:59 lasercnc lw.comm-server[11498]:
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: ***************************************************************
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: ---- LaserWeb Comm Server 4.0.136 ----
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: ***************************************************************
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: Use… to connect this server.
Jan 23 01:43:59 lasercnc lw.comm-server[11498]:
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: * Updates:
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: Remember to check the commit log on
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: …
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: regularly, to know about updates and fixes, and then when ready
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: update accordingly by running git pull
Jan 23 01:43:59 lasercnc lw.comm-server[11498]:
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: * Support:
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: If you need help / support, come over to
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: …
Jan 23 01:43:59 lasercnc lw.comm-server[11498]: ***************************************************************
Jan 23 01:43:59 lasercnc lw.comm-server[11498]:
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: App connected! (id=0)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: TypeError: SerialPort.list no longer takes a callback and only returns a promise
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Function.SerialPort.list (/home/pi/lw.comm-server/node_modules/@serialport/stream/lib/index.js:651:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace. (/home/pi/lw.comm-server/server.js:162:16)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (events.js:305:20)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (/home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:209:10)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at /home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:177:14
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at processTicksAndRejections (internal/process/task_queues.js:79:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see nodejsorg/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: App connected! (id=1)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: TypeError: SerialPort.list no longer takes a callback and only returns a promise
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Function.SerialPort.list (/home/pi/lw.comm-server/node_modules/@serialport/stream/lib/index.js:651:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace. (/home/pi/lw.comm-server/server.js:162:16)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (events.js:305:20)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (/home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:209:10)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at /home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:177:14
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at processTicksAndRejections (internal/process/task_queues.js:79:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see nodejs
org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: INFO: Requesting Server Config
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: INFO: Requesting Server Config
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: App connected! (id=2)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: TypeError: SerialPort.list no longer takes a callback and only returns a promise
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Function.SerialPort.list (/home/pi/lw.comm-server/node_modules/@serialport/stream/lib/index.js:651:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace. (/home/pi/lw.comm-server/server.js:162:16)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (events.js:305:20)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at Namespace.emit (/home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:209:10)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at /home/pi/lw.comm-server/node_modules/socket.io/lib/namespace.js:177:14
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: at processTicksAndRejections (internal/process/task_queues.js:79:11)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: (node:11498) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
Jan 23 01:44:02 lasercnc lw.comm-server[11498]: INFO: Requesting Server Config

I’m able to connect to the server but not the machine. It only lists com1 and com18 when my arduino board is on /dev/ttyAMA0

It appears that the SerialPort.list function changed recently and breaks server.js.

8.0.3

BREAKING CHANGES

  • drop callback argument on SerialPort.list() (#1943) (145b906]

I’m trying to figure out how to get it to work but I have almost zero python experience (though I do have experience with several other languages. It would be better if someone more knowledgable could come up with a patch.

Well, this is javascript not python. Here’s what a javascript “promise” is:

I’m a backend developer, but just looking at the code, it has examples like this:

serialport.list(function (err, ports) { ... });

I notice that it completely ignores err so you don’t even need to chain in error handling to simply replace it…

Looks like that changes to something like:

serialport.list().then(function(ports) { ... });

If there were error handling, I think the conversion would look like:

serialport.list().then(function(ports) { ... }|).catch(function(err) { ... });

But I’m not a javascript developer, nor do I play one at work or on TV, I’m just reading stack overflow… :roll_eyes:

Without compiling or testing syntax in any way, but just to be concrete about what I’m guessing the change might look like:

diff --git a/server.js b/server.js
index adad236..65e447a 100644
--- a/server.js
+++ b/server.js
@@ -159,13 +159,13 @@ io.sockets.on('connection', function (appSocket) {
     appSocket.emit('interfaces', supportedInterfaces);
     
     // check available ports
-    serialport.list(function (err, ports) {
+    serialport.list().then(function (ports) {
         portsList = ports;
         appSocket.emit('ports', portsList);
     });
-    // reckeck ports every 2s
+    // recheck ports every 2s
     listPortsLoop = setInterval(function () {
-        serialport.list(function (err, ports) {
+        serialport.list().then(function (ports) {
             if (JSON.stringify(ports) != JSON.stringify(portsList)) {
                 portsList = ports;
                 io.sockets.emit('ports', ports);
@@ -195,7 +195,7 @@ io.sockets.on('connection', function (appSocket) {
         writeLog(chalk.yellow('INFO: ') + chalk.blue('FirstLoad called'), 1);
         appSocket.emit('serverConfig', config);
         appSocket.emit('interfaces', supportedInterfaces);
-        serialport.list(function (err, ports) {
+        serialport.list().then(function (ports) {
             appSocket.emit('ports', ports);
         });
         if (isConnected) {
@@ -235,7 +235,7 @@ io.sockets.on('connection', function (appSocket) {
 
     appSocket.on('getPorts', function () { // Refresh serial port list
         writeLog(chalk.yellow('INFO: ') + chalk.blue('Requesting Ports list '), 1);
-        serialport.list(function (err, ports) {
+        serialport.list().then(function (ports) {
             appSocket.emit('ports', ports);
         });
     });

I expect this would ignore errors just as effectively as the old code. :wink:

My bad. I was just working on some python and suffered a brain fart I guess.

That’s pretty much what I was coming up with from looking at examples I found online. I guess I’ll just have to play with it.

I also tried downgrading serialport but it kept installing the latest serialport/bindings.

Thanks,
Duane

Well it’s closer anyways…

The client shows,

Connecting to Server @ 10.1.20.15:8000
Server connected
Machine disconnected
Serial ports detected: [{“path”:"/dev/ttyAMA0"},{“path”:"/dev/ttyS0"}]

No more errors but the client doesn’t show any available ports.

Thanks,
Duane

@cprezzi the code that exists looks like it expects list of objects that way. I don’t actually know what to expect in this code, so I don’t think I’m much more help. :frowning:

Why not just use the correct dependencies, as defined in package.json, which should be taken automatically if installed with npm install?
(most important are node 10, npm 6.4 and serialport 6.2.2)

The package.json I have doesn’t list serialport.

{
  "name": "lw.comm-server",
  "version": "4.0.136",
  "license": "AGPL-3.0",
  "description": "Unified communications server for LaserWeb/CNCweb",
  "author": "github.com/LaserWeb",
  "contributors": [
    "Claudio Prezzi <claudio.prezzi@gmail.com>",
    "Peter van der Walt <peter.plaaswerf@gmail.com>"
  ],
  "repository": {
    "type": "git",
    "url": "git+https://github.com/LaserWeb/lw.comm-server.git"
  },
  "devDependencies": {
    "copyfiles": "1.2.x",
    "electron": "2.0.x",
    "electron-builder": "14.5.x",
    "electron-rebuild": "1.8.x",
    "ncp": "2.0.x"
  },
  "dependencies": {
    "chalk": "*",
    "dotenv": "8.x",
    "libxmljs": "^0.19.7",
    "node-static": "*",
    "request": "*",
    "socket.io": "1.7.x",
    "ws": "^1.1.x"
  },
  "bugs": {
    "url": "https://github.com/LaserWeb/lw.comm-server/issues"
  },
  "homepage": "https://github.com/LaserWeb/lw.comm-server#readme",
  "main": "server.js",
  "scripts": {
    "start": "echo \"Please run 'npm run dist' to create a local installer, or run 'npm run nightlylinux' or 'npm run nightlywindows' to build distributable installers for each platform\" ",
    "test": "echo \"Error: no test specified\" && exit 0",
    "update_lw4": "git rm app/ -r -f && cp ../LaserWeb4/dist/. app/ -r -u && git add app/",
    "dist": "npm run copy && build",
    "distmac": "npm run copy && build --mac ",
    "distwinx86": "npm run copy && build --win --ia32 ",
    "distwinx64": "npm run copy && build --win --x64",
    "distlinx86": "npm run copy && build --linux --ia32 ",
    "distlinx64": "npm run copy && build --linux --x64",
    "copy": "ncp ../LaserWeb4/dist/ app/ --limit=6",
    "nightlywindows": "cd ../LaserWeb4 && git checkout dev-es6 && git pull && npm run installdev && npm run bundle-dev && cd .. && cd lw.comm-server && git checkout electron_bundler && git pull && npm install && npm run distwinx64 && cd ./dist && mv *.exe ../../LaserWeb4-Binaries/win64/ && cd .. && npm run distwinx86 && cd ./dist && mv *.exe ../../LaserWeb4-Binaries/win32/ && cd ../../LaserWeb4-Binaries",
    "nightlylinux": "cd ../LaserWeb4 && git checkout dev-es6 && git pull && npm run installdev && npm run bundle-dev && cd .. && cd lw.comm-server && git checkout electron_bundler && git pull && npm install && npm run distlinx64 && cd ./dist && mv *.exe ../../LaserWeb4-Binaries/linux64/ && cd .. && npm run distlinx86 && cd ./dist && mv *.exe ../../LaserWeb4-Binaries/linux32/ && cd ../../LaserWeb4-Binaries"
  },
  "keywords": [
    "laserweb",
    "cncweb",
    "grbl",
    "smoothieware",
    "tinyg",
    "usb",
    "serial",
    "ethernet",
    "gateway",
    "ESP8266"
  ],
  "engines": {
    "node": ">=10.15.1",
    "npm": ">=6.4.1"
  },
  "build": {
    "appId": "xyz.laserweb",
    "productName": "LaserWeb",
    "asar": true,
    "files": [
      "**/*"
    ],
    "win": {
      "icon": "app/favicon.ico"
    },
    "mac": {
      "icon": "build/icon.icns",
      "category": "public.app-category.graphics-design"
    },
    "dmg": {
      "icon": "build/icon.icns",
      "contents": [
        {
          "x": 410,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        },
        {
          "x": 130,
          "y": 150,
          "type": "file"
        }
      ]
    }
  }
}

I followed the directions on the wiki, which also doesn’t say anything about serialport.

I don’t know why your package.json don’t have the serialport dependency, but without that, lw.comm-server could not work. I would suggest to download the actual master branch of lw.comm-server, which has the serialport dependency on line 27.

I searched for laserweb and came up with the link: github.com/LaserWeb/LaserWeb4

This repository is a “development environment” - and no regular user would have to touch this at all (dont download the repo from here, use the Download links below)

Download

Releases are made available on github.com/LaserWeb/LaserWeb4-Binaries/

So I followed the link

LaserWeb4-Binaries

Installers for LaserWeb4

Windows Users: Download exe from github.com/LaserWeb/LaserWeb4-Binaries/releases

Mac Users: Download dmg from github.com/LaserWeb/LaserWeb4-Binaries/releases

Linux Users: Download AppImage from github.com/LaserWeb/LaserWeb4-Binaries/releases

Selected “Linux Users”…

[Latest release]
v4.0.996-134
@jorgerobles jorgerobles released this on Jan 15, 2019

LaserWeb for Mac and PC (dev-es6).

22e0f7e Jorge Robles 2018-06-29 Xregexp install natives

Assets
4
LaserWeb.Setup.4.0.996-134.exe
36.4 MB
latest.yml
228 Bytes
Source code
(zip)
Source code
(tar.gz)

serialport is not listed in package.json in either “Source code” download.

The Master branch is selected and it looks like you made the last commit.

Tried fetching with ‘git clone https://github.com/LaserWeb/lw.comm-server.git

It fails trying to build serialport

3352 verbose stack Error: serialport@6.2.2 install: prebuild-install || node-gyp rebuild
3352 verbose stack Exit status 1
3352 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
3352 verbose stack at EventEmitter.emit (events.js:305:20)
3352 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
3352 verbose stack at ChildProcess.emit (events.js:305:20)
3352 verbose stack at maybeClose (internal/child_process.js:1028:16)
3352 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
3353 verbose pkgid serialport@6.2.2
3354 verbose cwd /home/pi/lw.comm-server
3355 verbose Linux 4.19.66-v7+
3356 verbose argv “/usr/bin/node” “/usr/local/bin/npm” “install”
3357 verbose node v13.5.0
3358 verbose npm v6.13.4
3359 error code ELIFECYCLE
3360 error errno 1
3361 error serialport@6.2.2 install: prebuild-install || node-gyp rebuild
3361 error Exit status 1
3362 error Failed at the serialport@6.2.2 install script.

For a Raspberry Pi you only need the lw.comm-server. Please follow the instructions in the wiki

or the website
https://laserweb.yurl.ch/documentation/installation/36-install-raspberry-pi

It is important to use the correct versions of NodeJS, NPM (as stated in the instructions) to be able to compile Serialport!

You was not able to compile it, because you used NodeJS 13 (not 10).

NodeJS version should be >= 10.15.1

My undersrtanding is that this means the NodeJS version should be equal to, or greater than, 10.15.1. If that is the case then 13.5.0 would satisfy the stated requirement.

Or am I reading it wrong?

Thanks,
Duane

I understand this could be missunderstud, but the big title before that line says Install Node 10.x :wink:

I will add a hint.

Ok, I completely blew away nodejs and started over.

Seems to be working fine now. Just a little bump trying to figure out why it wasn’t recognizing the firmware.

Thanks for your patience and help.

Duane

You are welcome. I’m happy I could help.