使用 pycomm 将数据从 PLC 打印到 Python

Print Data from PLC to Python using pycomm

我正在尝试将数据(具体为 dint,但我的示例是 BOOL)从 plc 移动到 python 以用作显示图片的变量。问题是,如果我使用 pycomm,我会在 Windows Powershell 中遇到错误。我觉得这是一个非常简单的错误,来自基本 python 错误,而不是 pycomm 问题,但我没有足够的信息来判断。

系统信息:

configparser==3.5.0  
cpppo==3.9.7  
greenery==2.1  
ipaddress==1.0.18  
pycomm==1.0.8  
pyreadline==2.1  
pytz==2017.2  
python==2.7.13

我使用的代码:

from pycomm.ab_comm.clx import Driver as ClxDriver
import logging

if __name__ == '__main__':
    c = ClxDriver()

    if c.open('IPADDRESSHERE'):

         print(c.read_tag(['new_Bool']))

         c.close()

这只是 github https://github.com/ruscito/pycomm

上示例之一的精简版

这是 运行 powershell 的结果:

PS C:\Users\Tom\Documents\PythonProjects> python pycomm2.py Traceback (most recent call last): File "pycomm2.py", line 10, in print(c.read_tag(['new_Bool'])) File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag self.logger.warning(self._status) AttributeError: 'Driver' object has no attribute 'logger' PS C:\Users\Tom\Documents\PythonProjects>

我一直在寻找这个 AttributeError 并试图找到解决方案,但我认为我找到的解决方案超出了我的理解范围。如果我未能提供一些细节以使这个问题有意义,请告诉我。

编辑:

from pycomm.ab_comm.clx import Driver as ClxDriver
import logging


if __name__ == '__main__':
    logging.basicConfig(
        filename="ClxDriver.log",
        format="%(levelname)-10s %(asctime)s %(message)s",
        level=logging.DEBUG
    )
    c = ClxDriver()

    if c.open('IPADRESSHERE'):

        print(c.read_tag(['new_Bool']))


        c.close()

产生相同的属性错误。

PS C:\Users\Tom\Documents\PythonProjects> python pycommtest.py Traceback (most recent call last): File "pycommtest.py", line 15, in print(c.read_tag(['new_Bool'])) File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag self.logger.warning(self._status) AttributeError: 'Driver' object has no attribute 'logger' PS C:\Users\Tom\Documents\PythonProjects>

我能够读取一个值,但不能使用 pycomm。使用 CPPPO,我能够根据需要不断更新变量。这可能无法回答我的旧代码有什么问题的问题,但这是我的解决方法,以防将来有人必须做同样的事情。感谢用户 Liverpool_chris 和 Reddit 的深渊。

https://www.reddit.com/r/PLC/comments/5x3y5z/python_cpppo_library_writing_to_tag_in_plc/

from cpppo.server.enip.get_attribute import proxy_simple
import time

host = "IPHERE"
while True:
    x, = proxy_simple(host).read(( "CPID"))

    print x
time.sleep(5)