我试图让"PYCOMM"连接到我的CLX 5000处理器 . 每次我运行我的代码时,我得到: CommError: must be str, not bytes. 我查看了所有代码,但我无法找到问题所在 . 所有应该是字符串格式的东西是 . 我正在使用python3.6这是代码:
import sys
from pycomm.ab_comm.clx import Driver as ClxDriver
c = ClxDriver()
if c.open('172.16.2.161'):
print(c.read_tag('Start'))
# Prints (1,'BOOL') if true; (0,'BOOL') if false
c.close()
这是错误:
C:\ Users \ shirley \ Miniconda3 \ python.exe C:/Users/shirley/Downloads/pycomm-pycomm3/pycomm-pycomm3/examples/test_clx_comm.py Traceback(最近一次调用最后一次):文件"C:\Users\shirley\Miniconda3\lib\site-packages\pycomm\cip\cip_base.py", line 617, in build_header h += pack_uint(length) # Length UINT TypeError: must be str, not bytes
The header is 24 bytes fixed length, and includes the command and the length of the optional data portion.
:return: the headre
"""
try:
h = command # Command UINT
**h += pack_uint(length) # Length UINT**
h += pack_dint(self._session) # Session Handle UDINT
h += pack_dint(0) # Status UDINT
h += self.attribs['context'] # Sender Context 8 bytes
h += pack_dint(self.attribs['option']) # Option UDINT
return h
except Exception as e:
raise CommError(e)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次调用最后一次):文件"C:\Users\shirley\Miniconda3\lib\site-packages\pycomm\cip\cip_base.py",第786行,如果self.register_session()为None,则为open:文件"C:\Users\shirley\Miniconda3\lib\site-packages\pycomm\cip\cip_base.py",第635行,寄存器为register_session self._message = self.build_header(ENCAPSULATION_COMMAND ['register_session'],4)文件"C:\Users\shirley\Miniconda3\lib\site-packages\pycomm\cip\cip_base.py" ,第624行,在build_header中引发CommError(e) pycomm.cip.cip_base.CommError: must be str, not bytes
在处理上述异常期间,发生了另一个异常:
回溯(最近一次调用最后一次):文件"C:/Users/shirley/Downloads/pycomm-pycomm3/pycomm-pycomm3/examples/test_clx_comm.py",第5行,如果是c.open('172.16.2.161'):文件"C:\Users\shirley\Miniconda3\lib\site-packages\pycomm\cip\cip_base.py",第793行,在open中引发CommError(e) pycomm.cip.cip_base.CommError: must be str, not bytes
进程以退出代码1结束
1 回答
把我的头撞到墙上试图自己解决这个问题 . 我刚刚切换到使用PYLOGIX https://github.com/dmroeder/pylogix它第一次运行它并且速度相当快 .