代码之家  ›  专栏  ›  技术社区  ›  Carbide

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

  •  2
  • Carbide  · 技术社区  · 9 年前

    系统信息:

    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()
    

    https://github.com/ruscito/pycomm

    这是运行powershell的结果:

    PS C:\Users\Tom\Documents\PythonProjects>python pycomm2.py 回溯(最近一次呼叫最后一次): 文件“pycomm2.py”,第10行,in 打印(c.read\u标记(['new\u Bool')) 自记录器警告(自状态) AttributeError:“Driver”对象没有属性“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 回溯(最近一次呼叫最后一次): 打印(c.read\u标记(['new\u Bool')) 文件“C:\Python27\lib\site packages\pycomm\ab\u comm\clx.py”,第359行,在read\u标记中 AttributeError:“Driver”对象没有属性“logger”

    1 回复  |  直到 9 年前
        1
  •  2
  •   Carbide    9 年前

    我能够读取值,但无法使用Pycom。使用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)