严智鑫
2025-08-18 3b65a5dc04be7cdac460c84ebaa38bf009405128
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
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.northglass.Globel.mes"%>
<%@page import="com.northglass.SqlHelper.*"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <script src="/gmms2/static/js/ng/msgencoder.js"></script>
</head>
<body>
    <div class="content-wrapper" >
        <div>
            <span>输入设备号:</span>
            <select id="sel">
            </select>
            <button onclick="clk();">确定</button>
            
            <h4 id="hd"></h4>
        </div>    
        
        <div id="base">
        </div>
        
        
        
    </div>
    <script>
    
        <%
            out.print("var devs="+DBHelper.getTableToJson("SELECT id,machine_name from gmms_machine",true)+";");
        
        %>
         function init(){
            var sl=document.getElementById("sel");
            for(var i=0;i<devs.length;i++){
                var d=devs[i];
                var opt=document.createElement("option");
                opt.value=d.id;
                opt.innerText=d.machine_name;
                sl.appendChild(opt);
            }            
        }
        init();
    
        var mobian_config={};
        
        function makeDefaultConfig(){
            var data={
                header:{
                    name:"默认",
                    baseOffset:9
                }    ,
                body:[
                    
                ]
                    
            }
            
            var b=data.body;
            for(var j=0;j<5;j++){
                var p={
                        name:"---------------------------------------------------------------------------------------------------------------------------------",
                        baseOffset:0,
                        fields:[]
                }
                b.push(p);
                for(var i=0;i<10;i++){
                    var f={
                        name:"变量"+(j*10+i+1),
                        offset:(j*10+i)*2,
                        type:"short"
                    };
                    p.fields.push(f);
                }
            }
            return data;
        }
        
        
        var jia_su_tai = {
                header: {
                    name: "默认",
                    baseOffset: 9,
                    file: "加速台",
                },
                body: [
                    {
                        name: "PLC--------------------",
                        baseOffset: 0,
                        fields: [
                            { name: '任务请求字', offset: 0, type: "short" },
                            { name: '任务请求ID', offset: 2, type: "short" },
                            { name: '备用0', offset: 4, type: "short" },
                            { name: '备用1', offset: 6, type: "short" },
                            { name: '备用2', offset: 8, type: "short" },
                            { name: '备用3', offset: 10, type: "short" },
                            { name: '备用4', offset: 12, type: "short" },
                            { name: '备用5', offset: 14, type: "short" },
                            { name: '备用6', offset: 16, type: "short" },
                            { name: '备用7', offset: 18, type: "short" }
                        ]
                    },
                    {
                        name: "MES--------------------",
                        baseOffset: 0,
                        fields: [
                            { name: '任务发送字', offset: 20, type: "short" },
                            { name: '任务发送ID', offset: 22, type: "short" },
                            { name: '长', offset: 24, type: "short" },
                            { name: '宽', offset: 26, type: "short" },
                            { name: '厚', offset: 28, type: "short" },
 
                            { name: '玻璃落架第几片', offset: 30, type: "short" },
                            { name: '备用', offset: 32, type: "short" },
                            { name: '备用1', offset: 34, type: "short" },
                            { name: '备用2', offset: 36, type: "short" },
                            { name: '备用3', offset: 38, type: "short" },
 
                            { name: '备用4', offset: 40, type: "short" },
                            { name: '备用5', offset: 42, type: "short" },
                            { name: '备用6', offset: 44, type: "short" },
                            { name: '备用7', offset: 46, type: "short" },
                            { name: '备用8', offset: 48, type: "short" },
 
                            { name: '备用9', offset: 50, type: "short" },
                            { name: '备用10', offset: 52, type: "short" },
                            { name: '备用11', offset: 54, type: "short" },
                            { name: '备用12', offset: 56, type: "short" },
                            { name: '备用13', offset: 58, type: "short" }
                        ]
                    },
                    {
 
                        name: "PLC-警报字-------------------",
                        baseOffset: 0,
                        fields: [
 
                            { name: '报警状态', offset: 60, type: "short" },
                            { name: '报警1', offset: 62, type: "short" },
                            { name: '报警2', offset: 64, type: "short" },
                            { name: '报警3', offset: 66, type: "short" },
                            { name: '报警4', offset: 68, type: "short" }
                        ]
 
                    },
                    {
 
                        name: "PLC-状态字-------------------",
                        baseOffset: 0,
                        fields: [
                            { name: '设备状态字', offset: 70, type: "short" },
                            { name: '输入输出1', offset: 72, type: "short" },
                            { name: '输入输出2', offset: 74, type: "short" },
                            { name: '输入输出3', offset: 76, type: "short" },
                            { name: '输入输出4', offset: 78, type: "short" },
 
                            { name: '输入输出5', offset: 80, type: "short" },
                            { name: '输入输出6', offset: 82, type: "short" },
                            { name: '输入输出7', offset: 84, type: "short" },
                            { name: '所有普通电机运行状态', offset: 86, type: "short" },
                            { name: '主程序控制字', offset: 88, type: "short" },
 
 
                            { name: 'X输送轴位置', offset: 90, type: "short" },
                            { name: 'Y输送轴位置', offset: 92, type: "short" },
                            { name: 'Y测量轴位置', offset: 94, type: "short" }
                        ]
 
                    }
                ]
            }
        
        
        
        var dic=[
          {
              id:10,
              config:jia_su_tai
          },
          {
              id:20,
              config:jia_su_tai
          },
          {
              id:32,
              config:jia_su_tai
          }
          
        ];
    
        var current_id=0;
        var auto_flag=false;
        var encoder=null;
        function createEncoder(cfg,id){
            document.getElementById("base").innerHTML="";
            encoder= createMessageDecoder(cfg,document.getElementById("base"));
            if(encoder!=null){
                auto_flag=true;
                current_id=id;
            }
        }
        function create(id){
            for(var i=0;i<dic.length;i++){
                if(dic[i].id==id){
                    current_id=id;
                    createEncoder(dic[i].config,id);
                    auto_flag=true;
                    return;
                }
            }
            
            createEncoder(makeDefaultConfig(),id);
            for(var i=0;i<devs.length;i++){
                if(devs[i].id==id){
                    
                    document.getElementById("hd").innerText=devs[i].machine_name;
                    return;
                }
            }
        }
        
        function end(data,ok){
            
            setTimeout(autoproc,1000);
            if(ok){
                var data=JSON.parse(data);
                encoder.update(data.data.message);
            }
        }
        
        function autoproc(){
            if(auto_flag && current_id>0){
                $.ajax({
                    url:"/gmms2/mesview/data/_msgpeek",
                    type:"post",
                    data:{id:current_id},
                    async:true,
                    success:function(data){
                        end(data,true);
                    },
                    error:function(data){
                        end(data,false);
                    }
                }
                );
                return;
            }
            setTimeout(autoproc,1000);
        }
        autoproc();        
        function clk(){
            var id=parseInt( document.getElementById("sel").value);
            if(id>0)
            create(id);
            
        }
    
    </script>
</body>
</html>