I have some JavaScript code to read the value of DM[1] in my Nano-10, but it uses
HOSTLINK
which I'm not completely sure what it is. It appears to be some relative path dealing with the device, but I would like to make absolute, so that I could call the command from a separate web page.
Here is my JavaScript Code:
function h2d(h) {
var val16 = parseInt(h,16)
if (val16 > 32767) val16 += -65536
return val16
}
function timestamp(){ return "?%0C"+new Date().getTime()}
function createXMLhttp() {var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}
catch (e) { try {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
catch (E) {xmlhttp=false}
}
@else
xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try { xmlhttp = new XMLHttpRequest()}
catch (e) { xmlhttp=false}
}
if (!xmlhttp && window.createRequest) {
try {xmlhttp = window.createRequest()}
catch (e) {xmlhttp=false}
}
return xmlhttp
}
function errormsg(txt){alert("Connection Failed:"+txt)}
var errCount=0
function checkSvrResp(xmlobject, from){
if (xmlobject.status!=200 || xmlobject.responseText==""){
errCount++
if (errCount > 3) {alert("Server Error!");return 0;}
else return 1
}
errCount=0
return 1
}
function getTemperature(){
var cmd = "HOSTLINK/RD00010014"+timestamp() // read first 20 DMs (max 50 in one read)
var xmlhttpObj=createXMLhttp()
xmlhttpObj.open("GET",cmd, true)
var DM = "Nothing..."
try {
xmlhttpObj.onreadystatechange=function() {
if (xmlhttpObj.readyState==4) {
if (!checkSvrResp(xmlhttpObj,"getTemperature")) return
dataStr = xmlhttpObj.responseText.substring(4)
DM = h2d(dataStr.substring(0,4))
// display the temperature
document.getElementById("Temperature").innerHTML = ""+DM
setTimeout(getTemperature, 10000);
}
}
xmlhttpObj.send(null)
} catch (e){errormsg("Failed at getDM"+e)}
}
The code is essentially just a stripped down version of the pre-built webpage. It does exactly what I want when run through the Nano-10, but I want it to be run through some other device. I feel that the
HOSTLINK
(in the getTemperature function) should just change to an IP address, or some slight modification of that. Any help would be appreciated.