Help reading serial port

Evening all,

I've been struggling to read data from a serial port using the node-red serial input node.

If I open the serial port in another program, I can receive the data. However, if I close that connection and open the same port in Node-RED (using the same settings) I receive nothing. No errors, nothing written to the file, no debug output.

I am running Node-RED in Windows 11 Professional. I get confirmation in the terminal that the serial port has been opened (see example). I am running Node-RED with admin privileges.

I'm a bit at a loss? Maybe someone could suggest a means of testing the underlying Node.js install without having to write lots of JavaScript? Or maybe experience from having similar issues?

Flow:

[
    {
        "id": "11673c9bf329ceb5",
        "type": "tab",
        "label": "Fish Logger",
        "disabled": false,
        "info": "Listens on RS232 port for serial output from Counter whenever fish passage is detected.\r\nWrites the output to a log file.\r\nLog files are generated for each month and labeled 'log-[YEAR]-[MONTH].txt'\r\n\r\nWritten by J Hobbs, 16/11/2025",
        "env": []
    },
    {
        "id": "401d2da1b8ce37ae",
        "type": "function",
        "z": "11673c9bf329ceb5",
        "name": "Construct & Add msg.path",
        "func": "// @ts-ignore\nlet year = moment(msg.payload).year();\nlet month = moment(msg.payload).month() + 1;\nlet path = 'C:\\\\Users\\\\Admin\\\\Documents\\\\Fish Logger\\\\log-'+year+'-'+month+'.txt';\nvar newMsg = { payload: msg.payload, path: path };\n\nreturn newMsg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "moment",
                "module": "moment"
            }
        ],
        "x": 330,
        "y": 40,
        "wires": [
            [
                "a15b1c43a28fe09f"
            ]
        ]
    },
    {
        "id": "a15b1c43a28fe09f",
        "type": "file",
        "z": "11673c9bf329ceb5",
        "name": "Write Log File",
        "filename": "path",
        "filenameType": "msg",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "false",
        "encoding": "none",
        "x": 600,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "b81be536e162b742",
        "type": "debug",
        "z": "11673c9bf329ceb5",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 280,
        "y": 120,
        "wires": []
    },
    {
        "id": "a69c924a7dc9d838",
        "type": "serial in",
        "z": "11673c9bf329ceb5",
        "name": "COM5",
        "serial": "2bb465bb3840e480",
        "x": 90,
        "y": 40,
        "wires": [
            [
                "401d2da1b8ce37ae",
                "b81be536e162b742"
            ]
        ]
    },
    {
        "id": "55c93b32d6eeb77e",
        "type": "catch",
        "z": "11673c9bf329ceb5",
        "name": "",
        "scope": null,
        "uncaught": false,
        "x": 100,
        "y": 120,
        "wires": [
            [
                "b81be536e162b742"
            ]
        ]
    },
    {
        "id": "2bb465bb3840e480",
        "type": "serial-port",
        "name": "",
        "serialport": "COM5",
        "serialbaud": "9600",
        "databits": "7",
        "parity": "even",
        "stopbits": 1,
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "10000",
        "bin": "false",
        "out": "time",
        "addchar": "",
        "responsetimeout": 10000
    },
    {
        "id": "3185db8020375a45",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-node-serialport": "2.0.3"
        }
    }
]

Terminal Output:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Windows\system32> node-red
21 Nov 19:41:19 - [info]

Welcome to Node-RED
===================

21 Nov 19:41:19 - [info] Node-RED version: v4.1.1
21 Nov 19:41:19 - [info] Node.js  version: v24.11.1
21 Nov 19:41:19 - [info] Windows_NT 10.0.26200 x64 LE
21 Nov 19:41:19 - [info] Loading palette nodes
21 Nov 19:41:21 - [info] Settings file  : C:\Users\Admin\.node-red\settings.js
21 Nov 19:41:21 - [info] Context store  : 'default' [module=memory]
21 Nov 19:41:21 - [info] User directory : \Users\Admin\.node-red
21 Nov 19:41:21 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Nov 19:41:21 - [info] Flows file     : \Users\Admin\.node-red\flows.json
21 Nov 19:41:21 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

21 Nov 19:41:21 - [warn] Encrypted credentials not found
21 Nov 19:41:21 - [info] Server now running at http://127.0.0.1:1880/
21 Nov 19:41:21 - [info] Starting flows
21 Nov 19:41:21 - [info] Started flows
21 Nov 19:41:21 - [info] [serialconfig:2bb465bb3840e480] serial port COM5 opened at 9600 baud 7E1
21 Nov 19:43:03 - [info] Stopping flows
21 Nov 19:44:21 - [info] serial port COM5 closed
21 Nov 19:44:21 - [info] Stopped flows

Environment
Node-RED v4.1.1
Node.js v24.11.1
Windows_NT 10.0.26200 x64 LE

Thanks in advance!
Joe

Welcome to the forums @joeh7

Lets unpick this...

let year = moment(msg.payload).year();
let month = moment(msg.payload).month() + 1;
let path = 'C:\\Users\\Admin\\Documents\\Fish Logger\\log-'+year+'-'+month+'.txt';
var newMsg = { payload: msg.payload, path: path };

return newMsg;

This suggest you are expecting nothing more than a numerical value, that you then:

  • Use as part of the file name (parsed date elements)
  • simply write to the file - this same timestamp (raw value)

?

You also expect nothing more then a timestamp, 10 seconds after the first bits of the stream?

Note; you are delivering ASCII from the serial node, not a numerical value

I think you need to be clear as to what data you are expecting, as I feel this maybe part of the problem.

if you can advise what data (exactly) you are expecting, and in what format - it will help and hopefully resolve your issue

EDIT

And note its filename, not path ignore - I see you use typed input

Hi Marcus,

Thanks for your help!

The expected data is something like below (example taken from the manual which appears to have been written in 1997!):

S 19/03/97 23:11:54 150 1 D 050
D @@PP``pp@@PP``pp@@PP``pp@@PP``pp@@PP``pp@@PP``pp@@
D pp@@PP``pp@@PP``pp@@PP``pp@@PP``pp@@PP``pp@@PP``pp
F 1

Basically, it is the output from a device which logs fish going up or down river - you can see the manual here though it's not really required to understand the issue. Aquantic Logie Fish Counters Ltd.

The javascript you quote is designed to construct a month-specific filename and then append the serial data received to that file. However, the issue seems to be that the serial input node produces nothing (it is connected directly to a debug node). There may be issues in my javascript as well, but that node isn't yet receiving anything!

Thanks,
Joe

so is this payload after each detection? and is F 1 a constant terminator?

it does appear so....
what happens if you do this?

But do note - you cant pass this output to moment - as its not a timestamp, it has many components, which wont parse to a date.

You're better of doing something like.

const date = moment()
const path = `C:\\Users\\Admin\\Documents\\Fish Logger\\log - ${date.year()} - ${date.month()+1}.txt`;
const newMsg = { payload: msg.payload, path: path };

return newMsg;