Closed pdbjjens closed 1 year ago
Hi @pdbjjens!
Thank you for your detailed and helpful error report, I really appreciate it!
I reworked parts of the SerialConnection
class in https://github.com/danielwippermann/resol-vbus/commit/0f49d877704ec69f07be6419700dcb540ba15d65 and it now works again as intended. If the connection has been successfully established once, it will try to reconnect if the connection gets interrupted and not throw an "Unhandled promise rejection" error.
I plan to release an NPM package update in the next couple of days.
Thanks again! Daniel
FYI: I just released the NPM package update 0.27.0 including that bug fix a couple of minutes ago.
@danielwippermann Hi Daniel, thank you for your quick response and the new NPM package. I will check whether it works correctly in our ioBroker Adapter as soon as I can spare some time and provide feedback.
@danielwippermann Hi Daniel, I briefly checked resol-vbus 0.27.0 serialconnection in our ioBroker adapter. Seems to work fine, also the reconnect mechanism now works again. Thanks again, and keep up the good work!
Thanks for the feedback!
There seems to be a bug in serial-connection.js ("resol-vbus@0.25.0") which triggers an Unhandled promise rejection when a non-existent serial port is attempted to be opened. This can be fixed by removing the extra "null" argument in line
176 return new SerialPort(path, options, null, onCompletion);
(see error logs "Before" and "After" below).
Environment:
Platform: Windows operating system: win32 Architecture: ia32 CPUs: 2 Speed: 2394 MHz Model: Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz RAM: 3.2 GB System uptime: 00:43:40 Node.js: v14.21.0 time: 1677311416247 timeOffset: -60 adapters count: 558 NPM: v6.14.17 Disk size: 118.3 GB Disk free: 42.7 GB Uptime: 00:35:10 Active instances: 1 Path: C:\iob-dev\ioBroker.myvbus.dev-server\default\ alive:
"serialport": "^9.2.8", "resol-vbus@0.25.0"
Before:
serial-connection.js line 176:
new SerialPort() receives the wrong number of arguments, Instead of the openCallback, "null" is passed. Therefore the module crashes with "Unhandled promise rejection"
Remark: The "path" argument can be included in the options object since some time. Also the undocumented option "disconnectedCallback:" is deprecated and removed from node SerialPort since V4.x. So I assume that the code for the reconnect will not be working anymore. (I haven't tried it yet). Since V5.x "the close event now fires with a disconnect error object in the event of a disconnection". (err.disconnect) EDIT: I have tried to disconnect and it does not work as expected. So it would be desirable that you also fix the reconnect code.
2023-02-26 08:57:00.909 - info: myvbus.0 (10664) starting. Version 0.2.2 in C:/iob-dev/ioBroker.myvbus/.dev-server/default/node_modules/iobroker.myvbus, node: v14.21.0, js-controller: 4.0.24 2023-02-26 08:57:01.069 - debug: myvbus.0 (10664) Language: en 2023-02-26 08:57:01.085 - debug: myvbus.0 (10664) Connection Type: serial 2023-02-26 08:57:01.086 - debug: myvbus.0 (10664) Connection Identifier: COM8 2023-02-26 08:57:01.087 - debug: myvbus.0 (10664) Connection Port: 7053 2023-02-26 08:57:01.088 - debug: myvbus.0 (10664) VBus Password encrypted: 2023-02-26 08:57:01.259 - debug: myvbus.0 (10664) VBus Channel: 1 2023-02-26 08:57:01.370 - debug: myvbus.0 (10664) VBus Via Tag: 2023-02-26 08:57:01.470 - debug: myvbus.0 (10664) VBus Interval: 30 2023-02-26 08:57:01.583 - info: myvbus.0 (10664) Serial Connection at COM8 selected 2023-02-26 08:57:01.739 - info: myvbus.0 (10664) Wait for Connection... 2023-02-26 08:57:01.851 - debug: myvbus.0 (10664) Connection state changed to CONNECTING 2023-02-26 08:57:01.976 - error: myvbus.0 (10664) 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(). 2023-02-26 08:57:02.007 - error: myvbus.0 (10664) unhandled promise rejection: Opening COM8: File not found 2023-02-26 08:57:02.248 - error: myvbus.0 (10664) Error: Opening COM8: File not found 2023-02-26 08:57:02.264 - error: myvbus.0 (10664) Opening COM8: File not found 2023-02-26 08:57:02.381 - debug: myvbus.0 (10664) Connection state changed to DISCONNECTING 2023-02-26 08:57:02.412 - debug: myvbus.0 (10664) Connection state changed to DISCONNECTED 2023-02-26 08:57:02.510 - info: myvbus.0 (10664) Cleaned up everything... 2023-02-26 08:57:02.608 - info: myvbus.0 (10664) terminating 2023-02-26 08:57:02.675 - warn: myvbus.0 (10664) Terminated (UNCAUGHT_EXCEPTION): Without reason [nodemon] app crashed - waiting for file changes before starting...
After:
The error is correctly handed up from SerialPort to the ioBroker adapter.
2023-02-26 09:02:42.759 - info: myvbus.0 (14268) starting. Version 0.2.2 in C:/iob-dev/ioBroker.myvbus/.dev-server/default/node_modules/iobroker.myvbus, node: v14.21.0, js-controller: 4.0.24 2023-02-26 09:02:43.056 - debug: myvbus.0 (14268) Language: en 2023-02-26 09:02:43.137 - debug: myvbus.0 (14268) Connection Type: serial 2023-02-26 09:02:43.349 - debug: myvbus.0 (14268) Connection Identifier: COM8 2023-02-26 09:02:43.511 - debug: myvbus.0 (14268) Connection Port: 7053 2023-02-26 09:02:43.634 - debug: myvbus.0 (14268) VBus Password encrypted: 2023-02-26 09:02:43.664 - debug: myvbus.0 (14268) VBus Channel: 1 2023-02-26 09:02:43.689 - debug: myvbus.0 (14268) VBus Via Tag: 2023-02-26 09:02:43.701 - debug: myvbus.0 (14268) VBus Interval: 30 2023-02-26 09:02:43.707 - info: myvbus.0 (14268) Serial Connection at COM8 selected 2023-02-26 09:02:43.738 - info: myvbus.0 (14268) Wait for Connection... 2023-02-26 09:02:43.745 - debug: myvbus.0 (14268) Connection state changed to CONNECTING 2023-02-26 09:02:43.771 - error: myvbus.0 (14268) [onReady] error: Opening COM8: File not found, stack: Error: Opening COM8: File not found