mirror of
https://github.com/NanjingForestryUniversity/supermachine-wood.git
synced 2025-11-08 10:13:53 +00:00
做了一个简单应答测试,修改了一个numpy更新后的旧用法
This commit is contained in:
parent
0b291735e9
commit
27ec577e23
21
QT_test.py
21
QT_test.py
@ -155,6 +155,27 @@ def main():
|
||||
# print('指令执行完毕')
|
||||
# else:
|
||||
# print('指令执行失败')
|
||||
elif cmd == 'KM':
|
||||
model = "E:/wood_color/data/2023318"
|
||||
# model = "C:/Users/FEIJINTI/PycharmProjects/wood_color/models/model_2020-11-08_20-49.p"
|
||||
model = model.encode('ascii')
|
||||
length = len(model) + 4
|
||||
length = length.to_bytes(4, byteorder='big')
|
||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
||||
socket_send_1.send(send_message)
|
||||
print('发送成功')
|
||||
result = socket_send_2.recv(5)
|
||||
new_leng = int.from_bytes(result[1:], byteorder='big')
|
||||
result = socket_send_2.recv(new_leng)
|
||||
print(result)
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
# print('接收指令成功')
|
||||
# else:
|
||||
# print('接收指令失败')
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
# print('指令执行完毕')
|
||||
# else:
|
||||
# print('指令执行失败')
|
||||
else:
|
||||
print('指令错误')
|
||||
|
||||
|
||||
@ -551,8 +551,8 @@ class WoodClass(object):
|
||||
labels = [mapping[i] for i in labels]
|
||||
data = []
|
||||
for i in range(len(img_names)):
|
||||
x_tmp = np.round(x_data[i, :]).astype(np.int)
|
||||
x_tmp = np.char.zfill(x_tmp.astype(np.str), 3)
|
||||
x_tmp = np.round(x_data[i, :]).astype(np.int_)
|
||||
x_tmp = np.char.zfill(x_tmp.astype(np.str_), 3)
|
||||
x_tmp = "".join(x_tmp)
|
||||
data.append(x_tmp + y_data[i] + labels[i])
|
||||
return data
|
||||
@ -569,7 +569,7 @@ if __name__ == '__main__':
|
||||
# wood.correct()
|
||||
# wood.load()
|
||||
# fit 相应的文件夹
|
||||
# settings.model_path = str(ROOT_DIR / 'models' / wood.fit_pictures(data_path=data_path))
|
||||
settings.model_path = str(ROOT_DIR / 'models' / wood.fit_pictures(data_path=data_path))
|
||||
|
||||
x_data, y_data, labels, img_names = wood.get_kmeans_data(data_path, plot_2d=False)
|
||||
send_data = wood.data_adjustments(x_data, y_data, labels, img_names)
|
||||
|
||||
@ -9,7 +9,7 @@ from classifer import WoodClass
|
||||
import time
|
||||
import os
|
||||
|
||||
from database import Database
|
||||
# from database import Database
|
||||
from root_dir import ROOT_DIR
|
||||
from utils import PreSocket, receive_sock, parse_protocol, ack_sock, done_sock, DualSock, simple_sock
|
||||
import logging
|
||||
@ -68,7 +68,7 @@ def main(is_debug=False):
|
||||
handlers=[file_handler, console_handler], level=logging.DEBUG)
|
||||
dual_sock = DualSock(connect_ip='127.0.0.1')
|
||||
|
||||
database = Database(settings.database_addr)
|
||||
# database = Database(settings.database_addr)
|
||||
|
||||
|
||||
while not dual_sock.status:
|
||||
|
||||
6
utils.py
6
utils.py
@ -260,7 +260,9 @@ def parse_protocol(data: bytes) -> (str, any):
|
||||
elif cmd == 'MD':
|
||||
data = data.decode('ascii')
|
||||
return cmd, data
|
||||
|
||||
elif cmd == 'KM':
|
||||
data = data.decode('ascii')
|
||||
return cmd, data
|
||||
|
||||
def ack_sock(send_sock: socket.socket, cmd_type: str) -> bool:
|
||||
'''
|
||||
@ -336,7 +338,7 @@ def simple_sock(send_sock: socket.socket, cmd_type: str, result) -> bool:
|
||||
result = result.encode('ascii')
|
||||
result = b',' + result
|
||||
length = len(result)
|
||||
msg = msg + length.to_bytes(1, 'big') + result
|
||||
msg = msg + length.to_bytes(4, 'big') + result
|
||||
try:
|
||||
send_sock.send(msg)
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user