看一下代码没有啥问题:
def create_socket(self):
"""
连接PLC Service端, IP 默认:192.168.0.40, 端口:8501
"""
try:
cnn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cnn.connect((self.ip_address, self.port))
self.cnn = cnn
return cnn
except Exception as e:
logging.error('server not find or not open')
logging.error(e)
return None
最后回去检查了一给 TCP 的 ip, port, maodan, ip 最后多了个空,就是下面的 61 后面有个空格,删除就正常了。
IP = "100.100.196.61 " # TCP Server IP of PLC
PLC_PORT = 8501 # TCP Server PORT of PLC