Read Allen Bradley tags using Python 2.7 and pass the values to node-red.

 

dew

Read and write  Allen Bradley tag values using  python which utilize Common Industrial Protocol (CIP) on Ethernet/IP. This method will work on Controllogix and Compactlogix PLCs. The script  will be executed in Node-red and the return value will be displayed on dashboard and can be read on wireless devices such as tablets or smartphones.

Requirements:

1.Raspberry pi 3 (Jessie).

2.Node-Red (It was already installed in latest Jessie but  we might still need to get update to work with dashboard node).

3.Dashboard node. Here is the link to get this node:

https://flows.nodered.org/node/node-red-dashboard

4.python 2.6 or newer.

5.Python CIP library.

Get the library and code example from the following link:

https://github.com/dmroeder/pylogix

Step 1 :

If you follow on my previous article, you can switch Raspberry 3 pi to AP mode. Assign eth0 to static IP address. For  example : wan address: 192.168.42.1

static eth0  IP address : 192.168.60.50

Connect PLC networks to Raspberry ethernet port. Make sure there is no conflict between Raspberry eth0 static address with gateway or PLC IP addresses. To access raspberry pi via tablets or smartphones you can use android app such as VNC viewer or ConnectBot. Alternatively you can also use VNC viewer or PuTTY on Windows version.

Step 2.

Use pylogix library to get a taglist and to read a tag value from PLC. Here is the example of  python script to read “VLV_O3_HEADER_ISO_ZSC” tag from Controllogix PLC with IP address: 192.168.60.104.

plcread.py
 
  1. from eip import PLC
  2. comm = PLC()
  3. comm.IPAddress ="192.168.60.104"
  4. def ex_read():
  5.   ret = comm.Read("VLV_O3_HEADER_ISO_ZSC")
  6.   print ret
  7. ex_read()

 

Step 3.

Start node-red. To get return value from python script, we need to put plcread.py on “EXEC” node.

Edit exec node:

node2

Step 4.

Build a flow.

node1

 

 

 

Press Ctrl+C to copy the following code.
"