induction_admin.py
15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# codinf:utf-8
from flask import request,render_template
# from flask import render_template,
from app import app
import json
import time
import timeit
import pexpect
import os
import csv
import re
import logging
import requests
from config import Config
from werkzeug.utils import secure_filename
from app.utils.serial_communication import SerialCommunication
from app.induction_config import read_addrs,ip_config,testCidExists
from serial_config import ReadConfig
from app.utils.location import Location
config_dict,convert_dict = Location().read_location_file()
ser = SerialCommunication()
print('admin open serial')
@app.route('/adminaddr_test', methods=['POST'])
def adminaddr_test():
rec_data = []
addrs = read_addrs()
addrs = addrs.split('@')
ser = SerialCommunication()
for addr in addrs:
command = addr + '\n'
ser.send_data(command)
line_status=ser.read_Line()
if "sensor Time out" in line_status:
rec_data.append(line_status)
time.sleep(0.1)
if rec_data:
c_dict = {'msg':rec_data}
else:
c_dict = {'msg':'所有传感器通信成功'}
return json.dumps(c_dict)
@app.route('/adminled_test', methods=['POST'])
def adminled_test():
addrs = read_addrs()
addrs = addrs.split('@')
ser = SerialCommunication()
rece_data = []
for addr in addrs:
leds = [1,1,100]
# leds.insert(0,1)
number = re.findall(r"\d+",addr)[0]
command = str(json.dumps({"ADDR":number,"ledrange":leds})) + '\n'
ser.send_data(command)
line_response = ser.read_Line()
rece_data.append(line_response)
time.sleep(0.1)
msg = "结果:{}".format(rece_data)
return json.dumps({'msg':msg})
# @app.route('/check_single', methods=['POST'])
# def check_single():
# data = request.get_json()
# addr = data['addr']
# led_index = data['led_index']
# ser = SerialCommunication()
# texts = addr + '\n'
# print (texts)
# ser.send_data(texts)
# reponse=ser.read_alldata()
# # print (reponse)
# rec = response.decode().split("\r\n")
# for line in rec:
# if line.startswith("A") and line.endswith("]")
# led = re.search("\[.*?\]", line)
# c_list = list(led.group())
# # print ("-------------------c_list",c_list)
# c_list.pop(0)
# c_list.pop(-1)
# convert_dict.get()
#
@app.route('/auto_calibrate', methods=['POST'])
def auto_calibrate():
data = request.get_json()
calibrate = data['calibrate']
addr = data['addr']
command = str(json.dumps({"ADDR":addr,"calibrate":calibrate})) + '\n'
ser = SerialCommunication()
ser.send_data(command)
print (command)
msg = "auto calibrate:{}已发送".format(calibrate)
return json.dumps({'msg':msg})
@app.route('/auto_calibrate1', methods=['POST'])
def auto_calibrate1():
data = request.get_json()
calibrate = data['calibrate']
addr = data['addr']
command = str(json.dumps({"ADDR":addr,"calibrate":calibrate})) + '\n'
ser = SerialCommunication()
ser.send_data(command)
print (command)
msg = "auto calibrate:{}已发送".format(calibrate)
return json.dumps({'msg':msg})
@app.route('/hancalibrate',methods=['POST'])
def hancalibrate():
data = request.get_json()
addr = data.split('@')[0]
start = int(data.split('@')[1])
end = int(data.split('@')[2])
maxv = int(data.split('@')[3])
minv = int(data.split('@')[4])
threshold = int(data.split('@')[5])
setcalibrate = [start,end,maxv,minv,threshold]
command = str(json.dumps({"ADDR":addr,"setcalibrate":setcalibrate})) + '\n'
ser = SerialCommunication()
ser.send_data(command)
print (command)
msg = "handle calibrate:{}已发送".format(command)
return json.dumps({'msg':msg})
@app.route('/getcalibrate',methods=['POST'])
def getcalibrate():
data = request.get_json()
addr = data.split('@')[0]
start = int(data.split('@')[1])
end = int(data.split('@')[2])
v1 = 1
v2 = 1
v3 = 1
getcalibrate = [start,end,v1,v2,v3]
command = str(json.dumps({"ADDR":addr,"getcalibrate":getcalibrate})) + '\n'
ser = SerialCommunication()
ser.send_data(command)
print (command)
calibrate_value=ser.read_Line()
print (calibrate_value,type(calibrate_value))
msg = "get calibrate:{}".format(calibrate_value)
return json.dumps({'msg':msg})
@app.route('/threshold', methods=['POST'])
def threshold():
data = request.get_json()
threshold = int(data['threshold'])
addr = data['addr']
command = str(json.dumps({"ADDR":addr,"threshold":threshold})) + '\n'
ser = SerialCommunication()
ser.send_data(command)
print (command)
msg = "threshold:{}已发送".format(command)
return json.dumps({'msg':msg})
@app.route('/writeserial', methods=['POST'])
def writeserial():
current_state = read_state()
if current_state=='on':
return json.dumps({'msg':"请先停止系统"})
data = request.get_json()
command = data['command']+'\r\n'
#ser = SerialCommunication()
ser.send_data(command)
time.sleep(0.3)
msg = ser.read_alldata()
if msg is not None:
return json.dumps({'msg':"{}".format(bytes.decode(msg))})
return json.dumps({'msg':msg})
@app.route('/readserial')
def readserial():
current_state = read_state()
if current_state=='off':
ser = SerialCommunication()
msg = ser.read_alldata()
if msg is not None:
return json.dumps({'msg':"{}".format(bytes.decode(msg))})
return json.dumps({'msg':''})
@app.route('/sitereport', methods=['POST'])
def sitereport():
current_state = read_state()
if current_state=='on':
return json.dumps({'msg':"请先停止系统"})
ser.read_alldata()
ser.send_data("report")
time.sleep(1.5)
msg = ser.read_alldata()
return json.dumps({'msg':bytes.decode(msg)})
#16mm 放8mm料盘;25mm放16mm料盘;35放24mm料盘;45放32mm料盘;54门放44mm料盘
#plateh={'1':8,'2':16,'3':24,'4':32,'5':44}
plateh={'20':8,'14':16,'10':24,'8':32,'5':44}
@app.route('/buildstore', methods=['POST','GET'])
def buildstore():
cid = ip_config['cid']
cidExists = testCidExists()
if cidExists is None:
return json.dumps({'msg':"服务器还未支持本功能"})
if cidExists:
return json.dumps({'msg':"Cid相关库位已存在服务器,请先删除"})
current_state = read_state()
if current_state=='on':
return json.dumps({'msg':"请先停止系统"})
#data = request.get_json()
addrs = read_addrs()
addrs = addrs.split('@')
title = '位置,address,led,sensor,优先级,高度,宽度'
contents=title+'\r\n'
body=[]
for addr in addrs:
command = '{"ADDR":"'+ addr[1:] +'","action":"info"}'+'\r\n'
ser.send_data(command)
time.sleep(0.5)
msg = ser.read_alldata()
print(msg)
addr=re.sub('A1(\d)',r'B\1',addr)
if msg is None:
return json.dumps({'msg':'库位建立失败,地址:'+addr+' 通讯失败,请检查后重试.'})
#msg='ADDR=1//ShelfPartName=NLP-00030-10-330-01//BoardIsOK=1//ReadLedType 0=2//ReadLedType 1=2//ReadLedType 2=0//ReadLedType 3=0//ReadLedType 4=0//LedType=7,7,7,6,0,0,0,0,0,0,//Led Count=27//Led List=1,2,3,4,5,6,7,11,12,13,14,15,16,17,21,22,23,24,25,26,27,31,32,33,34,35,36,//RowWidth=13//'
if msg is not None:
msg=bytes.decode(msg)
ledcount=getinfo(msg,'Led Count=')
_LedType = getinfo(msg,'LedType=').split(',')
ShelfPartName=getinfo(msg,'ShelfPartName=')
RowWidth=getinfo(msg,'RowWidth=')
LedType=[]
LedTypeCopy=[]
for i in range(0,5):
ll=int(_LedType[i*2])+int(_LedType[i*2+1])
LedType.append(ll)
LedTypeCopy.append(ll)
LedTypeindex=0
print(addr+' ledcount:'+ledcount);
for num in range(1,int(ledcount)+1):
#ledh=plateh[getinfo(msg,'ReadLedType '+str(LedTypeindex)+'=')]
ledh=plateh[str(LedTypeCopy[0])]
if RowWidth is None:
RowWidth = plateWidth[ShelfPartName+'-'+addr]
data = {"addr":addr,'index':num,'width':RowWidth,'height':ledh}
contents+=cid+'-{addr}-{index:0>3d},{addr},{index},{index},10,{height},{width}\r\n'.format(**data)
body.append({'pos':cid+'-{addr}-{index:0>3d}'.format(**data),'pri':10,'h':data['height'],'w':data['width']})
LedType[LedTypeindex]=LedType[LedTypeindex]-1
if LedType[LedTypeindex]==0:
LedTypeindex=LedTypeindex+1
url = ip_config['ip'] + '/service/store/uploadStoragePos'
data = {"cid":cid,'deviceType':'NLP','posList':body}
print(contents)
#response = requests.post(url, data = json.dumps(body),headers = headers,timeout=2)
response = requests.post(url, data=json.dumps(data),headers = headers,timeout=10)
response=response.json()
if response['okResult']:
with open(Config.UPLOAD_FOLDER+"//linePositions.csv","w",newline='',encoding='gbk') as f:
f.write(contents)
return json.dumps({'msg':'库位更新成功'})
def getinfo(msg,key):
if msg.find(key)<0:
return None
msg=msg[msg.index(key)+len(key):]
return msg[:msg.index('//')]
basepath = os.path.dirname(__file__)
def read_state():
uploads_path = basepath + Config.STATE_PATH
with open(uploads_path + "state.txt","r") as f:
state=f.readline()
return state
headers = {'content-type': "application/json"} #请求头信息
plateWidth={}
plateWidth['NLMP-70030-21-159-T-EU-A1']=13
plateWidth['NLMP-70030-21-159-T-EU-A2']=7
plateWidth['NLMP-70030-21-159-T-EU-A3']=7
plateWidth['NLMP-70030-21-159-T-EU-B1']=7
plateWidth['NLMP-70030-21-159-T-EU-B2']=7
plateWidth['NLMP-70030-21-159-A1']=13
plateWidth['NLMP-70030-21-159-A2']=7
plateWidth['NLMP-70030-21-159-A3']=7
plateWidth['NLMP-70030-21-159-B1']=7
plateWidth['NLMP-70030-21-159-B2']=7
plateWidth['NLP-00030-10-330-01-A1']=13
plateWidth['NLP-00030-10-330-01-A2']=13
plateWidth['NLP-00030-10-330-01-A3']=13
plateWidth['NLP-00030-10-330-01-A4']=13
plateWidth['NLP-00030-10-330-01-A5']=13
plateWidth['NLP-00030-10-330-01-B1']=13
plateWidth['NLP-00030-10-330-01-B2']=13
plateWidth['NLP-00030-10-330-01-B3']=13
plateWidth['NLP-00030-10-330-01-B4']=13
plateWidth['NLP-00030-10-330-01-B5']=13
plateWidth['NLP-70000-7-924-01-A1']=7
plateWidth['NLP-70000-7-924-01-A2']=7
plateWidth['NLP-70000-7-924-01-A3']=7
plateWidth['NLP-70000-7-924-01-A4']=7
plateWidth['NLP-70000-7-924-01-A5']=7
plateWidth['NLP-70000-7-924-01-A6']=7
plateWidth['NLP-70000-7-924-01-A7']=7
plateWidth['NLP-70000-7-924-01-B1']=7
plateWidth['NLP-70000-7-924-01-B2']=7
plateWidth['NLP-70000-7-924-01-B3']=7
plateWidth['NLP-70000-7-924-01-B4']=7
plateWidth['NLP-70000-7-924-01-B5']=7
plateWidth['NLP-70000-7-924-01-B6']=7
plateWidth['NLP-70000-7-924-01-B7']=7
plateWidth['NLP-70000-7-1400-01-A1']=7
plateWidth['NLP-70000-7-1400-01-A2']=7
plateWidth['NLP-70000-7-1400-01-A3']=7
plateWidth['NLP-70000-7-1400-01-A4']=7
plateWidth['NLP-70000-7-1400-01-A5']=7
plateWidth['NLP-70000-7-1400-01-A6']=7
plateWidth['NLP-70000-7-1400-01-A7']=7
plateWidth['NLP-70000-7-1400-01-B1']=7
plateWidth['NLP-70000-7-1400-01-B2']=7
plateWidth['NLP-70000-7-1400-01-B3']=7
plateWidth['NLP-70000-7-1400-01-B4']=7
plateWidth['NLP-70000-7-1400-01-B5']=7
plateWidth['NLP-70000-7-1400-01-B6']=7
plateWidth['NLP-70000-7-1400-01-B7']=7
plateWidth['NLP-00035-82-480-01-A1']=13
plateWidth['NLP-00035-82-480-01-A2']=13
plateWidth['NLP-00035-82-480-01-A3']=13
plateWidth['NLP-00035-82-480-01-A4']=13
plateWidth['NLP-00035-82-480-01-A5']=15
plateWidth['NLP-00035-82-480-01-B1']=13
plateWidth['NLP-00035-82-480-01-B2']=13
plateWidth['NLP-00035-82-480-01-B3']=13
plateWidth['NLP-00035-82-480-01-B4']=13
plateWidth['NLP-00035-82-480-01-B5']=15
plateWidth['NLP-00035-82-660-01-A1']=13
plateWidth['NLP-00035-82-660-01-A2']=13
plateWidth['NLP-00035-82-660-01-A3']=13
plateWidth['NLP-00035-82-660-01-A4']=13
plateWidth['NLP-00035-82-660-01-A5']=15
plateWidth['NLP-00035-82-660-01-B1']=13
plateWidth['NLP-00035-82-660-01-B2']=13
plateWidth['NLP-00035-82-660-01-B3']=13
plateWidth['NLP-00035-82-660-01-B4']=13
plateWidth['NLP-00035-82-660-01-B5']=15
plateWidth['NLP-00035-82-628-A1']=13
plateWidth['NLP-00035-82-628-A2']=13
plateWidth['NLP-00035-82-628-A3']=13
plateWidth['NLP-00035-82-628-A4']=13
plateWidth['NLP-00035-82-628-A5']=15
plateWidth['NLP-00035-82-628-B1']=13
plateWidth['NLP-00035-82-628-B2']=13
plateWidth['NLP-00035-82-628-B3']=13
plateWidth['NLP-00035-82-628-B4']=13
plateWidth['NLP-00035-82-628-B5']=15
plateWidth['NLP-00035-82-608-01-A1']=13
plateWidth['NLP-00035-82-608-01-A2']=13
plateWidth['NLP-00035-82-608-01-A3']=13
plateWidth['NLP-00035-82-608-01-A4']=13
plateWidth['NLP-00035-82-608-01-A5']=15
plateWidth['NLP-00035-82-608-01-B1']=13
plateWidth['NLP-00035-82-608-01-B2']=13
plateWidth['NLP-00035-82-608-01-B3']=13
plateWidth['NLP-00035-82-608-01-B4']=13
plateWidth['NLP-00035-82-608-01-B5']=15
plateWidth['NLP-00035-82-466-01-A1']=13
plateWidth['NLP-00035-82-466-01-A2']=13
plateWidth['NLP-00035-82-466-01-A3']=13
plateWidth['NLP-00035-82-466-01-A4']=13
plateWidth['NLP-00035-82-466-01-A5']=15
plateWidth['NLP-00035-82-466-01-B1']=13
plateWidth['NLP-00035-82-466-01-B2']=13
plateWidth['NLP-00035-82-466-01-B3']=13
plateWidth['NLP-00035-82-466-01-B4']=13
plateWidth['NLP-00035-82-466-01-B5']=15
plateWidth['NLP-00035-82-473-01-A1']=13
plateWidth['NLP-00035-82-473-01-A2']=13
plateWidth['NLP-00035-82-473-01-A3']=13
plateWidth['NLP-00035-82-473-01-A4']=13
plateWidth['NLP-00035-82-473-01-A5']=15
plateWidth['NLP-00035-82-473-01-B1']=13
plateWidth['NLP-00035-82-473-01-B2']=13
plateWidth['NLP-00035-82-473-01-B3']=13
plateWidth['NLP-00035-82-473-01-B4']=13
plateWidth['NLP-00035-82-473-01-B5']=15
plateWidth['NLP-00030-10-398-01-A1']=13
plateWidth['NLP-00030-10-398-01-A2']=13
plateWidth['NLP-00030-10-398-01-A3']=13
plateWidth['NLP-00030-10-398-01-A4']=13
plateWidth['NLP-00030-10-398-01-A5']=13
plateWidth['NLP-00030-10-398-01-B1']=13
plateWidth['NLP-00030-10-398-01-B2']=13
plateWidth['NLP-00030-10-398-01-B3']=13
plateWidth['NLP-00030-10-398-01-B4']=13
plateWidth['NLP-00030-10-398-01-B5']=13
plateWidth['NLMP-70030K-311-379-01-A1']=7
plateWidth['NLMP-70030K-311-379-01-A2']=7
plateWidth['NLMP-70030K-311-379-01-A3']=7
plateWidth['NLMP-70030K-311-379-01-A4']=13
plateWidth['NLMP-70030K-311-379-01-B1']=7
plateWidth['NLMP-70030K-311-379-01-B2']=7
plateWidth['NLMP-70030K-311-379-01-B3']=7
plateWidth['NLP-00030-10-393-01-A1']=13
plateWidth['NLP-00030-10-393-01-A2']=13
plateWidth['NLP-00030-10-393-01-A3']=13
plateWidth['NLP-00030-10-393-01-A4']=13
plateWidth['NLP-00030-10-393-01-A5']=13
plateWidth['NLP-00030-10-393-01-B1']=13
plateWidth['NLP-00030-10-393-01-B2']=13
plateWidth['NLP-00030-10-393-01-B3']=13
plateWidth['NLP-00030-10-393-01-B4']=13
plateWidth['NLP-00030-10-393-01-B5']=13
plateWidth['NLP-00030-10-400-01-A1']=13
plateWidth['NLP-00030-10-400-01-A2']=13
plateWidth['NLP-00030-10-400-01-A3']=13
plateWidth['NLP-00030-10-400-01-A4']=13
plateWidth['NLP-00030-10-400-01-A5']=13
plateWidth['NLP-00030-10-400-01-B1']=13
plateWidth['NLP-00030-10-400-01-B2']=13
plateWidth['NLP-00030-10-400-01-B3']=13
plateWidth['NLP-00030-10-400-01-B4']=13
plateWidth['NLP-00030-10-400-01-B5']=13
plateWidth['NLP-00030-10-500-01-A1']=13
plateWidth['NLP-00030-10-500-01-A2']=13
plateWidth['NLP-00030-10-500-01-A3']=13
plateWidth['NLP-00030-10-500-01-A4']=13
plateWidth['NLP-00030-10-500-01-A5']=13
plateWidth['NLP-00030-10-500-01-B1']=13
plateWidth['NLP-00030-10-500-01-B2']=13
plateWidth['NLP-00030-10-500-01-B3']=13
plateWidth['NLP-00030-10-500-01-B4']=13
plateWidth['NLP-00030-10-500-01-B5']=13