Trouble with serialport. Error code 31

Hello. I'm having trouble to use serialport in node red to connect with my GPT-9803. The connect I was using is rs232C ( using usb to rs232C with CH340 CHIP). I'm successfully connect it via tera-term and getting feedback from the machine, but when I tried to use node red serialport it always having this error:

"[serialconfig:58065d3ff9e25096] serial port COM3 error: Error: Open (SetCommState): Unknown error code 31"

This is the output from tera term, if I tried to send "idn?" command to the machine:
teraterm out

And this is node-red when I tried to connect it:

[
    {
        "id": "52d7084d2efd8fbc",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "ea5031698f6e236f",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    },
    {
        "id": "1631f6c1af7f2963",
        "type": "ui_base",
        "theme": {
            "name": "theme-light",
            "lightTheme": {
                "default": "#0094CE",
                "baseColor": "#0094CE",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": true,
                "reset": false
            },
            "darkTheme": {
                "default": "#097479",
                "baseColor": "#097479",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": false
            },
            "customTheme": {
                "name": "Untitled Theme 1",
                "default": "#4B7930",
                "baseColor": "#4B7930",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
            },
            "themeState": {
                "base-color": {
                    "default": "#0094CE",
                    "value": "#0094CE",
                    "edited": false
                },
                "page-titlebar-backgroundColor": {
                    "value": "#0094CE",
                    "edited": false
                },
                "page-backgroundColor": {
                    "value": "#fafafa",
                    "edited": false
                },
                "page-sidebar-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-textColor": {
                    "value": "#1bbfff",
                    "edited": false
                },
                "group-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "widget-textColor": {
                    "value": "#111111",
                    "edited": false
                },
                "widget-backgroundColor": {
                    "value": "#0094ce",
                    "edited": false
                },
                "widget-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "base-font": {
                    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
                }
            },
            "angularTheme": {
                "primary": "indigo",
                "accents": "blue",
                "warn": "red",
                "background": "grey",
                "palette": "light"
            }
        },
        "site": {
            "name": "Node-RED Dashboard",
            "hideToolbar": "false",
            "allowSwipe": "false",
            "lockMenu": "false",
            "allowTempTheme": "true",
            "dateFormat": "DD/MM/YYYY",
            "sizes": {
                "sx": 48,
                "sy": 48,
                "gx": 6,
                "gy": 6,
                "cx": 6,
                "cy": 6,
                "px": 0,
                "py": 0
            }
        }
    },
    {
        "id": "5ad7a3c2f4cb1f09",
        "type": "ui_group",
        "name": "Default",
        "tab": "ea5031698f6e236f",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "a6e358b.672ffa8",
        "type": "ui_group",
        "name": "Demo",
        "tab": "4e528085.a1bfa",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "4e528085.a1bfa",
        "type": "ui_tab",
        "name": "Demo",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    },
    {
        "id": "58065d3ff9e25096",
        "type": "serial-port",
        "name": "",
        "serialport": "COM3",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    },
    {
        "id": "f57557155a8ddb6f",
        "type": "serial in",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "serial": "58065d3ff9e25096",
        "x": 490,
        "y": 280,
        "wires": [
            [
                "8fc2ed2bd72f2b24"
            ]
        ]
    },
    {
        "id": "8fc2ed2bd72f2b24",
        "type": "debug",
        "z": "52d7084d2efd8fbc",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 320,
        "wires": []
    },
    {
        "id": "c15a8906993c6221",
        "type": "inject",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "*idn?",
        "payloadType": "str",
        "x": 190,
        "y": 400,
        "wires": [
            [
                "34fcfe862721a4f3"
            ]
        ]
    },
    {
        "id": "34fcfe862721a4f3",
        "type": "serial out",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "serial": "58065d3ff9e25096",
        "x": 350,
        "y": 400,
        "wires": []
    }
]

I wonder what cause it? Using windows 10 pro. Thank you very much!

I don’t know too much about how windows handles its drivers.

But given its working in tera term - we should rule out drivers.

Next thing(s) to check

  • The serial port is not in use at the same time
  • check the settings (baudrate, stop bits) etc
    In tera term and match them in Node RED
  • NodeJS runtime architecture (32, 64 bit)
1 Like

Thanks for the reply!

  1. Checking the serial port to make sure it doesn't connect to terra term before using node red. If the serial is being used, I've seen a new error that saying
    "[serialconfig:58065d3ff9e25096] serial port COM3 error: Error: Opening COM3: Access denied"
    So I think it safe as I didn't have that error.

  2. Here is the setting, both in tera-term and node-red:
    teraterm serial setting


    I notice teraterm have "Flow control" option as it didn't exist in node red serial port. Does this affect the setting? ( It is none however).

  3. It is 64 bit. Im using

node -p "process.arch"

Oh yeah. Is using different OS will have a different output? I haven't tried it on ubuntu as I need to install the ch340 driver first on the ubuntu

UPDATE: It seems re-installing the CH340 did the trick. Now node red indicate that the connection is connected. The interesting thing is I can inject "*idn?" to the machine just fine but somehow didn't receive anything on the output side of the node red. However, when I open tera term once more and use "idn?" command, it seems the previous node-red inject end up printed here.I inject like 10 times, and it also printed extra 10 times when I send "idn?" from the tera -term. Does it has anything to do with CR or LF?

tera-term terminal

UPDATE 3: It is working! It seems I need to add \r everytime I finished the input!
Thank you for the answer! The settings is a bit different in the input side!

Here is the updated flow for anyone that might need it.

[
    {
        "id": "d5a2884de61808a4",
        "type": "serial in",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "serial": "58065d3ff9e25096",
        "x": 530,
        "y": 260,
        "wires": [
            [
                "4b8992af7b45d485"
            ]
        ]
    },
    {
        "id": "a5c8ce124ab72cb3",
        "type": "serial out",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "serial": "58065d3ff9e25096",
        "x": 430,
        "y": 320,
        "wires": []
    },
    {
        "id": "83ebbb84e030d34b",
        "type": "inject",
        "z": "52d7084d2efd8fbc",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "*idn?",
        "payloadType": "str",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "81799e70251bfbe4"
            ]
        ]
    },
    {
        "id": "4b8992af7b45d485",
        "type": "debug",
        "z": "52d7084d2efd8fbc",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 260,
        "wires": []
    },
    {
        "id": "81799e70251bfbe4",
        "type": "function",
        "z": "52d7084d2efd8fbc",
        "name": "function 1",
        "func": "msg.payload = msg.payload+\"\\r\"; \nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 320,
        "wires": [
            [
                "a5c8ce124ab72cb3"
            ]
        ]
    },
    {
        "id": "58065d3ff9e25096",
        "type": "serial-port",
        "name": "",
        "serialport": "COM3",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    }
]
2 Likes

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