- UID
- 799481
|
利用ASP操作串口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> ASP读取串口数据 </title>
< name="generator" content="editplus" />
< name="author" content="" />
< name="keywords" content="" />
< name="deion" content="" />
< language="VB">
'//页面载入时自动打开串口进行监听
'Sub Window_()
' MSComm1.PortOpen = True
'End Sub
'//打开串口进行监听
Sub OpenPort()
if Not MSComm1.PortOpen Then
MSComm1.PortOpen = True
MsgBox "Port opened !", vbOKOnly, "Warning"
Else
MsgBox "Port already opened !", vbOKOnly, "Warning"
End if
End Sub
'//关闭串口
Sub ClosePort()
if MSComm1.PortOpen Then
MSComm1.PortOpen = False
MsgBox "Port closed !", vbOKOnly, "Warning"
Else
MsgBox "Port already closed !", vbOKOnly, "Warning"
End if
End Sub
</>
< ID="clientEventHandlersJS" language="java">
<!--
//串口事件驱动部分
MSComm1_OnComm(){
var fldWeight = frmView.txtWeight
var strInput
strInput = MSComm1.Input;
alert(strInput);
fldWeight.value == strInput;
fldWeight.focus();
return false;
}
//-->
</>
< language="java" FOR="MSComm1" EVENT="OnComm">
<!--
//串口事件驱动关联
MSComm1_OnComm()
//-->
</>
</head>
<body>
<object classid="clsid:648A5600-2C6E-101B-82B6-000000000014" id="MSComm1" codebase="MSCOMM32.OCX" type="application/x-oleobject" style="left:54px;top:14px">
<param name="_ExtentX" value="1005">
<param name="_ExtentY" value="1005">
<param name="_Version" value="393216">
<param name="CommPort" value="1">
<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="14">
<param name="RTSEnable" value="0">
<param name="BaudRate" value="9600">
<param name="ParitySetting" value="0">
<param name="DataBits" value="7">
<param name="StopBits" value="0">
<param name="SThreshold" value="0">
<param name="EOFEnable" value="-1">
<param name="InputMode" value="0"></object>
<form action="" method="post" id="frmView" name="frmView">
<p>
<input id="txtWeight" name="txtWeight" style="left:50px;top:17px"></p>
<p> </p>
<p>
<button ="OpenPort()" value="Open Port">Open COM Port</button>
<button ="ClosePort()" value="Close Port">Close COM Port</button>
</p>
<p>
</p>
</form>
</body>
</html>
此文从网络整理而来,作者不详。
使用前请确保计算机中存在控件mscomm32.ocx
控件注册方法:
利用用Windows下的注册工具regsvr32注册该OCX控件,例如:
Regsvr32 … system目录\Mscomm32.ocx .
为了能正确使用该控件,需要修改注册表的信息,在注册表的在HKEY_CLASSES_ROOT\Licenses下建一主键:
4250E830-6AC2-11cf-8ADB-00AA00C00905 |
|