Important alert: (current site time 4/23/2014 11:02:45 PM EDT)
 

VB icon

Serial Communication ASP

Email
Submitted on: 8/15/2002 1:56:21 AM
By: Muhamad Kamal  
Level: Advanced
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 10312
author picture
(About the author)
 
     To communicate with any device connected to com port via an activeX provided by Microsoft called MSComm (MSCOMM32.OCX).

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Serial Communication ASP
' Description:To communicate with any device connected to com port via an activeX provided by Microsoft called MSComm (MSCOMM32.OCX).
' By: Muhamad Kamal
'
' Inputs:I've tried using my proximity card reader connected to COM1 and was able to read data from the card once it touch the reader.
'
' Returns:any string feeded in by the device through COM port.
'
' Assumes:it needs to be beautify coz I only spent about 2-3 hours to come out with this piece of code.
'
' Side Effects:not tested
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7763&lngWId=4'for details.'**************************************

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE="VBScript">
'Sub Window_OnLoad()
'	MSComm1.PortOpen =True
'end sub
Sub OpenPort()
	if Not MSComm1.PortOpen Then 
		MSComm1.PortOpen =True
	else
		msgbox "Port already opened !", vbOKOnly, "Warning"
	end if
end sub
Sub ClosePort()
	if MSComm1.PortOpen Then 
		MSComm1.PortOpen = False
	else
		msgbox "Port already closed !", vbOKOnly, "Warning"
	end if
end sub
</SCRIPT>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function MSComm1_OnComm() {
	var fldWeight = frmView.txtWeight
	var strInput
	strInput = MSComm1.Input;
	window.alert (strInput); 
	fldWeight.Value == strInput;
	fldWeight.focus();
	return false;
	
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE=javascript FOR=MSComm1 EVENT=OnComm>
<!--
	MSComm1_OnComm()
//-->
</SCRIPT>
</HEAD>
<BODY>
<OBJECT classid=clsid:648A5600-2C6E-101B-82B6-000000000014 id=MSComm1 
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 OnClick="OpenPort()" value="Open Port">Open COM Port</BUTTON>
<BUTTON onclick="ClosePort()" value="Close Port">Close COM Port</BUTTON>
</P>
<P>
</P>
</FORM>
</BODY>
</HTML>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/23/2003 4:46:15 AMhamidsk

i am trying to run this code but an error is occured.

(If this comment was disrespectful, please report it.)

 
1/23/2003 4:48:42 AMhamidsk

I am trying to run this code but an error occures Error is
"Objectt does not support this property of method Mscomm1.openport
(If this comment was disrespectful, please report it.)

 
1/23/2003 4:59:41 AMhamidsk

I am trying to run this code but an error occures
"Obdeject does not support this property or method Mscomm1.PortOpen"
(If this comment was disrespectful, please report it.)

 
1/23/2003 11:28:37 AMMuhamad Kamal

well, first of all, u need to have the MSCOMM32.OCX (and it's development license if any). i got mine from the VB6 installation. then for the OBJECT tag, make sure that the classid exists.

if u r using visual studio, u can add the active x object (MSCOMM32.OCX) from the toolbar panel
(If this comment was disrespectful, please report it.)

 
2/26/2004 3:12:08 AM

I get the error message - object doesn't support this property or method: MSComm1.PortOpen
I installed MSCOMM32.OCX in system32 directory and registered it using regsvr32.
Any ideas?
(If this comment was disrespectful, please report it.)

 
8/2/2004 11:50:20 AM

same here...exact same error.

who gave this guy an excellent rating anyway?
(If this comment was disrespectful, please report it.)

 
4/16/2007 2:20:45 AMSunny

Can anyone tell me how to use MSComm with VBScript. I am able to retrieve data from microcontroller serially using a code in Visual Basic. I do have MSCOMM32.OCX in my system32 folder as well as registered using regsvr. Has anyone been able to send and receive data using MSCOMM in VBScript?
(If this comment was disrespectful, please report it.)

 
6/29/2007 1:41:40 PMhoneypath

well done mr kamal, it work well.....
job job
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.