OSDN Git Service

replaced all files
[vem/WITs.git] / tsurutafile / emcontrol.js
1 var emname;
2 console.log("program move");
3 function emnamecatch(name){
4     emname=name;
5     console.log(emname);
6 }
7
8 function emcondition(command) {
9
10 var ajax=getAjax();
11
12     if (command == "request") {
13         var position1 = document.getElementById("Position");
14         var SpotsizeIndex = document.getElementById("SpotsizeIndex");
15         var MagIndex = document.getElementById("MagIndex");
16         var Obj = document.getElementById("Obj");
17         var BeamTilt = document.getElementById("BeamTilt");
18         var Speed = document.getElementById("Speed");
19     } else {
20         var position1 = document.anchorsgetElementById("result");
21     }
22
23     if (ajax) {
24         try {
25             ajax.onreadystatechange = getData;
26         } catch (e) {
27             position1.innerHTML = "Onreadystate change error.";
28         }
29         try {
30             ajax.open("GET", "//localhost:9090/"+encodeURIComponent(emname)+"/get", true);
31             console.log("//localhost:9090/"+encodeURIComponent(emname)+"/get");
32         } catch (e) {
33             position1.innerHTML = "ajax open error";
34         }
35         try {
36             ajax.send(null);
37         } catch (e) {
38             position1.innerHTML = "send error";
39         }
40
41     } else {
42         position1.innerHTML = "you cannot use ajax....";
43     }
44
45     function getData() {
46         if (ajax.readyState == 4) {
47             if (ajax.status == 200) {
48                 console.log("Hello!");
49                 var resultjson = ajax.responseText;
50                 resultjson = JSON.parse(resultjson);
51                 console.log(typeof resultjson);
52                 /*
53                  for (key in resultjson) {
54                  console.log(key+":"+resultjson(key));
55                  }
56                  */
57                 //position1.innerHTML=resultjson;
58                 position1.innerHTML = "x=" + resultjson["GonionX"] + " y=" + resultjson['GonionY'] + " z=" + resultjson['GonionZ'] + " a=" + resultjson['GonionA'];
59                 SpotsizeIndex.innerHTML = "Spotsize:" + resultjson['SpotsizeIndex'];
60                 MagIndex.innerHTML = "MagIndex:" + resultjson['MagIndex'];
61                 Obj.innerHTML = "Obj:" + resultjson['Obj'];
62                 BeamTilt.innerHTML = "BeamTilt:" + resultjson['BeamTilt'];
63                 Speed.innerHTML = "Speed:" + resultjson['Speed'];
64                 //   result.innerHTML = ajax.responseText;
65             } else {
66                 position1.innerHTML = "HTTP transmission....";
67             }
68         }
69     }
70 }