iontest.py
2.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
from flask import jsonify, request,Response
from app.models import Product,Testdata
from app.utils.ad_convter import read
# from app.api.auths import Auth
from app import common
from app import db
from app.api import bp
from app.api.errors import bad_request
from app import Config
import random
from werkzeug.utils import secure_filename
from datetime import datetime
import os
import threading
import time
# ad_convter = AdConvter()
value = {}
@bp.route("/ionstart",methods=['POST'])
def ionstart():
global value
global is_start
data = request.get_json()
op=data['type']
# pid = data['id']
# testtime_len = data['testtime_len']
# product = Product.query.get_or_404(id)
# p_data = product.to_dict()
# width = p_data['width']
# length = p_data['length']
# value = {'msg':'success',}
# start_test('dynamic')
is_start = True
value = {
'history_value':{'xlabel':[],'ydata':[]},
'current_value':{'x':0,'y':0}
}
back = threading.Thread(target=back_get)
back.start()
payload = {'code':200,'op':op}
return jsonify(common.trueReturn(payload, "start success"))
@bp.route("/ionstop",methods=['POST'])
def ionstop():
global is_start
# data = request.get_json()
# value = {
# 'msg':'',
# 'data'{'xlabel':[],'ydata':[]}
# 'current_data':{'x':0,'y':0}
# }
is_start = False
payload = {'code':200}
return jsonify(common.trueReturn(payload, "stop success"))
def back_get():
global value
seq = 0
c_y = 0
while is_start:
value['history_value']['xlabel'].append(seq)
value['current_value']['x'] = seq
# c_y = random.randint(1, 10)
# c_y = ad_value()
value['history_value']['ydata'].append(c_y)
value['current_value']['y'] = c_y
# value['msg'] = 'success'
print (value)
time.sleep(1)
seq += 1
c_y += 0.5
value = {}
return True
def ad_value():
A0 = read(0x43)
standard_v = 5.20
# voltage = ((5.20/255)*A1)*1000
voltage = (5.20/255)*A0
voltage = format(voltage, '.2f')
# print ("A0:", A0, "A1:", A1,
# "A2:", A2,"A3:", voltage)
# logging.info("原始值:{}----电压:{}V".format(A0,voltage))
print ("原始值:{}----电压:{}V".format(A0,voltage))
return voltage
@bp.route("/testvalue",methods=['POST'])
def testvalue():
# current_value = AdConvter.read()
global value
return jsonify(common.trueReturn(value, "success"))