My ChipCenter Knowledge Center Guides & Experts Product Reviews Ask Us Online Tools Circuit Cellar Resources Webcasts Careers


Data Sheets App Notes Ask Us
Search Type:
Search for:






Email this Article   |  Printer Friendly Page
EE Expert Robert Ashby
SpacerEmbedded Engineering

Click Here for the Embedded Engineering ArchiveClick Here for the Embedded Engineering Main EE Expert PageClick Here for the Guides and Experts Main Page

How to Communicate Via a COM Port with Web Pages
by Robert Ashby

I was asked some time ago by a reader to give a more detailed example of how to use COM ports in web pages. He had read my article on how to communicate via a COM port with web pages. His task was the testing of modems to see whether they could send and receive information and how to log the data response.

Javascript and ActiveX objects are easy to add to your web page and don’t require any tools fancier than a simple text editor. However, the use of these tools can be greatly facilitated with additional tools such as the Microsoft Development Environment that comes with Visual Studio. Visual J++ is another great tool. If you are cheap (like me) then you might just try your hand first with ‘Notepad’ or any other favorite text editor.

Not an authority on modems, I created a small page that would query the modem attached to the COM port for some simple information and log that information to a file. Copy this file onto your computer to try it out.

WARNING this page creates the file C:\testfile.txt on your hard drive. In the unlikely event that you already have a file by this name on your hard drive, it will be overwritten. Please either back up that file or make sure you edit this provided file so you don’t overwrite your information.

I have only tested this page with computers running Windows 2000 and 98 and Internet Explorer 5.01. If the program isn’t working for you, check to make sure that you have the MSComm ActiveX object registered on your computer. If it’s still not working and you’re ready to pull your hair out, drop me an e-mail and I’ll try to help.

The property about the MSComm ActiveX object that seems to trip me up most often is the Input Mode property. If it is set to 0 (text) then the information is retrieved from the port as a string. If it is set to 1 (binary data) then the information is structured as a byte array. If you are just dealing with ASCII characters and don’t care much about possible appending returns and line feeds, then leave it at 0.

I’ve left the file simple so you don’t have to wade through a bunch of bells and whistles to figure out what is going on.

When the file is first loaded you will probably get a prompt like this:

figure 1

Select yes or the web page won’t work. You are getting this prompt because the ActiveX MSComm object is embedded in the page. When the file opens, it will create the file "C:\testfile.txt" on your hard-drive. Any text that is received from the COM Port while this page is open and the file has not been closed will be recorded into this file. The file object is set up to overwrite any existing files.

Here is a quick shot of what the page looks like:

figure 2

The COM Port Number should be set to the port that your modem resides on. Or if you are using this file to check your own design, then set it to the appropriate port number. If you are using ports greater than 4, then you can edit that object on lines 71 — 74 to match the desired port number.

Once you have opened the port you can type a line in the left-hand text area. This is the SendWindow. When you press the SendButton, the text in the SendWindow is sent to your respective COM Port. I have set the COM Port up to be 9600 baud, 8 bits of data, 1 stop bit, no parity.

Any text that is received from the COM Port is echoed in the right-hand text area (ReceiveWindow). This information is also written to the file that was opened when the page was first initialized. If you want to stop recording to the file, you can press the Close File button, which will close the file and prevent any further writing to that file. If you refresh the page, then the file is reinitialized and the old information is gone. You can edit the file as an ordinary text document.

If you are sending an AT type command to your modem be sure to follow the command with a return so that the command is recognized by the modem. If you want to send several commands in series, you will most likely need to add some timing to your web page to allow the modem time to respond to your first command before proceeding to any additional commands. Here is an example of what my computer looks like after sending the command ATI5:

figure 3

The modem’s response has been logged to a file on my hard drive. Pretty cool! There’s not that much to it, but it can be a very powerful tool.

E-mail me if you would like some more in-depth articles in this area.

Embedded Engineering Archive

Guides and Experts   Analog Avenue   EDA Tools   PLD   DSP   EDA   Embedded Systems   Power   Test


Email this Article   |  Printer Friendly Page

Copyright ©2001 eChips
About ChipCenter  Contact Us  Privacy Statement   Advertising Information