question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modbus TCP: "PortNotOpenError: Port Not Open"

See original GitHub issue

I’m submitting a …

Problem

  • (x) unexpected behavior

Current behavior

My device doesn’t maintain permanent TCP connection and close after 1.5 second or so. Single FC 3 request rise the list of errors: TypeError: Cannot read property 'getMachineState' of undefined PortNotOpenError: Port Not Open FSM Reset On State [object Object] Client -> try to reconnect by init in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 Client -> try to reconnect by init in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 FSM Reset On State [object Object] Client -> try to reconnect by init in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1

and log from console: 5 Dec 09:08:04 - [error] [modbus-flex-getter:Shtyl] TypeError: Cannot read property 'getMachineState' of undefined at Object._inputCallback (/data/node_modules/node-red-contrib-modbus/modbus/maps/modbus-flex-getter.js:123:61) at Object.Node._emitInput (/usr/src/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:199:18) at Immediate._onImmediate (/usr/src/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:179:33) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5) 5 Dec 09:08:04 - [error] [modbus-flex-getter:Shtyl] PortNotOpenError: Port Not Open at ModbusRTU.writeFC4 (/data/node_modules/modbus-serial/index.js:501:24) at ModbusRTU.writeFC3 (/data/node_modules/modbus-serial/index.js:487:10) at /data/node_modules/modbus-serial/apis/promise.js:48:31 at new Promise (<anonymous>) at ModbusRTU.readHoldingRegisters (/data/node_modules/modbus-serial/apis/promise.js:39:27) at Object.noneCommandSent [as callModbus] (/data/node_modules/node-red-contrib-modbus/modbus/maps/modbus-client.js:550:7) at Object.sequentialDequeueCommand (/data/node_modules/node-red-contrib-modbus/modbus/maps/modbus-client.js:140:13) at Timeout.r.dequeueCommand [as _onTimeout] (/data/node_modules/node-red-contrib-modbus/modbus/maps/modbus-client.js:172:14) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10) 5 Dec 09:08:04 - [warn] [modbus-flex-getter:Shtyl] FSM Reset On State [object Object] 5 Dec 09:08:04 - [warn] [modbus-client:Shtyl-dacha] Client -> try to reconnect by init in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 5 Dec 09:08:04 - [warn] [modbus-flex-getter:Shtyl] FSM Reset On State [object Object] 5 Dec 09:08:04 - [warn] [modbus-client:Shtyl-dacha] Client -> try to reconnect by init in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 5 Dec 09:08:05 - [warn] [modbus-client:Shtyl-dacha] Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 5 Dec 09:08:05 - [warn] [modbus-client:Shtyl-dacha] Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1 5 Dec 09:08:05 - [warn] [modbus-client:Shtyl-dacha] Client -> reconnect in 100 ms TCP@192.168.77.137:502 default Unit-Id: 1

no response for request, request is lost. The only workaround, constantly send requests, in that case only first one is lost.

Expected behavior

Process a request. If port is closed, should open connection and process a request.

Minimal reproduction of the problem with instructions

  1. Create simple flow with Getter or FlexGetter node with TCP connection.
  2. Device should close connection.
  3. Send FC 3 request in result list of errors and no response.

Your Environment

Please tell us about your environment:

  • (x) I am using just the Node-RED package and got modbus-serial package installed with it

  • ( ) I have installed modbus-serial package global from source (using git clone)

  • ( ) I have installed modbus-serial as a global package (using npm i -g)

  • node-red-contrib-modbus version: 5.1.0

  • Node: (min. 6.x) node --version = v10.17.0 Node-RED 1.0.3 docker on raspberry PI

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
biancodecommented, Feb 26, 2022

Hi, some devices will close the Port if the communication is to slow. Why should the queue work with a delay per message of 1 sec. ? Please, check the Modbus Specs or the information of the responding Modbus device in those cases.

0reactions
Naim-Bijapurecommented, Jun 7, 2022

hi, I am also getting a port not found error on the TCP connection.

actually, we are fetching plc data every 1 minute. the issue is coming after 6-8 hours. I am getting port not found error . and after node server restart it starts again !

is there any solution for this? i am on version 8.0.5

@biancode please help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modbus serial port msg : PortNotOpenError ...
i'am trying to read data using serial port, but i always get this error "msg : PortNotOpenError "PortNotOpenError: Port Not Open" ".
Read more >
"Port not open error/permission issues" or "no ... - Stack Overflow
I have googled and searched alot for my issues but did not get any threat of use. I have the same ...
Read more >
Node-RED Modbus TCP Handling Communication Errors
Node-RED Modbus TCP can recover from communication errors automatically. Options are available to you the programmer to continue the ...
Read more >
'Unable to open slave path' - Modbus TCP/IP Error
This error indicates that the Modbus TCP/IP driver is unable to actually create a local socket on the system. This is usually because...
Read more >
Developers - PortNotOpenError - - Bountysource
Hi, I am trying to connect an energy meter(modbus) to my ubuntu 16.04 machine. However, when I run the following node app, I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found