Jump to content

edic01

Neophyte
  • Posts

    1
  • Joined

  • Last visited

Everything posted by edic01

  1. Помогите, пожалуйста, разобраться в коде! Не могу понять где происходит вывод не нулевых значений. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script type="text/javascript"> var host="10.1.0.99"; var Module_Port=502; var NetID=1; var DO=new Array; var AAO=new Array; DO[631]=1; var MAXCDEL='500ms'; AAO[427]=new Array(12,12,12); AAO[296]=new Array(32767,32767,32767); AAO[328]=new Array(-32768,-32768,-32768); var AICh=3; </script> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>HMI</title> <script src="AC_OETags.js" language="javascript"></script> <style type="text/css"> body {font: 12px Arial; background-color: #D0D0D0; margin: 0px; overflow: auto} table {font: 14px Arial; background-color: #EEEEEE; width: 96%; border-collapse: collapse} caption {font: bold 14px Arial; text-align: left} input {font: normal 12px arial} .Clr_Button {font: normal 11px arial; width: 30%} </style> <script type="text/javascript" src="AnalogIO.js"></script> <script type="text/javascript"> var requiredMajorVersion=9; var requiredMinorVersion=0; var requiredRevision=28; var Timer, Timeout; var Scanrate=300; var IsSent; var iProcess; function thisMovie(movieName){ if (navigator.appName.indexOf("Microsoft")!=-1) { return window[movieName]; } else { return document[movieName]; } } function ModbusSocketClose(event_string){ //alert(event_string); IsSent=-1; } function sendToActionScript(FunCode, ReferNum, Counnt, Value){ thisMovie("msocket").sendToActionScript(FunCode, ReferNum, Counnt, Value); } function setData(msg){ var patt1=/[0-9a-f]{1,2}/g; var result=msg.match(patt1); var ivalue; var temp; if(result!=null){ try{ if(iProcess==0 && result[1]=="04" && parseInt(result[2], 16)==(AICh*2)){ for(var i=0; i<AICh; i++){ if(DO[631]){ ivalue=parseInt(result[(i<<1)+3]+result[(i<<1)+4], 16); if(ivalue>32767) ivalue-=65536; document.getElementById("AI"+i).innerHTML=ivalue; } else document.getElementById("AI"+i).innerHTML=(result[(i<<1)+3]+result[(i<<1)+4]).toUpperCase(); document.getElementById("AI_Floating"+i).innerHTML=Hex2Float_AI(result[(i<<1)+3]+result[(i<<1)+4], i); } } if(iProcess==1 && result[1]=="04" && parseInt(result[2], 16)==((32+AICh)*2)){ var iIdx=0; var i=0; do{ if(i<AICh){ if(DO[631]){ ivalue=parseInt(result[(i<<1)+3]+result[(i<<1)+4], 16); if(ivalue>32767) ivalue-=65536; document.getElementById("Lahch_High_"+iIdx).innerHTML=ivalue; } else document.getElementById("Lahch_High_"+iIdx).innerHTML=(result[(i<<1)+3]+result[(i<<1)+4]).toUpperCase(); document.getElementById("Lahch_High_Float_"+iIdx).innerHTML=Hex2Float_AI(result[(i<<1)+3]+result[(i<<1)+4], iIdx++); } else if(i>31){ if(DO[631]){ ivalue=parseInt(result[(i<<1)+3]+result[(i<<1)+4], 16); if(ivalue>32767) ivalue-=65536; document.getElementById("Lahch_Low_"+iIdx).innerHTML=ivalue; } else document.getElementById("Lahch_Low_"+iIdx).innerHTML=(result[(i<<1)+3]+result[(i<<1)+4]).toUpperCase(); document.getElementById("Lahch_Low_Float_"+iIdx).innerHTML=Hex2Float_AI(result[(i<<1)+3]+result[(i<<1)+4], iIdx++); } i++; if(i==31) iIdx=0; }while(i<(32+AICh)) } if(iProcess==2 && result[1]=="02" && parseInt(result[2], 16)==byteCount(32+AICh)){ var decvalue_high=(parseInt(result[5], 16)<<16)+(parseInt(result[4], 16)<<8)+parseInt(result[3], 16); var decvalue_low=(parseInt(result[8], 16)<<8)+parseInt(result[7], 16); for(var i=0; i<AICh; i++){ temp=document.getElementById("Alarm_High_"+i); if(temp!=null) temp.innerHTML=(decvalue_high&(0x01<<i))?"<font color='red'>ON</font>":"OFF"; temp=document.getElementById("Alarm_Low_"+i); if(temp!=null) temp.innerHTML=(decvalue_low&(0x01<<i))?"<font color='red'>ON</font>":"OFF"; } } } catch(err){ var txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; //alert(txt); } } iProcess++; if(iProcess>2) iProcess=0; } function byteCount(bits){ return parseInt((parseInt(bits)+7)/8); } var flashReady=false; function IsReady(){ flashReady=true; } var myTimeticks=0; function myTimer(){ if(flashReady==true){ Timer=window.clearInterval(Timer); thisMovie("msocket").ModbusSocketConnect(NetID, host, Module_Port); Timer=setInterval("timerupdate()", Scanrate); } else if(myTimeticks>10){ Timer=window.clearInterval(Timer); } myTimeticks+=1; } function Init(){ iProcess=0; IsSent=0; Timeout=0; host=location.hostname; if(flashReady==false){ Timer=setInterval("myTimer()", 100); return; } thisMovie("msocket").ModbusSocketConnect(NetID, host, Module_Port); Timer=setInterval("timerupdate()", Scanrate); } var Recon_Timeticks; function timerupdate(){ var tmp_comm=document.getElementById("communication"); var tmp_timeout=document.getElementById("timeout"); var tmp_comm_status=document.getElementById("tab_comm_status"); if(thisMovie("msocket").ModbusSocketStatus()==1){ tmp_comm_status.style.backgroundColor="#EEEEEE"; tmp_comm.innerHTML="Good"; } else{ tmp_comm_status.style.backgroundColor="#FF1A1A"; tmp_comm.innerHTML="Failed"; tmp_timeout.innerHTML=""; Recon_Timeticks+=1; if((Scanrate*Recon_Timeticks)>20000){ if(thisMovie("msocket").ModbusSocketStatus()==1) thisMovie("msocket").ModbusSocketClose(); thisMovie("msocket").ModbusSocketConnect(NetID, host, Module_Port); Recon_Timeticks=0; } IsSent=0; } if(IsSent==1){ if(thisMovie("msocket").IsRead()==1){ tmp_timeout.innerHTML=""; setData(thisMovie("msocket").receiveFromActionScript()); } else{ Timeout++; if(Timeout>1){ tmp_timeout.innerHTML="- Timeout -"; Recon_Timeticks=0; } else return; } IsSent=0; Timeout=0; } if(IsSent==0){ switch(iProcess){ case 0: sendToActionScript(4, 0, AICh, 0); break; case 1: sendToActionScript(4, 236, (32+AICh), 0); break; case 2: sendToActionScript(2, 224, (32+AICh), 0); break; } IsSent=1; } } function ShowStrainGauge(){ var str=(DO[631]>0?"Engineering":"Hex"); document.write("<tr bgcolor='#C0C0C0'>"); document.write("<td width='25%'>"+str+" Format</td>"); document.write("<td width='25%'>Floating Format</td></tr>"); for(var i=0; i<AICh; i++){ document.write("<tr><td width='25%'>AI"+i+"</td>"); document.write("<td width='25%'>"+(30000+i)+"</td>"); document.write("<td width='25%'><b><div id='AI"+i+"'>0000</div></b></td>"); document.write("<td width='25%'><b><div id='AI_Floating"+i+"'>0000</div></b></td></tr>"); } } function ShowAILatchedTable(){ var str=(DO[631]>0?"Engineering":"Hex"); document.write("<tr bgcolor='#C0C0C0'>"); document.write("<td width='16%'>"+str+" Format</td>"); document.write("<td width='16%'>Floating Format</td>"); document.write("<td width='16%'>"+str+" Format</td>"); document.write("<td width='16%'>Floating Format</td></tr>"); for(var i=0; i<AICh; i++){ document.write("<tr><td width='10%'>AI"+i+"</td>"); document.write("<td width='13%'>"+(30236+i)+"</td>"); document.write("<td width='16%'><b><div id='Lahch_High_"+i+"'>0000</div></b></td>"); document.write("<td width='16%'><b><div id='Lahch_High_Float_"+i+"'>0000</div></b></td>"); document.write("<td width='13%'>"+(30268+i)+"</td>"); document.write("<td width='16%'><b><div id='Lahch_Low_"+i+"'>0000</div></b></td>"); document.write("<td width='16%'><b><div id='Lahch_Low_Float_"+i+"'>0000</div></b></td></tr>"); } } function ShowAIAlarmTable(){ for(var i=0; i<AICh; i++){ document.write("<tr><td width='10%'>AI"+i+"</td>"); document.write("<td width='15%'>"+PrintModAddr(10224+i)+"</td>"); document.write("<td width='15%'><b><div id='Alarm_High_Value_"+i+"'>0</div></b></td>"); document.getElementById("Alarm_High_Value_"+i).innerHTML=Dec2Float_AI(AAO[296][i], i); document.write("<td width='15%'><b><span id='Alarm_High_"+i+"'>-</span></b> <input id='BtnClearH"+i+"' type='button' value='Clear' onclick='Clear_onclick("+(764+i)+")' /></td>"); document.write("<td width='15%'>"+PrintModAddr(10256+i)+"</td>"); document.write("<td width='15%'><b><div id='Alarm_Low_Value_"+i+"'>0</div></b></td>"); document.getElementById("Alarm_Low_Value_"+i).innerHTML=Dec2Float_AI(AAO[328][i], i); document.write("<td width='15%'><b><span id='Alarm_Low_"+i+"'>-</span></b> <input id='BtnClearL"+i+"' type='button' value='Clear' onclick='Clear_onclick("+(796+i)+")' /></td></tr>"); } } function Clear_onclick(BtnName){ sendToActionScript(5, BtnName, 1, 1); IsSent=1; } function ClearLatch_onclick(Latched_Type){ var DO_Address=(Latched_Type==0?634:635); sendToActionScript(5, DO_Address, 1, 1); IsSent=1; } </script> </head> <body onload="Init()"> <script type="text/javascript"> var hasProductInstall=DetectFlashVer(6, 0, 65); var hasRequestedVersion=DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision); if ( hasProductInstall && !hasRequestedVersion ) { var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn"; var MMredirectURL = window.location; document.title = document.title.slice(0, 47) + " - Flash Player Installation"; var MMdoctitle = document.title; AC_FL_RunContent( "src", "Install", "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"", "width", "100%", "height", "100%", "align", "middle", "id", "msocket", "quality", "high", "bgcolor", "#869ca7", "name", "msocket", "allowScriptAccess","always", "type", "application/x-shockwave-flash", "pluginspage", "http://www.adobe.com/go/getflashplayer" ); } else if (hasRequestedVersion) { AC_FL_RunContent( "src", "msocket", "width", "1", "height", "1", "align", "middle", "id", "msocket", "quality", "high", "bgcolor", "#869ca7", "name", "msocket", "allowScriptAccess","always", "type", "application/x-shockwave-flash", "pluginspage", "http://www.adobe.com/go/getflashplayer" ); } else { // flash is too old or we can't detect the plugin var alternateContent = 'Alternate HTML content should be placed here. ' + 'This content requires the Adobe Flash Player. ' + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>'; document.write(alternateContent); // insert non-flash content } </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="msocket" width="1" height="1" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> <param name="movie" value="msocket.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#869ca7" /> <param name="allowScriptAccess" value="always" /> <embed src="msocket.swf" quality="high" bgcolor="#869ca7" width="1px" height="1px" name="msocket" align="middle" play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"> </embed> </object> </noscript> <div align="center"> <br /> <table border="1" bordercolor="#808080"> <caption>Analog Input</caption> <tr bgcolor="#C0C0C0"> <td width="25%" rowspan="2">No</td> <td width="25%" rowspan="2">Register</td> <td width="50%" colspan="2">Value</td> </tr> <script type="text/javascript"> ShowStrainGauge(); </script> </table> <br /> <table border="1" bordercolor="#808080"> <caption>High/Low Latched Value for Analog Inputs</caption> <tr bgcolor="#C0C0C0"> <td width="10%" rowspan="3">No</td> <td width="45%" colspan="3">Latched High</td> <td width="45%" colspan="3">Latched Low</td> </tr> <tr bgcolor="#C0C0C0"> <td width="13%" rowspan="2">Register</td> <td width="32%" colspan="2">Value</td> <td width="13%" rowspan="2">Register</td> <td width="32%" colspan="2">Value</td> </tr> <script type="text/javascript"> ShowAILatchedTable(); </script> </table> <table> <tr height="20" bgcolor="#D0D0D0"> <td width="10%"></td> <td width="45%" valign="middle" align="right"><input id="BtnClearLatchH" type="button" value="Clear AI Latched" onclick="ClearLatch_onclick(0)" class="Clr_Button" /> </td> <td width="45%" valign="middle" align="right"><input id="BtnClearLatchL" type="button" value="Clear AI Latched" onclick="ClearLatch_onclick(1)" class="Clr_Button" /> </td> </tr> </table> <br /> <table border="1" bordercolor="#808080"> <caption>High/Low Alarm Status for Analog Inputs</caption> <tr bgcolor="#C0C0C0"> <td width="10%" rowspan="2">No</td> <td width="45%" colspan="3">High Alarm</td> <td width="45%" colspan="3">Low Alarm</td> </tr> <tr bgcolor="#C0C0C0"> <td width="15%">Register</td> <td width="15%">Value</td> <td width="15%">Status</td> <td width="15%">Register</td> <td width="15%">Value</td> <td width="15%">Status</td> </tr> <script type="text/javascript"> ShowAIAlarmTable(); </script> </table> <br /> <table border="0"> <tr id="tab_comm_status"> <td width="33%" align="right">Communication Status: </td> <td width="33%"><div id="communication"></div></td> <td width="34%"><font color="#666666"><div id="timeout"></div></font></td> </tr> </table> </div> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy