# Help reading serial port

**URL:** <https://discourse.nodered.org/t/help-reading-serial-port/99740>\
**Category:** General\
**Created:** [21 November 2025 22:32 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740 "2025-11-21T22:32:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeh7](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@joeh7](https://discourse.nodered.org/u/joeh7)\
**Post date:** [21 November 2025 22:32 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/1 "2025-11-21T22:32:48Z")

</div>

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:**

```flows
[
    {
        "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:**

```auto
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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 November 2025 22:52 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/2 "2025-11-21T22:52:20Z")

</div>

Welcome to the forums @joeh7

Lets unpick this...

```auto
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

---

<div class="post-metadata">

**Author:** ![joeh7](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@joeh7](https://discourse.nodered.org/u/joeh7)\
**Post date:** [21 November 2025 23:05 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/3 "2025-11-21T23:05:37Z")

</div>

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!):

```auto
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.](https://www.aquantic-logie-fish-counters-ltd.com/2100C.html)

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 November 2025 23:09 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/4 "2025-11-21T23:09:16Z")

</div>

> [@joeh7](#):
>
> ```auto
> 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
> 
> ```

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

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

 ![Screenshot 2025-11-21 at 23.22.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/025ad133db5dd62483f9f175dc7263c8d86cee97.png)

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.

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![joeh7](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@joeh7](https://discourse.nodered.org/u/joeh7)\
**Post date:** [28 November 2025 21:43 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/5 "2025-11-28T21:43:27Z")

</div>

Thanks for the help Marcus, your suggestion worked and has led me to a workaround!

It appears to be an issue with waiting for the line end character - this never seems to trigger the delivery of a message by the node. Maybe it's an isolated issue for me but I have the same issue on two different computer and both serial adaptors and virtual COM ports. Anyway - a problem for another day!

Joe

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 February 2026 21:43 UTC](https://discourse.nodered.org/t/help-reading-serial-port/99740/6 "2026-02-26T21:43:31Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
