Data Sheet

dScript
dScript User Manual v2.15
First we need to add the following to the dScript program to define the relay:
digitalport Rly1 1
so we have:
tcpip.hostname "dS3484"
tcpip.ip "192.168.0.136"
tcpip.mask "255.255.255.0"
digitalport Rly1 1
main: do
loop
The button line on the web page needs some more code, change it to:
<button id="Rly1" onmousedown="newAJAXCommand('dscript.cgi?Rly1=2');">Yard
Lights</button>
We have given the button the id "Rly1" so we can refer to it to update the colour. We also
added onmousedown="newAJAXCommand('dscript.cgi?Rly1=2');"
The general format for changing something on the module is
"newAJAXCommand('dscript.cgi?name=value');"
Where a name is a defined resource in the dScript program and value is what you want to
assign to it. In the case of digitalport objects, 0 will clear it, 1 will set it and 2 will toggle it.
dscript.cgi is the file that processes these commands, you do not need to supply this file as it's
built in.
We also need to add just a little javascript to make it happen. It's a single function containing
one line of code (and the start/end script tags)
<script type="text/javascript">
function ajaxUpdate()
{
document.getElementById('Rly1').style.backgroundColor =
(getValue('Rly1')=='1') ? 'rgba(255,0,0,0.2)' : 'rgba(0,0,255,0.2)';
}
</script>
ajaxUpdate is a callback function you must include, it is called whenever new variable data
arrives from the module so you can update your web page.
getValue('Rly1') is a function you call from within ajaxUpdate to retrieve the value of your
variables. The variable name must be identical to the one used in your dScript program.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
42