<script>ecbox_number=1;</script><style type="text/css" style="display:none;" id="easycode_inline_style">
.easycodebox li {white-space:pre !important; word-wrap:normal !important; word-break:keep-all; list-style-type:decimal-leading-zero !important;}
.easycodebox .main ol {font-family: 'Consolas','Consolas_WEB',Consolas,monaco,monospace !important; font-size: 90% !important;}

.easycodebox .headbar .message:after {content:"- Show or hide the code";}</style><script>ecbox_number=2;</script>{"id":121,"date":"2017-11-30T15:08:45","date_gmt":"2017-11-30T15:08:45","guid":{"rendered":"http:\/\/taptronics.com\/taptronics\/?p=121"},"modified":"2018-04-13T12:50:39","modified_gmt":"2018-04-13T12:50:39","slug":"read-allen-bradley-tags-using-python-2-7-and-pass-the-values-to-node-red","status":"publish","type":"post","link":"http:\/\/taptronics.com\/taptronics\/read-allen-bradley-tags-using-python-2-7-and-pass-the-values-to-node-red\/","title":{"rendered":"Read  Allen Bradley tags using Python 2.7  and pass the values to node-red."},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-186\" src=\"http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2018\/04\/dew-200x300.jpg\" alt=\"dew\" width=\"200\" height=\"300\" \/><\/p>\n<p><span style=\"color: #333333;\">Read and write\u00a0 Allen Bradley tag values using\u00a0 python which utilize Common Industrial Protocol (CIP) on Ethernet\/IP. This method will work on Controllogix and Compactlogix PLCs. The script\u00a0 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.<\/span><\/p>\n<p><span style=\"color: #333333;\"><strong>Requirements:<\/strong><\/span><\/p>\n<p><span style=\"color: #333333;\">1.Raspberry pi 3 (Jessie).<\/span><\/p>\n<p><span style=\"color: #333333;\">2.Node-Red (It was already installed in latest Jessie but\u00a0 we might still need to get update to work with dashboard node).<\/span><\/p>\n<p><span style=\"color: #333333;\">3.Dashboard node. Here is the link to get this node:<\/span><\/p>\n<h3><span style=\"color: #800000;\"><a style=\"color: #800000;\" href=\"https:\/\/flows.nodered.org\/node\/node-red-dashboard\">https:\/\/flows.nodered.org\/node\/node-red-dashboard<\/a><\/span><\/h3>\n<p><span style=\"color: #333333;\">4.python 2.6 or newer.<\/span><\/p>\n<p><span style=\"color: #333333;\">5.Python CIP library.<\/span><\/p>\n<p><span style=\"color: #333333;\">Get the library and code example from the following link:<\/span><\/p>\n<h2><span style=\"color: #800000;\"><a style=\"color: #800000;\" href=\"https:\/\/github.com\/dmroeder\/pylogix\">https:\/\/github.com\/dmroeder\/pylogix<\/a><\/span><\/h2>\n<h3><span style=\"text-decoration: underline;\"><strong><span style=\"color: #333333; text-decoration: underline;\">Step 1 :<\/span><\/strong><\/span><\/h3>\n<p><span style=\"color: #333333;\">I<span style=\"color: #000000;\">f you follow on my previous article, you can switch Raspberry 3 pi to AP mode. Assign eth0 to static IP address. For\u00a0 example : wan address: 192.168.42.1<\/span><\/span><\/p>\n<p><span style=\"color: #000000;\">static eth0\u00a0 IP address : 192.168.60.50<\/span><\/p>\n<p><span style=\"color: #000000;\">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.<\/span><\/p>\n<h3><span style=\"text-decoration: underline;\"><strong><span style=\"color: #000000; text-decoration: underline;\">Step 2.<\/span><\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">Use pylogix library to get a taglist and to read a tag value from PLC. Here is the example of\u00a0 python script to read &#8220;VLV_O3_HEADER_ISO_ZSC&#8221; tag from Controllogix PLC with IP address: 192.168.60.104.<\/span><\/p>\r\n\t<div class='easycodebox  ' id='easycodebox-1'>\r\n\t<div class='headbar' onclick='EasyCodeClass(this).ShowCode();'  title=\"Click here to show\/hide the code.\"> plcread.py<\/div>\r\n\t<div class='flex-box'>\r\n\t<div class='scrollbox'  ondblclick=\"EasyCodeClass(this).editCode(1);\">\r\n\t<div class='ecside'>&nbsp;<\/div>\r\n\t<div class='main'><ol>\n<li>from\u00a0eip\u00a0import\u00a0PLC<\/li>\n<li>comm\u00a0=\u00a0PLC()<\/li>\n<li>comm.IPAddress\u00a0=\"192.168.60.104\"<\/li>\n<li>def\u00a0ex_read():<\/li>\n<li>\u00a0\u00a0ret\u00a0=\u00a0comm.Read(\"VLV_O3_HEADER_ISO_ZSC\")<\/li>\n<li>\u00a0\u00a0print\u00a0ret<\/li>\n<li>ex_read()<\/span><\/li><\/ol><\/div>\r\n\t<\/div><\/div><\/div><p>&nbsp;<\/p>\n<h3><span style=\"text-decoration: underline; color: #000000;\"><strong>Step 3.<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">Start node-red. To get return value from python script, we need to put plcread.py on &#8220;EXEC&#8221; node.<\/span><\/p>\n<p><span style=\"color: #000000;\">Edit exec node:<\/span><\/p>\n<p><span style=\"color: #000000;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-133\" src=\"http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node2-265x300.png\" alt=\"node2\" width=\"412\" height=\"466\" srcset=\"http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node2-265x300.png 265w, http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node2.png 497w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/span><\/p>\n<p><span style=\"text-decoration: underline; color: #000000;\"><strong>Step 4.<\/strong><\/span><\/p>\n<p><span style=\"color: #000000;\"><strong>Build a flow.<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-132\" src=\"http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node1-300x68.png\" alt=\"node1\" width=\"731\" height=\"166\" srcset=\"http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node1-300x68.png 300w, http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node1-768x174.png 768w, http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node1-800x182.png 800w, http:\/\/taptronics.com\/taptronics\/wp-content\/uploads\/2017\/11\/node1.png 828w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Read and write\u00a0 Allen Bradley tag values using\u00a0 python which utilize Common Industrial Protocol (CIP) on Ethernet\/IP. This method will work on Controllogix and Compactlogix PLCs. The script\u00a0 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. &hellip; <a href=\"http:\/\/taptronics.com\/taptronics\/read-allen-bradley-tags-using-python-2-7-and-pass-the-values-to-node-red\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Read  Allen Bradley tags using Python 2.7  and pass the values to node-red.<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,5,4],"_links":{"self":[{"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/posts\/121"}],"collection":[{"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":19,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":187,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/posts\/121\/revisions\/187"}],"wp:attachment":[{"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/taptronics.com\/taptronics\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}