2017-07-27 78 views
0

我想從plc移動數據(具體是一個dint,但我的例子是一個BOOL),以便用作顯示圖片的變量。問題是,如果我使用pycomm,我在Windows Powershell中出現錯誤。我覺得這是一個基本的python錯誤而非pycomm問題的一個非常簡單的錯誤,但我沒有足夠的信息來告訴。使用pycomm將數據從PLC打印到Python

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

+0

我不知道我周圍這種方式特別,但你已經剝離出來的例子的位中的一個似乎是記錄設置..調用'logging.basicConfig (..' – TessellatingHeckler

+0

我發佈了一個更新,我認爲可能是這樣,所以我用另一個例子,但我一定做錯了什麼。 – Carbide

回答

0

我能讀取一個值,但不能用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)