Overview

In the previous example, we saw how to read one or all Int32 variables. Now let’s use a Write node, and then connect a Read to a Write node.

Write to an Int32 Variable

  1. Place a SNAP PAC Write node onto your flow.
  2. Connect an Inject node to the input port. You do NOT need to connect a Debug node to the output port.
  3. Double-click on the SNAP PAC Write node to open the “Edit snap pac read node”.
  4. For the Controller field, select a configured controller.
  5. For the Data Type field, select Int32 Variable.
  6. For the Tag Name field, enter the name of tag in your strategy that is okay to write to.
  7. For the Value field, select Value from the dropdown and enter a number.
  8. Click Done.
  9. Click Deploy.
  10. Make sure the Debug tab is open in the right-hand sidebar.
  11. Click the Inject node’s button.
  12. Using PAC Control, confirm that the value was written to the controller.

Write to an Int32 Variable from Message Object

The value to write can also come in on the msg object. Continuing from the previous section:

  1. Double-click on the Inject node.
  2. For the Payload field, select “number” from the dropdown list. In the text field, enter a number you wish to write to your strategy variable.
  3. Click Done.
  4. Double-click on the existing SNAP PAC Write node from above..
  5. Change the Value field from Value to msg.payload.
  6. Click Done.
  7. Click Deploy.
  8. Click the Inject node’s button.
  9. Using PAC Control, confirm that the value was written to the controller.

This is just a preview of the power within Node-RED to build complex and dynamic solutions.

Connect a Read Node to a Write Node

Now let’s see how a Read and Write node can be used together. We’ll connect a digital input to a digital output. Normally this would be done within a strategy, but it’s a nice example to help learn Node-RED.

If you don’t have digital points available for testing, you can also use variables instead. Use whatever works for your strategy.

  1. Place an Inject node onto a flow.
    • Configure the node to use a Repeat interval of 1 second.
  2. Place a SNAP PAC Read node onto the flow.
    • Configure the Read node to read from a digital input point. This will place a boolean value into the msg.payload object property that is returned by the Read node.
  3. Place a SNAP PAC Write node onto the flow.
    • Configure the Write node to write to a digital output point.
    • For the Value field, select msg.payload.
  4. Deploy the flow.
  5. The digital input should now be controlling the digital output point, with an update occuring once a second.

Conclusion

This concludes our Getting Started with Node-RED for SNAP PAC section.

There’s also a quick introduction to Node-RED on the official website, with tutorials for a first and second flow.

Please explore the other material available on the Opto 22 Developer site for additional information, including the section on Node-RED resources.