_Ronin_ 2018-11-13 07:15
浏览 480

求大神指教,程序不报错,运行的时候不能识别串口

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   



JavaScript串口测试

<br> &lt;!--<br> function MSComm1_OnComm()<br><br> {<br><br> switch(MSComm1.CommEvent)<br> {<br> case 1:{ window.alert(&quot;Send OK!&quot;); break;} //发送事件<br> case 2: { Receive();break;} //接收事件<br> default: alert(&quot;Event Raised!&quot;+MSComm1.CommEvent);;<br> }<br><br> }<br><br> //--&gt; </p> <p>

<br> &lt;!--<br> // MSComm1控件每遇到 OnComm 事件就调用 MSComm1_OnComm()函数<br> MSComm1_OnComm();<br> //--&gt; <br>

<br> &lt;!-- </p> <p>String.prototype.Blength = function(){<br><br> var arr = this.match(/[^\x00-\xff]/ig);<br><br> return arr == null ? this.length : this.length + arr.length;<br><br> } </p> <p>function OperatePort()<br> {<br> if(MSComm1.PortOpen==true)<br> {<br> try{MSComm1.PortOpen=false;<br> document.getElementById(&quot;OperateButton&quot;).value=&quot;打开串口&quot;;<br> }catch(ex)<br> {alert(ex.message);}<br><br> }<br> else{<br> try{ MSComm1.PortOpen=true;<br> document.getElementById(&quot;OperateButton&quot;).value=&quot;关闭串口&quot;;<br> }catch(ex)<br> {alert(ex.message);}<br><br> }<br> }</p> <p>function ConfigPort()<br> {<br> alert(MSComm1.PortOpen);<br> if(MSComm1.PortOpen==false)<br> {<br><br> try{<br> MSComm1.CommPort=document.getElementById(&quot;ComName&quot;).value;<br> MSComm1.Settings=document.getElementById(&quot;BaudRate&quot;).value.toString()+<br> &quot;,&quot;+document.getElementById(&quot;CheckBit&quot;).value.toString()+<br> &quot;,&quot;+document.getElementById(&quot;DataBits&quot;).value.toString()+<br> &quot;,&quot;+document.getElementById(&quot;StopBits&quot;).value.toString();<br><br> MSComm1.OutBufferCount =0; //清空发送缓冲区<br> MSComm1.InBufferCount = 0; //滑空接收缓冲区<br><br> alert(&quot;已配置串口COM&quot;+MSComm1.CommPort+&quot;\n 参数:&quot;+MSComm1.Settings);<br><br> }catch(ex){alert(ex.message);}<br> }<br> else{ alert(&quot;请先关闭串口后再设置!&quot;);}<br> }</p> <p>function stringToHex(str,n){<br>     var val=&quot;&quot;;<br>     for(var i = 0; i &lt; str.length; i++){<br>       if(val == &quot;&quot;)<br>         val = str.charCodeAt(i).toString(16);<br>       else<br>         val += &quot;,&quot; + str.charCodeAt(i).toString(16);<br>     }<br>     return val;<br>   }</p> <p>function Send()<br> {<br> //alert(document.getElementById(&quot;txtSend&quot;).value);<br> var orgstr=document.getElementById(&quot;txtSend&quot;).value;<br><br> var newstr=&quot;&quot;;<br> var hexflag=document.getElementById(&quot;isSendHex&quot;).checked;<br> if(hexflag&amp;&amp;orgstr!=&quot;&quot;)<br> {<br> if(orgstr.substr(0,2)==&quot;0x&quot;||orgstr.substr(0,2)==&quot;0X&quot;) orgstr=orgstr.substring(2,orgstr.length);<br> if(orgstr.length%2!=0) orgstr=&quot;0&quot;+orgstr;<br> //alert(stringToHex(orgstr,16));<br> if((newstr=stringToHex(orgstr,16))==&quot;&quot;) {alert(&quot;错误的16进制数&quot;);return false;}<br> }<br> try{<br> MSComm1.Output=hexflag?newstr:orgstr;<br><br> }catch(ex)<br><br> {alert(ex.message);}<br> }</p> <p>function Receive()<br> {<br><br> //alert(&quot;InBufferCount::&quot;+MSComm1.InBufferCount);<br> document.getElementById(&quot;txtReceive&quot;).value += MSComm1.Input;<br><br> //alert(&quot;InBufferCount::&quot;+MSComm1.InBufferCount);<br><br> }</p> <p>function ClearReceived()<br> {<br> document.getElementById(&quot;txtReceive&quot;).innerText=&quot;&quot;;<br> } </p> <p>


配置串口

串口号: COM1COM2COM3COM4
波特率: 960057600115200
校验位: 无NONE奇ODD偶EVEN
数据位:
停止位:

发送区域

16进制
接收区域

16进制

CLASSID="CLSID:648A5600-2C6E-101B-82B6-000000000014"
CODEBASE="MSCOMM32.OCX">








  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名