Visual Basic interfacing RS-232,MODERM dial-up phone and I2C serial communications. Pc interface hardware electronic and control input output hardware by tcp/ip with winsock,api. Serial-port-vb.doc 1 2/1/2010 Serial Port Using Visual Basic.NET and Windows Introduction The serial (COM) port is one of the simplest ways to communicate between a PC and a. This topic describes how to use My.Computer.Ports to send strings to the computer's serial ports in Visual Basic. The serial port should.
-->This topic describes how to use My.Computer.Ports
to send strings to the computer's serial ports in Visual Basic.
Example
This example sends a string to the COM1 serial port. You may need to use a different serial port on your computer.
Use the My.Computer.Ports.OpenSerialPort
method to obtain a reference to the port. For more information, see OpenSerialPort.
The Using
block allows the application to close the serial port even if it generates an exception. All code that manipulates the serial port should appear within this block or within a Try...Catch...Finally
block.
Visual Basic Serial Port Programming
The WriteLine method sends the data to the serial port.
Compiling the Code
Visual Basic Terminal Program
- This example assumes the computer is using
COM1
.
Visual Studio Serial Port Example
Robust Programming
Visual Basic Code For Beginners
This example assumes the computer is using COM1
; for more flexibility, the code should allow the user to select the desired serial port from a list of available ports. For more information, see How to: Show Available Serial Ports.
Programming In Visual Basic 2010
This example uses a Using
block to make sure that the application closes the port even if it throws an exception. For more information, see Using Statement.