d) Creating Flows for Modbus

Creating Flows for Modbus

Note: This course assumes you already understand the MODBUS protocol or have done our MODBUS protocol course to understand how the commands and messages are sent.

I cannot express this enough, SAVE your COMPLETE NODE-RED flows (all) by EXPORTING from time to time, so you have a backup file. Files can be lost on any operating system and with any application - you have been warned.

Breaking down the messaging for Modbus

We will need to create new FLOWS and these will be done in order of:

a) A simulated MODBUS Master (Server) to simulate a device / PLC.

b) Read the device outputs as individual bits, FC 1 Read Coil Status (Output #0xxxx)

c) Read Input Status as individual bits, FC 2 (#1xxxx)

d) Read Holding Registers, FC 3 (Output #4xxxx)

e) Read Input Registers FC 4 (#3xxxx)

f) Force Coil FC 5

g) Preset Single Register FC 6

h) Force Multiple Coils FC 15

i) Preset Multiple Registers FC 16


Included will be a means to display the data or force/write the data, but first:


NODE-RED BASICS

The main workspace is where flows are developed by dragging nodes from the palette and wiring them together.

Editor windowThe workspace has a row of tabs along the top; one for each flow and any subflows that have been opened.A flow is represented as a tab within the editor workspace and is the main way to organise nodes.

Each flow can have a name, and description that is displayed in the Information sidebar.

All of the nodes in a flow can access the same flow-scoped context.


Adding a flow

To add a new flow, either click the button in the top bar, or double-click on free space in the tab bar.

Reordering flows

Flows can be reordered in the workspace by dragging their tabs around in the tab bar.


Enabling or disabling a flow

The flow can be enabled or disabled using the toggle button at the bottom of the dialog. If a flow is disabled, none of the nodes it contains will be created when the flow is deployed.

Deleting a flow

To delete a flow, click the ‘Delete’ button in the Flow Properties dialog.

Switching between flows

To open a list of the available flows, click the "list" button in the top bar.


NODES

Nodes can be added to the workspace by either:

  • dragging them from the palette,
  • using the quick-add dialog,
  • or importing from the library or clipboard.

Node port labels

Nodes are joined together by wires via their ports. A node can have at most one input port and many output ports. A port may have a label that is displayed when the mouse hovers over it. A node may specify labels, for example, the Switch node shows the rule that matches the port. The labels can also be customised in the node edit dialog.


Some nodes display a status message and icon below the node. This is used to indicate the runtime state of the node - for example, the MODBUS RESPONSE nodes indicate if they are currently connected or not and data.


Node elements

If a node has any undeployed changes, it displays a blue circle above it. If there are errors with its configuration, it displays a red triangle.

Node Example:

Some nodes include a button on either its left or right edge. These allow some interaction with the node from within the editor. The Inject and Debug nodes are the only core nodes that have buttons.


Wires

Nodes are wired together by pressing the left-mouse button on a node’s port, dragging to the destination node and releasing the mouse button.

Splitting wires

If a node with both an input and output port is dragged over the mid-point of a wire, the wire is draw with a dash. If the node is then dropped, it is automatically inserted into the flow at that point.

Moving wires

To disconnect a wire from a port, select the wire by clicking on it, then press and hold the Shift key when the left-mouse button is pressed on the port. When the mouse is then dragged, the wire disconnects from the port and can be dropped on another port. If the mouse button is released over the workspace, the wire is deleted.


If a port has multiple wires connected to it, if none of them is selected when button is pressed with the Shift key held, all of the wires will move.


Deleting wires

To delete a wire, first select it by clicking on it and then press the delete key.


Importing and Exporting Flows

Flows can be imported and exported from the editor using their JSON format, making it very easy to share flows with others.


Importing flows

The Import dialog can be used to import a flow by the following methods:

  • pasting in the flow JSON directly,
  • uploading a flow JSON file,
  • browsing the local flow library,
  • browsing the example flows provided by installed nodes.

In all cases, the dialog offers the option to import the nodes into the current flow, or to create a new flow for them.


Sidebar

This information will change depending on the node selected.


Editor Sidebar

The sidebar contains panels that provide a number of useful tools within the editor.

  • Information - view information about nodes and their help
  • Debug - view messages passed to Debug nodes
  • Configuration Nodes - manage configuration nodes
  • Context data - view the contents of context

Some nodes contribute their own sidebar panels, such as node-red-dashboard.


VIDEO