我想從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>
我不知道我周圍這種方式特別,但你已經剝離出來的例子的位中的一個似乎是記錄設置..調用'logging.basicConfig (..' – TessellatingHeckler
我發佈了一個更新,我認爲可能是這樣,所以我用另一個例子,但我一定做錯了什麼。 – Carbide