How to use the serial port in visual basic

Written by jackson lewis
  • Share
  • Tweet
  • Share
  • Email

Visual Basic is an event-driven programming language produced by Microsoft. The original programming language and integrated development environment was designed to support the COM programming model. The current version of Visual Basic is fully integrated into the Microsoft .NET development environment. Visual Basic is also cable of programming computer serial ports if you have a need to access or modify computer peripheries with your application through using the MSComm control that is incorporated into Visual Basic.

Skill level:
Moderate

Other People Are Reading

Things you need

  • Microsoft Visual Studio .NET Integrated Development Environment

Show MoreHide

Instructions

  1. 1

    Open Microsoft Visual Studio and select "File->New->Project" from the primary file menu. Then, choose "Project Types->Visual Basic Projects" and select the "Console Application" under the templates menu.

  2. 2

    Right click the project icon and select the "Add Reference" menu option. Then, choose the "Com" menu tab and select "Microsoft Comm Control 6.0" that is listed under "Component Name". Choose "Select" followed by the "OK" button.

  3. 3

    Double-click the program module visible in the Visual Basic IDE. This will open the programming window.

  4. 4

    Input the following programming code to initialise the serial port data structures that will be used to manipulate the serial port once opened: Dim MSComm1 As MSComm MSComm1 = New MSComm Dim Buffer As String MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" MSComm1.InputLen = 0

  5. 5

    Open the serial port by including the following programming code after the last line of code entered in step 4: MSComm1.PortOpen = True MSComm1.InputMode() = InputModeConstants.comInputModeText MSComm1.InBufferCount() = 0 MSComm1.Output = "ATV1Q0" & Chr(13)

  6. 6

    Manipulate the serial port information and then close the serial port by entering the following code at the bottom of the Visual Basic programming module: Do Buffer = Buffer & MSComm1.Input Loop Until InStr(Buffer, "OK" & vbCrLf) MSComm1.PortOpen = False Console.WriteLine("Close the serial port.") EndModule

  7. 7

    Select the "CTRL+F5" keys simultaneously to build and run the project.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.