In the manufacturing world there is a lot of valuable data that exists in the PLC. However, because it can be difficult to access, the information is rarely used to improve operations. When PLC data is moved to the cloud, it can be visualized to gain insights, make real-time business decisions, diagnose problem machines, and trigger alerts to critical team members.
We are able to solve this problem and bring the data that exists within the PLC to the next layer by using the Losant Enterprise IoT Platform along with the Losant Allen-Bradley Read and Write nodes. In this blog, we are going to walk through how to connect to an Allen-Bradley CompactLogix or ControlLogix PLC from the Losant platform. By doing this, we will have the ability to read tag values from the PLC to Losant and also write values from Losant to the PLC tags.
Let’s walk through each component of the Losant platform that we will be using.
In order to demonstrate how this works together, we are going to walk through a remote monitoring pump demo we’ve designed. All of the controls and feedback for this demo exist in Losant which reads data from the PLC and writes data to the PLC. Together, we’ll take two parts of this demo and walk through how to turn the pump output on from Losant and how to read the flow switch input data back to the Losant platform.
If you do not have a Losant account, you can sign up here. This gives you a free, fully functional developer license that will allow you connect to your PLC.
Create a new application or add to an existing application. Steps to create an application are here. The name I gave this application is ‘PLC Monitoring’.
Create an Edge Compute Device by following the instructions listed here. I named this ‘Edge Device’.
Install the Losant Edge Agent on a device that also has Ethernet access to the PLC and to the internet. Follow the instructions here for getting the Losant Gateway Edge Agent on a device. For testing purposes, you can use your personal laptop but it is not recommended for a long-term solution.
This Edge Workflow will be deployed to a local device running the Losant Gateway Edge Agent and will be responsible for communicating with the PLC using the Allen-Bradley Read and Write nodes.
Within the ‘PLC Monitoring’ application, we want to click on Workflows and then Create Workflow.
Click create and your Edge Workflow will be created.
Now that we have our Edge Workflow created, let’s add two different flows. The first flow will be responsible for turning the pump on when a command from the Application Workflow is sent. The second flow is responsible for reading the flow switch every second to see if flow is present. Go ahead and drag and drop each node and connect these nodes as shown below and then we will walk through each node.
The Device:Command Node will trigger this workflow when a device command from the Application Workflow is made to our ‘Edge Device’. Do not worry about how this command is made from the Application Workflow yet, we will cover that below. There is no configuration needed for this Device:Command Node.
The Losant Allen-Bradley Write Node will write all tag values configured within this node for the PLC of the IP Address provided.
In our PLC program, we have a program named ‘MainProgram’ which has a program tag named ‘Pump’ which drives the output to turn the pump on. We are writing a value of ‘true’ (1 works as well) to this program tag. If this tag were a controller tag then the Program Template field would be left blank. We are also configuring the optional Destination Path so that we get feedback of the PLC write on the payload.
When the write node is executed, it will return a ‘plcProperties’ object on the Destination Path payload. These properties give information about the PLC and the current state of the PLC such as minor or major faults, PLC serial number, the PLC model, PLC firmware version, etc. These properties are also returned when the read node is executed.
This completes the edge workflow for writing to the PLC. Now let’s read a PLC tag which is connected to a flow sensor input. The timer node in this example is set to one second. Every second, it will trigger this workflow.
The Losant Allen-Bradley Read Node will read all tag values configured within this node for the PLC of the IP Address provided.
This node shows that we will be reading a program tag named ‘Flow_Switch’ from a program named ‘MainProgram’. The result of this read will be put on the payload as the Result Key, which in this case is also named ‘Flow_Switch’. The Result Key (‘Flow_Switch’) will be put onto the payload at the Destination Path that was configured (working.plc_read.result).
The next node updates the Device State. I created a device named Flow_Switch as Device Type Peripheral and I am updating a number attribute I created named ‘flow’ with the response from the previous Allen-Bradley Read Node.
The next node, Device State, allows us to update the Flow_Switch device each time we trigger a read on this PLC input. Configure the node so that the attribute ‘flow’ for the Flow_Switch reflects what is being read from the PLC which is accessible from the payload at working.plc_read.result.Flow_Switch.
To deploy the workflow, click Save in the top right corner and then click Deploy which will bring up a pop-up box like the one shown below.
Any version name can be given but it must be unique each time you deploy so using a timestamp works well. Select the device(s) that this should be deployed to which in our case is the ‘Edge Device’ that we created earlier. Then we can click Deploy Version to have this workflow deployed to our Edge Agent.
This application workflow will command the pump on from the cloud. Follow the same steps that we used to create an Edge Workflow except select Application for Workflow Type. Once this workflow is created, then create the flow as shown below.
The virtual button named Pump On will trigger this workflow when this button is clicked - no configuration is needed for this node. The Device Command Node will send a command named ‘pump_on’ to the ‘Edge Device’. This ‘pump_on’ command was used earlier to trigger the edge workflow and allow the Allen-Bradley Write Node to execute. Once this workflow is created and configured, then we can press the Save and Deploy button at the top right corner. Now, if the Pump On virtual button is clicked, the command ‘pump_on’ will be sent to the edge agent on ‘Edge Device’ through the payload path ‘data.name’ and trigger the edge workflow that will write to the PLC to turn the pump on.
Now that we have all of this setup, a dashboard can be created to display the information we are reading from the PLC. The dashboard shown below is from our Pump demo and built by using easy drag and drop visualization blocks. To find out more on how to build a dashboard, look here.
Now that you know how to use the new Losant Allen-Bradley Read and Write nodes, use them to connect to the machines on your factory floor. You can start by pulling machine state data and alarms and warnings for each of your machines. Using the Losant Dashboard, you can start tracking downtime on each machine to find your problem machines and also find which alarms are causing the most problems. If you have any questions, check out the Losant Forums. If you want to take your project further, we would love to learn more about your use case.