prevalue_set.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="icon" href="favicon.ico" type="image/x-icon">
  5. <title>Set PreValue</title>
  6. <meta charset="utf-8">
  7. <style>
  8. h1 {font-size: 2em;}
  9. h2 {font-size: 1.5em;}
  10. h3 {font-size: 1.2em;}
  11. p {font-size: 1em;}
  12. div {
  13. width: 200px;
  14. padding: 10px 5px;
  15. display: inline-block;
  16. border: 1px solid #ccc;
  17. font-size: 16px;
  18. max-height: 35px;
  19. }
  20. input[type=number] {
  21. width: 125px;
  22. padding: 10px 5px;
  23. display: inline-block;
  24. border: 1px solid #ccc;
  25. font-size: 16px;
  26. }
  27. .button {
  28. padding: 10px 20px;
  29. width: 211px;
  30. font-size: 16px;
  31. }
  32. </style>
  33. </head>
  34. <body style="font-family: arial; padding: 0px 10px;">
  35. <h3>Set the previous value for consistency check and substitution for NaN</h3>
  36. <class id="Numbers_text" style="font-size: 120%; color:black;"><b>Choose Number: </b>
  37. <select id="Numbers_value1" onchange="numberChanged()">
  38. </select>
  39. </class>
  40. <table style="width:100%">
  41. <tr>
  42. <h3>Current Value:</h3><p>
  43. <div id="prevalue"></div>
  44. <h3>Set Value:</h3><p>
  45. Input (Format = 123.456):<p>
  46. Previous Value:
  47. <input type="number" id="myInput" name="myInput"
  48. pattern="[0-9]+([\.,][0-9]+)?" step="0.001"
  49. title="This should be a number with up to 4 decimal places.">
  50. <p></p>
  51. <button class="button" type="button" onclick="setprevalue()">Set Previous Value</button>
  52. </tr>
  53. <tr>
  54. <h3>Result:</h3><p>
  55. <div id="result" readonly></div>
  56. </tr>
  57. </table>
  58. </body></html>
  59. <script type="text/javascript" src="common.js"></script>
  60. <script type="text/javascript" src="readconfigcommon.js"></script>
  61. <script type="text/javascript" src="readconfigparam.js"></script>
  62. <script type="text/javascript">
  63. var domainname = getDomainname();
  64. var NUMBERS;
  65. function setprevalue() {
  66. var inputVal = document.getElementById("myInput").value;
  67. var sel = document.getElementById("Numbers_value1");
  68. var _number = sel.options[sel.selectedIndex].text;
  69. inputVal = inputVal.replace(",", ".");
  70. var xhttp = new XMLHttpRequest();
  71. try {
  72. url = domainname + "/setPreValue?value=" + inputVal + "&numbers=" + _number;
  73. xhttp.open("GET", url, false);
  74. xhttp.send();
  75. response = xhttp.responseText;
  76. document.getElementById("result").innerHTML=response;
  77. }
  78. catch (error)
  79. {
  80. alert("Failed to get data from device!");
  81. }
  82. }
  83. function loadPrevalue(_domainname) {
  84. // Get current Pre Value
  85. var sel = document.getElementById("Numbers_value1");
  86. var _number = sel.options[sel.selectedIndex].text;
  87. var xhttp = new XMLHttpRequest();
  88. try {
  89. url = _domainname + '/setPreValue?numbers=' + _number;
  90. xhttp.open("GET", url, false);
  91. xhttp.send();
  92. response = xhttp.responseText;
  93. document.getElementById("prevalue").innerHTML=response;
  94. }
  95. catch (error)
  96. {
  97. alert("Failed to get data from device!");
  98. }
  99. // Get current RAW Value
  100. var sel = document.getElementById("Numbers_value1");
  101. var _number = sel.options[sel.selectedIndex].text;
  102. var xhttp = new XMLHttpRequest();
  103. try {
  104. url = _domainname + '/value?all=true&type=raw';
  105. xhttp.open("GET", url, false);
  106. xhttp.send();
  107. response = xhttp.responseText;
  108. lines = response.split(/\r?\n/);
  109. lines.forEach(function(line) {
  110. arr = line.split("\t");
  111. if (_number == arr[0]) {
  112. document.getElementById("myInput").value=arr[1];
  113. return;
  114. }
  115. });
  116. }
  117. catch (error)
  118. {
  119. alert("Failed to get data from device!");
  120. }
  121. }
  122. function numberChanged(){
  123. loadPrevalue(domainname);
  124. }
  125. function UpdateNUMBERS(_sel){
  126. zw = getNUMBERInfo();
  127. index = 0;
  128. var _index = document.getElementById("Numbers_value1");
  129. while (_index.length){
  130. _index.remove(0);
  131. }
  132. for (var i = 0; i < zw.length; ++i){
  133. var option = document.createElement("option");
  134. option.text = zw[i]["name"];
  135. option.value = i;
  136. _index.add(option);
  137. if (typeof _sel !== 'undefined') {
  138. if (zw[i]["name"] == _sel)
  139. index = i
  140. }
  141. }
  142. _index.selectedIndex = index;
  143. loadPrevalue(domainname);
  144. }
  145. function init(){
  146. domainname = getDomainname();
  147. loadConfig(domainname);
  148. ParseConfig();
  149. UpdateNUMBERS();
  150. loadPrevalue(domainname);
  151. }
  152. init();
  153. </script>