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
- Place a PAC Control Write node onto your flow.
- Connect an Inject node to the input port. You do NOT need to connect a Debug node to the output port.
- Double-click on the PAC Control Write node to open the “Edit pac read node”.
- For the Device field, select a configured controller.
- For the Data Type field, select Int32 Variable.
- For the Tag Name field, enter the name of tag in your strategy that is okay to write to.
- For the Value field, select Value from the dropdown and enter a number.
- Click Done.
- Click Deploy.
- Make sure the Debug tab is open in the right-hand sidebar.
- Click the Inject node’s button.
- 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:
- Double-click on the Inject node.
- 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.
- Click Done.
- Double-click on the existing PAC Control Write node from above..
- Change the Value field from Value to msg.payload.
- Click Done.
- Click Deploy.
- Click the Inject node’s button.
- 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.
- Place an Inject node onto a flow.
- Configure the node to use a Repeat interval of 1 second.
- Place a PAC Control 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.
- Configure the Read node to read from a digital input point. This will place a boolean value into the
- Place a PAC Control Write node onto the flow.
- Configure the Write node to write to a digital output point.
- For the Value field, select msg.payload.
- Deploy the flow.
- 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 PAC Control 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.