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:
Other People Are Reading
Things you need
- Microsoft Visual Studio .NET Integrated Development Environment
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.
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.
Double-click the program module visible in the Visual Basic IDE. This will open the programming window.
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
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)
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
Select the "CTRL+F5" keys simultaneously to build and run the project.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for