EasyManua.ls Logo

ControlByWeb X-600M - Page 146

ControlByWeb X-600M
158 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Appendix H: Custom Web Pages X-600M Users Manual
61:<script>
62: $(document).ready(function() {
63: // update the IO fields using data from widget1State.json every 3 seconds
64: currentPage.refreshIOFields("widget1State.json", 3, "content");
65: });
66:
67: function callback(result) {
68: var str = result.substring(2);
69: alert(str);
70: }
71:</script>
The key to updating I/O using the X-600M helper library is the function refreshIOFields that belongs to
the currentPage class. This function takes 3 parameters:
Filename: xml/json file to get I/O states from. In this example we use “widget1State.json.”
XML/JSON files are generate for any widgets found on the dashboard pages. For this example we
created a simple widget on the main dashboard with owSensor1 and register1 in order to get
widget1State.json. This will need to be done for any I/O that are to be updated in the custom web
pages. Alternatively the state.xml file can be used. This will return the states of all the I/O configured
on the X-600M.
RefreshRate: how often to update the page, in seconds. If set to 0, then the refresh will occur once.
ContentDivID: The id of the main content div for the page.
The refreshIOFields function will parse through the web page and look for all span tags with id's that
match I/O found in the XML/JSON file. It will then update the content inside the span tags to match that
of the XML file. In this example, the XML file would look like:
<datavalues>
<owSensor1>90.5</owSensor1>
<register1>100</register1>
</datavaues>
The span tag on line 14 has the id “owSensor1” and the span tag on line 18 has the id “register1”. The
content inside of these span tags will be updated to match the XML file every 3 seconds. If the div
specified in ContentDivID does not exist, then the updates will stop. This prevents updates continuing
when the page is no longer visible.
Another thing to note in this example is that the value of register1 can be changed by clicking on the
buttons labeled “ON”, “PULSE” and “TOGGLE” on lines 19, 20 and 21. These are just HTML input
buttons that have their onclick event setup to call the X-600M helper library functions set, pulse, and
toggle. Each of these functions belong to the reg class, the first and last parameters of each are the
same:
regName: The name of the register to change, “register1” in this example.
callback: A callback function to call with the result of the function.
The second parameter of the set function is the value that the register should be set to. The second
parameter of the pulse function is the pulse time.
Line 67 shows an example of a callback function that can be called when these functions return. The
callback function has one parameter, which contains the result of the function call. The format of result is
x:desc”, where x is a result code, and desc is a description of the result code. The following table lists
the possible result codes and their descriptions that can be expected from any of the X-600M helper
functions.
Page 144 Xytronix Research & Design, Inc.

Table of Contents