advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the Code for this Article
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.4/5 | Rate this item | 20 users have rated this item.
Email this articleEmail this article
 
Programming Serial Ports Using Visual Basic 2005
While serial port programming was absent in .NET version 1.1, Visual Basic developers who grew accustomed to the MSCOMM control in VB6 will be glad to know that this functionality is supported again in .NET 2.0. Learn to use the SerialPort class to make two computers talk to one another or even to manipulate a mobile device from your computer using Bluetooth.  

advertisement
isual Basic programmers who do networking programming will no doubt be familiar with the MSCOMM control in VB6. For those of us who followed VB's progression to VB.NET, it was a big surprise to find that control missing in .NET 1.x. What we had instead was Platform Invoke (P/Invoke), which was the only way to access the unmanaged Win32 APIs from your managed application. Fortunately, the situation has been rectified: In .NET 2.0, the functionality of the MSCOMM control is restored in the form of the SerialPort control (located under the Components tab in the Toolbox).


In this article, I will show you how to use the SerialPort control in .NET 2.0 for your serial communication needs. In particular, I will build a chat application that allows two computers (connected using either a serial cable or a Bluetooth connection) to communicate. One interesting use of this chat application is in communicating with external serial devices. You will learn how to use the AT commands to programmatically control your mobile phones through a serial Bluetooth connection.

Hardware Needed
Unless you have two computers, you won't be able to test serial communications. However, you can use a null modem cable to connect two serial ports on the same computer to simulate two computers communicating over serial ports. But most computers today come with at most one serial port (and some notebooks do not even have one). One good solution is to use a USB-to-serial port adapter to convert an USB connection into a serial port. Hence, if you computer does not have any serial ports, you would need a pair of USB-to-serial port adapters, and a null modem cable (see Figure 1). Then, connect each USB-to-serial port adapters to a USB connection.


Figure 1. Accordingly: A USB-to-serial port adapter and a null modem cable will be needed unless you have two serial ports.
 
Figure 2. Portly: Locate the newly created serial ports and make note of their names; you'll need them later.

The USB-to-serial port adapter comes with its own drivers. After installing the drivers, right-click on My Computer on the Desktop and select Properties. In the System Properties window, click on the Hardware tab and click the Device Manager button. Expand the Ports (COM & LPT) item and locate the two newly added COM ports (see Figure 2).

On my computer, the two serial ports are COM28 and COM29. Write down the port names as you'll need these later.

  Next Page: Creating the Chat Application


Page 1: IntroductionPage 3: Testing the Application
Page 2: Creating the Chat Application 
Untitled
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES