Simple APP to read and write data to ROCKWELL PLC

2020-08-01 06:32发布

I'm looking for a simple way, if that's even possible, to make an app that can read/write to tags in a ROCKWELL PLC.

What I need is a simple window that allows me to type the PLC IP (they are all connected to the network) so I can connect to the device, a container that loads all the PLC current tags, and the ability to read and/or write to those tags.

I consider myself a beginner when it comes to PLC and Java programming, so I would like to know if guys can assist me somehow. I said JAVA because it's the programming language that I know a little, but it doesn't matter if there's another one that is better to use, like VBA.

The GUI isn't really the issue here, but to connect to the device and manipulate it's variables.

标签: java plc opc
4条回答
我想做一个坏孩纸
2楼-- · 2020-08-01 06:44

I am a little late to the party but there is a new library https://github.com/dmroeder/pylogix that is very promising. I have written a few web apps apps with it and it is very easy to use. From the docs:

Pylogix:

This project will allow you to easily read/write values from tags in Rockwell Automation Logix based PLC's over Ethernet I/P using Python. PLC models inclued CompactLogix, ControlLogix and Micro8xx. Python2 and Python3 are both supported.

Reading a tag is as simple as (from the examples):

from pylogix import PLC

with PLC() as comm:
    comm.IPAddress = '192.168.1.9'
    ret = comm.Read('CurrentScreen')
    print(ret.Value)
查看更多
可以哭但决不认输i
3楼-- · 2020-08-01 06:55

If you know the Tag names in the Rockwell ControlLogix PLC, you can quickly read and write their values from a Python program (from Windows, Mac or Linux hosts), using https://github.com/pjkundert/cpppo. To install it, run, install Python 2 or 3, and run:

pip install cpppo pytz

Lets assume that your Rockwell ControlLogix PLC is at domain name "controller" in your local network (or, just use its IP address in host = "192.168.1.2" below), and that it contains a Tag named scada containing an array of 11 or more elements of CIP type INT:

from __future__ import print_function
from cpppo.history import timestamp
from cpppo.server.enip import client

host = "controller" # Or, simply use an IP address, eg: 192.168.1.2
tags = [ "scada[0-10]", "scada[1]=99", "scada[0-10]" ]

with client.connector( host=host ) as conn:
    for index,descr,op,reply,status,value in conn.pipeline(
            operations=client.parse_operations( tags ), depth=2 ):
        print( "%s: %20s: %s" % ( timestamp(), descr, value ))

Assuming that the Tag scada exists, you'll see something like:

2015-05-25 14:35:15.891: Single Read  Tag  scada[0-10]: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
2015-05-25 14:35:15.897: Single Write Tag  scada[1-1]: True
2015-05-25 14:35:15.915: Single Read  Tag  scada[0-10]: [0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0]

If you don't have a Rockwell ControlLogix PLC around, you can simulate one (for the purposes of reading/writing Tag data, at least), by running:

python -m cpppo.server.enip --print -v scada=INT[100]
查看更多
女痞
4楼-- · 2020-08-01 07:05

Here you can find a librairy which will allow you to communicate with a Rockwell PLC. (look at TuxPLC for more detail --> documentation is in french)

Here you will find an adaptation of TuxPLC in python (which is very simple to understand if you are a beginner)

https://github.com/gaynertechnical/python-tuxeip

Example of reading then writing data in PLC (Be carefull when you proceed to you test) Read carefully the documentation in TuxEip folder ( https://github.com/leicht/TuxPLC )

查看更多
再贱就再见
5楼-- · 2020-08-01 07:06

I am familiar with two useful libraries in Python that allow connection to a PLC with tag writing and reading. They both work well and I have tried them out.

OpenOPC allows connection, tag reading and writing in a short Python program. It is best for Rockwell, assuming that you have Rockwell's RSLinx program running in the background to give your OPC server - make sure you use the same OPC topic to address tags in the PLC as what you set up on RSLinx. You will end up with something like:

import OpenOPC
opc_client = OpenOPC.client()
opc_client.connect('RS Linx Remote OPC Server')
result = opc_client.read('[OPC_topic]tag_name')  # read a tag
opc_client.write('[OPC_topic]tag_name', value)  # write a tag
opc_client.close()

If for some reason you can't use RSLinx, there's another way to do it in Python using pycomm:

from pycomm.ab_comm.clx import Driver
clx_driver = Driver()
clx_driver.open(ip_address)
result = clx_driver.read_tag(tag_name)  # read tag
clx_driver.write_tag(tag_name, value)  #write tag
clx_driver.close()

Hope this helps - I know you'd prefer an answer in Java, but Python is what I've done this with before. Hopefully someone else can come along with a Java-specific answer.

查看更多
登录 后发表回答