1、在本地安裝MSCOMMSetup原始.exe, 目的是為了在本地注冊MSCOMM32.OCX控件。
2、注冊好了之後
先做個測試JSP,代碼如下:
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
var CalendarWebControl = new atCalendarControl();
function prints(){
alert(printport);
}
function init(){
//document.all.printport.CommPort = "3";
// var object1=document.getElementById("printport");
// object1.PortOpen = true;
document.all.printport.PortOpen=true;
}
function doPrint(printmsg){
document.all.printport.Output = printmsg;
}
function pageEnd(){
document.all.printport.PortOpen = false;
}
</script>
</head>
<body onload='init();' onunload='pageEnd();'>
<p><object id="printport" classid="clsid:648A5600-2C6E-101B-82B6-000000000014" codebase="MCSCOMM32.cab" >
<param name="CommPort" value="3">
<param name="DTREnable" value="1">
<param name="Handshaking" value="0">
<param name="InBufferSize" value="1024">
<param name="InputLen" value="0">
<param name="NullDiscard" value="0">
<param name="OutBufferSize" value="512">
<param name="ParityReplace" value="63">
<param name="RThreshold" value="0">
<param name="RTSEnable" value="0">
<param name="BaudRate" value="9600">
<param name="ParitySetting" value="0">
<param name="DataBits" value="8">
<param name="StopBits" value="0">
<param name="SThreshold" value="0">
<param name="EOFEnable" value="0">
<param name="InputMode" value="0">
</object></p>
<p><input type="button" value="Print" name="B1" onclick=prints();'></p>
</body >
</html>
當JS彈框為3,那麼說明控件加載成功,程序已經可以向端口發數據了