induction_debug.html
11.7 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
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>{{ _('感应式料架系统') }}-Admin</title>
<link rel="icon" href="/static/favicon.ico">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<style>
.shelf_row {}
.shelf_box {
width: 100%;
border-top: 1px black solid;
border-bottom: 1px black solid;
border-right: 1px black solid;
margin: 5px;
background-color: gainsboro;
}
.shelf_col {
height: 30px;
float: left;
border-left: 1px black solid;
}
.align_right {
width: 100%;
text-align: right;
}
.st {
font-size: 12px;
font-weight: bolder;
transform: scale(0.7);
word-wrap: break-word;
line-height: 12px;
width: 100%;
height: 100%;
}
.t {
background-color: lightgreen;
}
.cla {
background-color: white;
}
</style>
</head>
<body style="font-size:18px;">
{% set index=5 %}
{% import 'head.html' as head with context%}
{{ head }}
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<h2>{{ _('料架系统') }}</h2>
<hr class="divider">
<!-- 灯条测试 -->
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">{{ _('料架状态显示') }}</h3>
</div>
<div class="panel-body">
<div class="col-sm-12">
<input type="button" value="{{ _('开始扫描库位') }}" id="btn_start" class="btn btn-warning"
onclick="startscan()" />
<input type="button" value="{{ _('停止扫描库位') }}" id="btn_stop" class="btn btn-warning"
onclick="stopscan()" />
</div>
<div style="clear: both;margin: 5px;width: 100%;"></div>
<div id="shelflist"></div>
<div style="height: 10px;"></div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
});
//运行中状态
var isrun = false;
//站号灯书对应表
ledcountdict = {};
//当前扫描站号
var current_addr = '';
var current_test_index = 0;
var checked_test_index = -1;
//全部站号
var addrlist = [];
$("#btn_stop").hide();
function startscan() {
if (confirm("进入料架扫描,需要停止料架运行,点击确认停止")) {
stoppost();
}
else
return;
isrun = true;
current_addr = '';
if ($(".shelf_col").length == 0) {
$.ajax({
url: "/getledcount",
type: "get",
contentType: "text/json",
dataType: 'json',
success: function (data) {
setshelflist(data)
},
error: function (e) {
alert("error");
}
});
}
else {
$(".shelf_box").removeClass('cla');
setshelflist([])
}
}
function stopscan() {
isrun = false;
starttest("");
$(".shelf_box").addClass('cla');
$("#btn_stop").hide();
$("#btn_start").show();
}
function setshelflist(data) {
$("#btn_stop").show();
$("#btn_start").hide();
//$("#shelflist").html('');
for (var e in data) {
var ledinfo = data[e];
var ledcount = ledinfo['ledcount'];
ledcountdict[e] = ledcount
var DeviceUniqueID = ledinfo['DeviceUniqueID'];
var Version = ledinfo['Version'];
var shelfid = "shelf_" + e;
addrlist.push(e);
$("#shelflist").append("<div class='shelf_row'><div>" + e + " - V" + Version + "- <span id='" + shelfid + "_info'></span></div></div><div id='" + shelfid + "' class='shelf_box'></div><div class='align_right'><input type='button' value=\"{{ _('开始顺序测试') }}\" class='btn btn-warning' onclick='starttest(\"" + e + "\")'/></div></div>");
for (var i = 0; i < ledcount; i++) {
var width = 100 / ledcount;
$("#" + shelfid).append("<div id='col_" + i + "' class='shelf_col' style='width:" + width + "%'><div class='st'>" + (ledcount - i) + "</div></div>");
}
$("#" + shelfid).append("<div style='clear:both'></div>");
};
getshelfstate();
}
function starttest(addr) {
current_addr = addr;
current_test_index = 0;
checked_test_index = -1;
}
function getshelfstate() {
var addrs = addrlist.join('@');
if (current_addr.length > 0)
addrs = currnet_addr
var data = { "addrs": addrs };
$.ajax({
url: "/getshelfstate",
type: "get",
contentType: "text/json",
dataType: 'json',
data: JSON.stringify(data),
success: function (data) {
try {
if (!isrun)
return;
if (data['msg']) {
stoppost();
getshelfstate();
return;
}
var addrcopy = addrlist.slice(0);
for (var e in data) {
shelfid = e;
if (shelfid.length == 3)
shelfid = "B" + e.substring(2);
var shelfdom = $("#shelf_" + shelfid)
shelfdom.remove('cla');
if (addrcopy.indexOf(shelfid) >= 0) {
addrcopy.splice(addrcopy.indexOf(shelfid), 1)
}
line = data[e];
ledcount = ledcountdict[shelfid];
if (shelfdom.length == 0)
continue;
rightledlist = [];
badledlist = [];
closeledlist = [];
shelfdom = shelfdom[0]
for (var i = 0; i < ledcount; i++) {
var d = $(shelfdom.childNodes[ledcount - 1 - i])
if (line[i] == "0") {
if (d.hasClass('t')) {
d.removeClass('t');
closeledlist.push(i + 1);
if (String(checked_test_index) == line[i] && current_test_index == checked_test_index) {
current_test_index++;
setledcolor(e, 'blue', [i + 1]);
}
}
} else {
if (!d.hasClass('t')) {
d.addClass('t');
if (String(current_test_index) == line[i]) {
rightledlist.push(i + 1);
} else {
badledlist.push(i + 1);
}
}
}
}
if (ledcount==current_test_index){
}
if (badledlist.length > 0) {
setledcolor(e, 'red', badledlist);
setledcolor(e, 'red', rightledlist);
} else if (rightledlist.length > 0) {
checked_test_index = current_test_index;
setledcolor(e, 'green', rightledlist);
}
//setledcolor(e, 'red', openledlist, closeledlist);
}
addrcopy.forEach(function (shelfid) {
$("#shelf_" + shelfid + "").addClass('cla');
})
} catch { }
finally {
if (isrun)
setTimeout(getshelfstate(), 1);
}
},
error: function (e) {
if (isrun)
setTimeout(getshelfstate(), 1);
}
})
};
function setledcolor(addr, color, ledlist) {
if (ledlist.length == 0 && closeledlist.length == 0)
return;
var data = {
"addr": addr,
"color": color,
"ledlist": ledlist,
}
$.ajax({
url: "/setledcolor",
type: "post",
data: JSON.stringify(data),
contentType: "application/json",
dataType: 'json',
async: false,
success: function (data) {
console.log(data);
},
error: function (e) {
//alert("error");
}
})
}
function stoppost() {
$.ajax({
url: "/stoppost",
type: "post",
async: false,
// data:form,
dataType: 'json',
processData: false,
contentType: false,
success: function (data) {
//alert(data[0].msg)
},
error: function (e) {
//alert("{{_('停止失败')}}");
}
})
}
// auto_calibrate
function auto_calibrate() {
if (confirm("{{ _('请谨慎操作') }}")) {
var addrs = document.getElementById("addr").value;
addrs = addrs.replace('B', 'A1');
addrs = addrs.replace('A', '');
var data = {
"addr": addrs,
"calibrate": document.getElementById("calibrate").value
}
$.ajax({
url: "/auto_calibrate",
type: "post",
data: JSON.stringify(data),
contentType: "application/json",
dataType: 'json',
success: function (data) {
// $("#testinfo").html(data.msg)
alert(data.msg);
},
error: function (e) {
alert("error");
}
})
}
}
</script>
</body>
</html>