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.
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:
4.python 2.6 or newer.
5.Python CIP library.
Get the library and code example from the following link:
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.
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.
- from eip import PLC
- comm = PLC()
- comm.IPAddress ="192.168.60.104"
- def ex_read():
- ret = comm.Read("VLV_O3_HEADER_ISO_ZSC")
- print ret
Start node-red. To get return value from python script, we need to put plcread.py on “EXEC” node.
Edit exec node:
Build a flow.