pCOWeb
+030220966 – rel. 1.1 – 12.12.2017
76
Library “pw_ajax.js” and CGI “xml.cgi”
APPENDIX H
Overview
To cope with the increasing requests to integrate
pCOWeb
in enterprises system, it had became mandatory for the
pCOWeb
to integrate a standard way of
communicate using the HTTP protocol, that is why the
pCOWeb
now is able to send information using XML over HTTP (which is the standard way to use the
XML).
Minimum Requirements
This application note is addressed to people with the following knowledge:
•
Discrete knowledge of HTML
•
Discrete knowledge of JAVASCRIPT
How to read variables
Starting from version A135 (and with major improvements in version A142)
pCOWeb
implements a library called “pw_ajax.js” that allows users to read the
values of the variables without using the standard
pCOWeb
HTML tags.
Example (need to copy the file “pw_ajax.js” from the config folder to the same folder of the html file):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-15" http-equiv="content-type">
<title>Happy Island</title>
<script src="pw_ajax.js" type="text/javascript"></script>
<script type="text/javascript">
// arrays used by the javascript library, DO NOT USE OTHER NAMES!
digitals = new Array;
integers = new Array;
analogs = new Array;
var timestamp;
function getVariables() {
// N.B. The function getParams is defined in the file pw_ajax.js
// This reads variables Digitals 1 and 2, Integers 11 and 12 and
// analogs 101 and 102
// and then copy them into the arrays declared here above to the
// cells with the index equal to their supervisry index
// e.g. analog 101 is copied into the array called "analogs" to the index 101
// The string is composed by: TYPE|START_INDEX|END_INDEX|TYPE2|START_INDEX2...
// It can contain up to 5 different ranges of variables
getParams('/config/xml.cgi','D|1|2|I|11|12|A|101|102');
function parseResults() {
// The following instructions assign the values of the variables
// in the arrays to an element of the HTML page to be visualized
document.getElementById("digital1").innerHTML=digitals[1];
document.getElementById("digital2").innerHTML=digitals[2];
document.getElementById("integer11").innerHTML=integers[11];
document.getElementById("integer12").innerHTML=integers[12];
document.getElementById("analog101").innerHTML=analogs[101];
document.getElementById("analog102").innerHTML=analogs[102];
document.getElementById("currentTime").innerHTML=timestamp;
// Refresh the variables every 5 seconds (the time is ms)
timer=setTimeout('getVariables()',5000);
}
</script>
</head>
<body onLoad="getVariables();">
<!—- The onLoad is necessary to load the variables as soon as the page loads -->
Current time is: <span id="currentTime"></span><br>
<table>
<tr>
<td>Digital 1 is:</td><td><span id="digital1"></span></td>
</tr>
<td>Digital 2 is:</td><td><span id="digital2"></span></td>
</tr>
<td>Integer 11 is:</td><td><span id="integer11"></span></td>
</tr>
<td>Integer 12 is:</td><td><span id="integer12"></span></td>
</tr>
<td>Analog 101 is:</td><td><span id="analog101"></span></td>
</tr>
<td>Analog 102 is:</td><td><span id="analog102"></span></td>
</tr>
</table>
</body>
</html>
As you can see from the example here above, the line <!--tagparser="/pcotagfilt"--> doesn’t need to be included in the code because the
pCOWeb
doesn’t
have to parse the page as values are coming from the xml, reducing the workload of the card, the values will be loaded on the arrays by the function get
Variables.