我试图将数据(特别是一个Dint,但我的示例是BOOL)从plc移动到python,以用作显示图片的变量。问题是,如果我使用pycomm,则Windows Powershell中出现错误。我觉得这是来自基本python错误而不是pycomm问题的非常简单的错误,但我没有足够的信息去告诉。

SysInfo:

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
  追溯(最近一次通话):
    在第10行的文件“ pycomm2.py”中
      打印(c.read_tag(['new_Bool']))
    read_tag中的文件“ C:\ Python27 \ lib \ site-packages \ pycomm \ ab_comm \ clx.py”,行359
      self.logger.warning(self._status)
  AttributeError:“驱动程序”对象没有属性“记录器”
  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
  追溯(最近一次通话):
    文件“ pycommtest.py”,第15行
      打印(c.read_tag(['new_Bool']))
    read_tag中的文件“ C:\ Python27 \ lib \ site-packages \ pycomm \ ab_comm \ clx.py”,行359
      self.logger.warning(self._status)
  AttributeError:“驱动程序”对象没有属性“记录器”
  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)

关于python - 使用pycomm将数据从PLC打印到Python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45354244/

10-10 21:24