我正在写一个网页,当我按下按钮,执行其功能,然后自我关闭时将打开。该功能用于解释继电器的状态,并将其从开启切换为关闭或从关闭切换为开启。
简要背景:
我正在切换支持网络的主板上的继电器。每块板上有16个继电器。通过打开特定网页来切换每个中继。例如:192.168.1.4/30000/05打开继电器3. 192.168.1.4/30000/06将其关闭。
我可以通过打开192.168.1.4/30000/99来获取板上所有16个继电器的状态。当我这样做时,它返回一个带有16位二进制响应的网页。最左边的数字代表继电器1状态(1 =关闭,0 =开),最右边的数字是继电器16.例如:1001100111001101
请求:
我需要帮助代码打开... 99网站(我已经可以做),解释特定继电器的状态(比如继电器3),将该状态设置为变量并使用该变量if / else语句将打开相应的网页来切换中继。
我不知道如何从open ... 99网站中提取数据并将其解析为我尝试定位的特定中继状态。
这是我到目前为止的代码。我在这个页面上正确加载它有点麻烦。是的。我是一个非常新手的编码员。
<!DOCTYPE html>
<html>
<head>
<title>Button Press</title>
<--This script opens a window which displays the status of 16 relays in binary fashion. It closes the "data" window and then closes the browser. For example: 1100001000110011 means relays 1,2,7,11,12,15,16 are on. Others are off. -->
<script type="text/javascript">
function GetStatus(){
var win = window.open('http://192.168.0.89/30000/99');
setTimeout(function() {win.close();}, 1000);
var closeme = window.open('', '_self', '');;
setTimeout(function() {closeme.close();}, 4000);
}
</script>
<--Here I need help with code that will interpret the data extracted above and singling out a single relay for use as a variable (Status) with the if/else statement below. For example, I want to know the status of relay 3 from GetStatus and set it as the varible to use below.-->
<--This if/else statement is intended to use the relay Status variable collected above and open one of two webpages to trigger the relay to go to the alternate state. The relays are toggled by opening a specific webpage. 192...05 turns it on, 192... 04 turns it off. The page will open, then close after a timeout. I hope I have designed my if/else statement correctly. I have assumed Status is a variable created by the parsing process commented above (that I have no idea how to do) -->
if(Status = 0) {
<script type="text/javascript">
function ActionOff(){
var win = window.open('http://192.168.0.89/30000/05','','');
setTimeout(function() { win.close();}, 1000);
}
</script>
} else {
<script type="text/javascript">
function ActionOn(){
var win = window.open('http://192.168.0.89/30000/06','','');
SetTimeout(function() { win.close();}, 1000);
}
</script>
}
</head>
<--The intention is for this page to automate upon opening, then close itself when it is done via the GetStatus function.-->
<body onload="GetStatus();">
</body>
</html>
如果一切正常,当我转到此网页时,它将打开,读取所有继电器的状态,隔离目标继电器状态,并通过if / else语句,将继电器的状态从打开切换到关闭,或从关闭到开启。然后所有窗口和浏览器都将关闭。