<!DOCTYPE html>
<% language=javascript %>
<html>
<head lang="en">
    <meta charset="GB2312">
    <title></title>
    <link href="css/style.css" title="style" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.6.3.min.js"></script>

</head>
<body style="background: #F3F3F3">
<div class='type1280 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-elec.png" style="width: 70%;text-align: center;"></td>
    <td>
    <table width='100%'>
        <tr><td style='border: none'> <h1>HC-311A单相导轨式电表</h1></td></tr>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID272'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr272'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port272'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd272'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State272'> </span></td></tr>
    </table>
    <table width='100%' style='margin-top: 30px'>
        <tr><td style='border: none'> <h1>各项基本信息</h1></td></tr>
		<tr><td width='25%'>电压1: <span class='Vol1272'></span></td><td width='25%'>电压2: <span class='Vol2272'></span></td><td width='25%'>电压3: <span class='Vol3272'></span></td><td width='25%'><span class='272'></span></td></tr>
		 <tr><td width='25%'>开关量输入1: <span class='Di1272'></span></td><td width='25%'>开关量输入2: <span class='Di2272'></span></td><td width='25%'>开关量输入3: <span class='Di3272'></span></td><td width='25%'>开关量输入4: <span class='Di4272'></span></td></tr>
		 <tr><td width='25%'>开关量输出1: <span class='Do1272'></span></td><td width='25%'>开关量输出2: <span class='Do2272'></span></td><td width='25%'>开关量输出3: <span class='Do3272'></span></td><td width='25%'>开关量输出4: <span class='Do4272'></span></td></tr>
		
    </table>
    <table width='100%' style='margin-top: 30px' class="ofBTN">
        <tr><td style='border: none'> <h1>开关量输出</h1></td></tr>
        <tr><td width='20%'>开关量输出1: </td><td width='30%'> <a  href='javascript:relayctrl(0, 1)' id='DOX1On' class='gray'>闭合</a><a href='javascript:relayctrl(0, 0)' id='DOX1Off' class='gray'>断开</a></td><td></td></tr>
        <tr><td width='20%'>开关量输出2: </td><td width='30%'> <a  href='javascript:relayctrl(1, 1)' id='DOX2On' class='gray'>闭合</a><a href='javascript:relayctrl(1, 0)' id='DOX2Off' class='gray'>断开</a></td><td></td></tr>
        <tr><td width='20%'>开关量输出3: </td><td width='30%'> <a  href='javascript:relayctrl(2, 1)' id='DOX3On' class='gray'>闭合</a><a href='javascript:relayctrl(2, 0)' id='DOX3Off' class='gray'>断开</a></td><td></td></tr>
        <tr><td width='20%'>开关量输出4: </td><td width='30%'> <a  href='javascript:relayctrl(3, 1)' id='DOX4On' class='gray'>闭合</a><a href='javascript:relayctrl(3, 0)' id='DOX4Off' class='gray'>断开</a></td><td></td></tr>
    </table>
    </td>
    </tr>
  </table>
    
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
</div>
<script>
var itype=272;
var tescape= 5000,time;
  
<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json=<% db_QryAdv("select * from tbElecXuanYue where SID="+sid,0);%>;
<% db_Close(); %>
	
var dovalue = 0;

$(function(){
   time=setInterval(ajax,tescape)
});
function ajax(){
    $.ajax({
        type: "POST",
        url: "omdev/smdat0.asp",
        data: "itype="+itype+"&sid="+sid,
        dataType:"json",
        success: function(msg){
            list3(msg); 
			
        }
    });
}
var monitorStatus = ["正常","告警","故障"];

list3(json);
function list3(data){
    $.each(data.recs,function(i,n){
        $(".SID272").html(n.SID);
        $(".Addr272").html(n.Addr);
        $(".Port272").html(n.Port%256);
        $(".DateUpd272").html(n.DateUpd);
        $(".State272").html(monitorStatus[n.State%3]);
        $(".Type272").html(n.Type+"A");
        $(".Snap272").html(n.SnapID);

        $(".Vol1272").html(n.Vol1/10+"V");
        $(".Vol2272").html(n.Vol2/10+"V");
        $(".Vol3272").html(n.Vol3/10+"V");
		$(".Di1272").html(n.Di1 ? "吸合" : "断开");
		$(".Di2272").html(n.Di2 ? "吸合" : "断开");
		$(".Di3272").html(n.Di3 ? "吸合" : "断开");
		$(".Di4272").html(n.Di4 ? "吸合" : "断开");
		
		$(".Do1272").html(n.Do1 ? "吸合" : "断开");
		if (n.Do1)
		{
			dovalue |= 0x01;
            $("#DOX1On").attr("class","redd");
            $("#DOX1Off").attr("class","gray");
		}
		else
		{
			dovalue &= ~0x01;
            $("#DOX1On").attr("class","gray");
            $("#DOX1Off").attr("class","redd");
		}
		
		$(".Do2272").html(n.Do2 ? "吸合" : "断开");
		if (n.Do2)
		{
			dovalue |= 0x02;
            $("#DOX2On").attr("class","redd");
            $("#DOX2Off").attr("class","gray");
		}
		else
		{
			dovalue &= ~0x02;
            $("#DOX2On").attr("class","gray");
            $("#DOX2Off").attr("class","redd");
		}
		
		$(".Do3272").html(n.Do3 ? "吸合" : "断开");
		if (n.Do3)
		{
			dovalue |= 0x04;
            $("#DOX3On").attr("class","redd");
            $("#DOX3Off").attr("class","gray");
		}
		else
		{
			dovalue &= ~0x04;
            $("#DOX3On").attr("class","gray");
            $("#DOX3Off").attr("class","redd");
		}
		
		$(".Do4272").html(n.Do4 ? "吸合" : "断开");
		if (n.Do4)
		{
			dovalue |= 0x08;
            $("#DOX4On").attr("class","redd");
            $("#DOX4Off").attr("class","gray");
		}
		else
		{
			dovalue &= ~0x08;
            $("#DOX4On").attr("class","gray");
            $("#DOX4Off").attr("class","redd");
		}
		
    })
	$("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
        $("span:contains('正常')").addClass("ger").removeClass("red");
    
}

function relayctrl(idx, state)
{
	if (state)
		dovalue |= (1<<idx);
	else
		dovalue &= ~(1<<idx);
		
	var wParam = 0x10001D; //[32:16]功能码，[15:0]寄存器地址
	var lParam = (sid << 16) | (dovalue & 0xFFFF)//[32:16]SID，[15:0]控制值
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        success: function(msg){
            alert("ok!");
        }
    });
}

</script>
</body>
</html>