induction_admin.py
4.3 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
# 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
from config import Config
from werkzeug.utils import secure_filename
from app.utils.serial_communication import SerialCommunication
from app.induction_config import read_addrs
from serial_config import ReadConfig
from app.utils.location import Location
config_dict,convert_dict = Location().read_location_file()
# ser = SerialCommunication()
@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('/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})