update 初次融合+调试
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
from COM.COM_TCP import TCPClient
|
||||
import queue
|
||||
import json
|
||||
from Model.RobotModel import DataAddress,DATARequest
|
||||
from Model.RobotModel import DataAddress,DATARequest,DATAReply
|
||||
|
||||
class RobotClient(TCPClient):
|
||||
|
||||
def __init__(self, ip, port, command_quene, status_model):
|
||||
def __init__(self, ip, port, command_quene, status_model:DataAddress):
|
||||
super().__init__(ip, port)
|
||||
self.command_quene = command_quene
|
||||
self.status_model = status_model
|
||||
@ -16,26 +16,27 @@ class RobotClient(TCPClient):
|
||||
return
|
||||
|
||||
def send_Command(self):
|
||||
q = queue.Queue
|
||||
q.qsize()
|
||||
while True: # 让出时间间隔
|
||||
try:
|
||||
if self.command_quene.qsize()!=0:
|
||||
command = self.command_quene.get()
|
||||
self.client_socket.send(json.dumps(command).encode('utf-8'))
|
||||
try:
|
||||
if self.command_quene.qsize()!=0:
|
||||
command = self.command_quene.get()
|
||||
self.client_socket.send(command.encode('utf-8'))
|
||||
|
||||
if False:
|
||||
response = self.client_socket.recv(1024).decode('utf-8')
|
||||
response_message = json.loads(response)
|
||||
if True:
|
||||
print('正确相应')
|
||||
else:
|
||||
self.errorCommands[json.dumps(command).encode('utf-8')] = response_message
|
||||
print('出错')
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
except Exception as e:
|
||||
print('连接断开')
|
||||
return False
|
||||
|
||||
if False:
|
||||
response = self.client_socket.recv(1024).decode('utf-8')
|
||||
response_message = json.loads(response)
|
||||
if True:
|
||||
print('正确相应')
|
||||
else:
|
||||
self.errorCommands[json.dumps(command).encode('utf-8')] = response_message
|
||||
print('出错')
|
||||
except Exception as e:
|
||||
print('连接断开')
|
||||
|
||||
#return False
|
||||
|
||||
def send_Status(self):
|
||||
request = DATARequest()
|
||||
@ -45,25 +46,23 @@ class RobotClient(TCPClient):
|
||||
# 移除特殊属性和方法
|
||||
request_status_json = request.toString()
|
||||
# 转字符串
|
||||
while True:
|
||||
try:
|
||||
self.client_socket.send(json.dumps(request_status_json).encode('utf-8'))
|
||||
if False:
|
||||
response = self.client_socket.recv(1024).decode('utf-8')
|
||||
response_message = json.loads(response)
|
||||
if True:
|
||||
data_status = DATARequest()
|
||||
data_status.__dict__ = response_message
|
||||
data_address_array = data_status.queryAddr
|
||||
data_Address = DataAddress()
|
||||
for i in attributes.count():
|
||||
setattr(data_Address,attributes[i],data_address_array[i])
|
||||
self.status_model = data_Address
|
||||
else:
|
||||
print('转换失败')
|
||||
except Exception as e:
|
||||
print('连接断开')
|
||||
|
||||
try:
|
||||
self.client_socket.send(request_status_json.encode('utf-8'))
|
||||
if True:
|
||||
response = self.client_socket.recv(1024).decode('utf-8')
|
||||
response_message = json.loads(response)
|
||||
if True:
|
||||
data_status = DATAReply()
|
||||
data_status.__dict__ = response_message
|
||||
data_address_array = data_status.queryAddr
|
||||
data_Address = DataAddress()
|
||||
data_Address.setPosition(*data_address_array)
|
||||
self.status_model.setPosition(*data_address_array)
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
return False
|
||||
|
||||
@ -30,10 +30,9 @@ class TCPClient:
|
||||
time.sleep(0.2)
|
||||
self.connected = self.error_count > 0
|
||||
try:
|
||||
#time.sleep(30)
|
||||
if (self.send_Status() and self.send_Command()):
|
||||
self.error_count = 0
|
||||
except:
|
||||
except Exception as e:
|
||||
self.error_count += 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user