I am getting the following error on a Raspberry pi 3 B+ when using the modbus node.
(node:747) UnhandledPromiseRejectionWarning: Error: Port is not open
at fs.write (/home/pi/.node-red/node_modules/@serialport/bindings/lib/unix-write.js:49:25)
at FSReqWrap.wrapper [as oncomplete] (fs.js:509:5)
(node:747) 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(). (rejection id: 3)
(node:747) [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.
It is strange because this happens on a new Pi Zero W and an older Pi 3B+ but works fine on an older Pi Zero. I have tried older versions of Raspbian and NR, but cannot identfy why the one Zero works
Does the user running Node-RED (pi I assume) belong to group "dialout" on the one that works and not the others? I doubt it though as I've just done a fresh install a week ago and my "pi" user is in the group without me adding it explicitly.
This is a longshot but as serialport uses native bindings, maybe it needs to be rebuilt (perhaps Node version has changed or something). You could try rebuilding it with:
cd .node-red
npm rebuild
Then restart NR.
Edit: also observe for possible build errors for the module
Thanks, tried that but error remains. I have gone through all my Pi's and now found another A+ that also works fine. The only common issue I can find is both have a similar version of node (10.16 and 10.17)
I have started again with a complete fresh install of Raspberry OS and NR but error the same
Thanks for your help, I am just cheating for now, I have taken the SD card out of the A+ and put it into the 3 B+ (where I need it) and it works, so I am just going to make a image of this SD and use that until I can find a solution.
I think I might have found the reason. It supports your findings:
NodeJS has dropped prebuilt binaries for NodeJS 10 and above for 32bit linux. As a result it's too difficult to maintain support. However if you build nodejs and serialport yourself it will probably work.
This reminded of me the fact I just ran across the fact that an USB serial interface might bind to either /dev/ttyAMA0 or /dev/ttyACM0 depending on the situation. I just tried the search icon on the serial in node and it offered me both options (I have a CC2531 zigbee2mqtt stick attached).
You are all genius! @edje11 the document that you liked to solved the problem. I changed the config.txt and assigned the GPIO14 and 15 the "main" UART to AMA0 and that fixed the problem