# Modbus Flex Connector Example

**URL:** <https://discourse.nodered.org/t/modbus-flex-connector-example/24447>\
**Category:** General\
**Created:** [8 April 2020 09:55 UTC](https://discourse.nodered.org/t/modbus-flex-connector-example/24447 "2020-04-08T09:55:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdbell](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bdbell](https://discourse.nodered.org/u/bdbell)\
**Post date:** [8 April 2020 09:55 UTC](https://discourse.nodered.org/t/modbus-flex-connector-example/24447/1 "2020-04-08T09:55:43Z")

</div>

Does anyone have a working example of Modbus Flex Connector with the ability to dynamically connect to both TCP and SERIAL devices (using the most recent version of NR and [node-red-contrib-modbus](https://github.com/BiancoRoyal/node-red-contrib-modbus))? I have looked at [MODSCAN](https://flows.nodered.org/flow/bc19aff2598d6a214bbfbe0e6f66ee64) - and although I have been able to get it working it still requires manually going into the Node-Red GUI and selecting the Link-out for either TCP or Serial connection before they will work, and I have found it's now not working with the latest updates to node-red-contrib-modbus (v5.8). I am looking for something that will allow changing the settings from Dashboard to switch between a WiFi/TCP and Serial RS-485 connection. I am using a Function as follows to input the settings to Modbus Flex Connector;

```auto
msg.payload = { 
    'connectorType': 'TCP',
    'tcpHost': '192.168.1.36',
    'tcpPort': '10502',
    'unitId': '253'
    };
return msg;

```

or

```auto
msg.payload = { 
    'connectorType':"SERIAL",
    'serialPort': '/dev/ttyUSB0',
    'serialType': 'RTU',
    'serialBaudrate': '115200',
    'unitId': '254'
    };
return msg;

```

I currently have it working for the TCP connection, but when I try to switch to Serial it gives me a " Dynamic Reconnect Starts on actual state activated" message and then reconnects to TCP.

```auto
  contribModbus:flex:connector dynamicReconnect: {"connectorType":"SERIAL","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"115200","unitId":"254"} +0ms
  contribModbus:core:client Dynamic Reconnect Parameters {"connectorType":"SERIAL","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"115200","unitId":"254","emptyQueue":false} +1m
  contribModbus:core:client New Connection Serial Settings /dev/ttyUSB0 115200 RTU +6ms
  contribModbus:core:client Dynamic Reconnect Starts on actual state activated +1ms
2 Apr 22:56:46 - [warn] [modbus-client:ModbusConnect] Client -> init in 2000 ms TCP@192.168.1.36:502 default Unit-Id: 254

```

Any info on this would be much appreciated.

---

<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:** [7 June 2020 10:01 UTC](https://discourse.nodered.org/t/modbus-flex-connector-example/24447/2 "2020-06-07T10:01:24Z")

</div>

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