我想从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