使用javascript调用mscomm传递数据时由于大于127的数据都会被拆分为两字节数据所以想试试通过二进制的方式传递请问怎么传递二进制数组数据呢谢谢各位

解决方案 »

  1.   


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>JS串口操作测试</title>
    <script language="javascript">
    function OpenPort(aid,type){
    if(MSComm1.PortOpen=="undefiend"){
    alert("您的浏览器不支持ActiveX控件,请降低您的浏览器安全级别。");
    }else if(MSComm1.PortOpen==false){
    MSComm1.PortOpen=true;
    //ajaxSubmit(aid,type);
    }else{
    //ajaxSubmit(aid,type);
    }
    //即时公告
    //var show="0x7e,0x43,0x00,0x61,0x06,0x57,0x53,0x48,0x4f,0x57,0x01,0x01,0x00,0x01,0x43,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x02,0x00,0x00,0x0f,0x01,0x00,0x00,0x01,0x00,0x06,0x02,0x01,0x00,0x00,0x00,0x00,0x37,0xd4,0xc2,0xb5,0xd7,0xc7,0xeb,0xd0,0xb4,0xba,0xc3,0xb9,0xa4,0xd7,0xf7,0xd7,0xdc,0xbd,0xe1,0xa3,0xa8,0xbd,0xd8,0xd6,0xb9,0xb5,0xbd,0x32,0x35,0xba,0xc5,0xa3,0xa9,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xcf,0xc2,0xb0,0xe0,0xc7,0xeb,0xd6,0xee,0xce,0xbb,0xcb,0xa2,0xbf,0xa8,0xa3,0xa1,0x12,0xa6,0x7e";
    //var s="126 67 0 46 6 119 83 72 79 87 1 1 0 1 67 112 0 0 0 0 0 0 0 1 0 0 1 0 0 15 1 0 0 1 0 5 2 1 0 0 0 0 4 116 101 115 116 49 -119 126";
    //var dall="0x7e,0x43,0x00,0x09,0x06,0x53,0x44,0x41,0x4c,0x4c,0x60,0x49,0x7e"
    var dall="7e 43 00 09 06 53 44 41 4c 4c 60 49 7e"
    //var dall="1111110 1000011 0 1001 110 1010011 1000100 1000001 1001100 1001100 1100000 1001001 1111110";
    var value="";
    var arr=dall.split(" ");
    for(var i=0;i<arr.length;i++){
    value+=String.fromCharCode(arr[i]);
    //value+=parseInt(arr[i],10).toString(2);
    }
    //alert(value);
    MSComm1.Output=escape(value);
    }
    </script>
    <script ID="clientEventHandlersJS"   language="javascript">
    function MSComm1_OnComm(){
    switch(MSComm1.CommEvent){
             case 1:{ break;}  //发送事件
             case 2: { Receive();break;} //接收事件
             default: alert("Event Raised!"+MSComm1.CommEvent);;
    }
    }
    function Receive(){
    MSComm1.InputLen=13;
    var v=MSComm1.Input;
    var value="";
    for(var i=0;i<v.length;i++){
    value+=v.charCodeAt(i).toString(16)+" ";
    }
    alert("接收到的数据:"+v.length+"___"+value);
       }
    </script>
    <script   language="javascript"   FOR="MSComm1"   EVENT="OnComm"> 
        // MSComm1控件每遇到 OnComm 事件就调用 MSComm1_OnComm()函数
    MSComm1_OnComm()
    </script>
    </head>
      
    <body><input type="button" onclick="OpenPort(1,1)" value="串口数据发送测试"/>
    <OBJECT CLASSID="clsid:648A5600-2C6E-101B-82B6-000000000014" id=MSComm1 codebase="MSCOMM32.OCX" type="application/x-oleobject" style="LEFT: 54px; TOP: 14px;display:none;" >  
    <PARAM NAME="CommPort" VALUE="4">
    <PARAM NAME="DTREnable" VALUE="1">
    <PARAM NAME="Handshaking" VALUE="0">
    <PARAM NAME="InBufferSize" VALUE="1024">
    <PARAM NAME="InputLen" VALUE="15">
    <PARAM NAME="NullDiscard" VALUE="0">
    <PARAM NAME="OutBufferSize" VALUE="512">
    <PARAM NAME="ParityReplace" VALUE="-1">
    <PARAM NAME="RThreshold" VALUE="1">
    <PARAM NAME="RTSEnable" VALUE="1">
    <PARAM NAME="SThreshold" VALUE="0">
    <PARAM NAME="EOFEnable" VALUE="0">
    <PARAM NAME="InputMode" VALUE="0">
    <PARAM NAME="DataBits" VALUE="8">
    <PARAM NAME="StopBits" VALUE="1">
    <PARAM NAME="BaudRate" VALUE="9600">
    <PARAM NAME="Settings" VALUE="9600,N,8,1">
    </OBJECT></body>
    </html>
      

  2.   

    代码中dall是可以传送的  但是show就不能 因为show中有大于127的。
    不知道该怎么解决了