serial terminal window, COM port selector, baud rate selector, transmit and receive fields

How to use Serial Port in VB 2010

12.6M Views
40
700
60
25
60
PCBWay

Hello friends, I hope you are doing well. In this tutorial, we will build a simple serial terminal in Visual Basic 2010. The application will detect the COM ports available on a Windows computer, open a selected port, transmit text, receive incoming data and close the connection cleanly.

This article keeps Visual Basic 2010 because that is the environment used in the original project and screenshots. According to the official Microsoft lifecycle record, Visual Studio 2010 reached the end of support in July 2020, so you should use a supported Visual Studio and .NET version for a new production application. However, the serial communication principles explained here still apply to maintenance work, laboratory computers and older engineering projects.

We will begin with the electrical and protocol basics, create the Windows Forms interface, write the complete VB code and then test the terminal with a loopback connection. I will also explain why received data cannot be written directly to a Windows Forms control from the serial event handler.

serial terminal window, COM port selector, baud rate selector, transmit and receive fields
Figure: The original terminal interface includes connection controls and separate areas for transmitting and receiving text.

What Is Serial Communication?

Serial communication transfers bits one after another over a communication channel. In a basic asynchronous UART link, one device transmits on its TX line and the other receives on its RX line. The devices normally share a ground reference. A full-duplex link uses separate TX and RX conductors, so both sides can transmit at the same time.

A COM port is the Windows name for a serial interface. A built-in RS-232 port, a USB-to-UART converter and some Bluetooth serial profiles can all appear as names such as COM3 or COM8. The name identifies the Windows port; it does not tell us the electrical voltage used by the attached hardware.

SettingMeaningValue used here
Baud rateNumber of symbols transmitted per second9600 baud by default
Data bitsPayload bits in each frame8
ParityOptional error-detection bitNone
Stop bitsMarks the end of a frame1
HandshakeHardware or software flow controlNone

The common notation 9600 8N1 therefore means 9600 baud, eight data bits, no parity and one stop bit. A normal 8N1 character contains one start bit, eight data bits and one stop bit, which gives ten transmitted bits per byte. The ideal maximum payload rate is:

Payload rate = 9600 bits/s / 10 bits per byte = 960 bytes/s

This is a theoretical value before application delays and protocol overhead. Both endpoints must use matching settings. A mismatch may produce unreadable characters, incomplete messages or no useful data.

Check the Electrical Interface Before Connecting Hardware

A microcontroller UART commonly uses 3.3 V or 5 V logic, while a traditional computer RS-232 connector uses inverted positive and negative voltage levels. Do not connect a microcontroller UART directly to a DB9 RS-232 port. Use a suitable level translator, such as a MAX232 circuit, or a USB-to-UART adapter with the correct logic voltage.

For a three-wire UART connection, connect the adapter TX to the device RX, adapter RX to device TX and the grounds together. Check the device documentation before joining grounds when either circuit is mains-powered or otherwise isolated. The software cannot correct an unsafe or incompatible electrical connection.

Controls Used in the Visual Basic Serial Terminal

Our application uses the System.IO.Ports.SerialPort class. Microsoft documents this class as the interface for synchronous and event-driven I/O through a serial port. We will place a SerialPort component on the form so Visual Studio creates and disposes the component with the form.

Create the following controls. The Name property is the identifier used in code, while the Text property is the caption shown to the user.

ControlName propertyText or purpose
FormfrmMainSerial Terminal
ComboBoxcmbPortAvailable COM ports
ComboBoxcmbBaudBaud-rate choices
ButtonbtnConnectConnect
ButtonbtnDisconnectDisconnect
TextBoxtxtTransmitText to transmit
ButtonbtnSendSend
RichTextBoxrtbReceivedReceived text
SerialPortSerialPort1Serial connection component

Step 1: Create a Windows Forms Project

  1. Open Microsoft Visual Basic 2010 Express or Visual Studio 2010.
  2. Select File, New Project.
  3. Select Windows Forms Application under Visual Basic.
  4. Name the project SerialPortInterface and select OK.
Visual Basic 2010 Express, Start Page window, New Project link, development environment
Figure: Begin the serial-terminal project from the Visual Basic 2010 Express Start Page.

The New Project dialog in your edition may look slightly different, but the application type must be a Visual Basic Windows Forms application.

New Project dialog, Windows Forms Application template, Visual Basic project, project name field
Figure: Select a Visual Basic Windows Forms application and give the serial-terminal project a name.

Visual Studio creates a blank form and the files required for the project. The form is the visual surface on which we will place the terminal controls.

blank Form1 designer, Windows Forms project, Solution Explorer panel, Properties window
Figure: The newly created project opens with an empty form ready for the terminal controls.

Step 2: Configure the Main Form

Select the form and open the Properties window. Change the (Name) property from Form1 to frmMain. Change its Text property to Serial Terminal. The name makes the form easy to identify in code, while the text appears in its title bar.

Windows Forms designer, form title properties, Toolbox controls, blank terminal layout
Figure: Configure the form properties before adding the port-selection and communication controls.

Step 3: Add Port and Baud-Rate Controls

Drag two ComboBox controls, two Button controls and two Label controls from the Toolbox to the form. Arrange them in a clear connection section.

COM port ComboBox, baud rate ComboBox, Connect button, Disconnect button
Figure: The connection area groups the port and baud-rate selectors with the connection buttons.
  • Name the first ComboBox cmbPort and label it COM Port.
  • Name the second ComboBox cmbBaud and label it Baud Rate.
  • Name the buttons btnConnect and btnDisconnect. Set their Text properties to Connect and Disconnect.
  • Set each ComboBox DropDownStyle to DropDownList if you want the user to select only a detected or predefined value.

Visual Basic identifiers are normally case-insensitive, but spelling still matters. Using the exact names in the table ensures that the event handlers and references in our code point to the intended controls.

Step 4: Add Transmit and Receive Controls

Add two GroupBox controls. Set their Text properties to Transmit Data and Received Data. Put a TextBox named txtTransmit and a Button named btnSend inside the transmit group. Set the button text to Send. Put a RichTextBox named rtbReceived inside the receive group.

serial terminal form designer, transmit text field, Send button, receive text area
Figure: The form now includes separate transmit and receive areas alongside the connection controls.

Finally, find SerialPort in the Components section of the Toolbox and drag it onto the form. It appears in the component tray below the designer because it has no visible user interface. Keep its name as SerialPort1. The code will set its communication properties before opening the port.

Step 5: Add the Visual Basic Code

Press F7 or right-click the form and select View Code. The code editor opens as shown below.

Visual Basic code editor, form class declaration, Load event handler, Solution Explorer
Figure: The form's code editor is where the serial-port event handlers are added.

Replace the form class code with the following example. Leave the designer-generated file unchanged. This version handles an empty port list, validates the baud rate, reports common connection errors, marshals received data to the user-interface thread and closes the port when the form exits.

Imports System.IO
Imports System.IO.Ports

Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles MyBase.Load
        cmbBaud.Items.AddRange(New Object() {"9600", "19200", "38400", "57600", "115200"})
        cmbBaud.SelectedIndex = 0

        RefreshPortList()
        SetConnectedState(False)
    End Sub

    Private Sub RefreshPortList()
        Dim ports() As String = SerialPort.GetPortNames()
        Array.Sort(ports)

        cmbPort.Items.Clear()
        cmbPort.Items.AddRange(ports)

        If cmbPort.Items.Count > 0 Then
            cmbPort.SelectedIndex = 0
        End If
    End Sub

    Private Sub btnConnect_Click(ByVal sender As System.Object,
                                 ByVal e As System.EventArgs) Handles btnConnect.Click
        If cmbPort.SelectedItem Is Nothing Then
            MessageBox.Show("No COM port is available. Connect the adapter and try again.")
            Return
        End If

        Dim selectedBaud As Integer
        If Not Integer.TryParse(cmbBaud.Text, selectedBaud) Then
            MessageBox.Show("Select a valid baud rate.")
            Return
        End If

        Try
            SerialPort1.PortName = cmbPort.Text
            SerialPort1.BaudRate = selectedBaud
            SerialPort1.DataBits = 8
            SerialPort1.Parity = Parity.None
            SerialPort1.StopBits = StopBits.One
            SerialPort1.Handshake = Handshake.None
            SerialPort1.Encoding = System.Text.Encoding.ASCII
            SerialPort1.ReadTimeout = 1000
            SerialPort1.WriteTimeout = 1000
            SerialPort1.Open()

            SetConnectedState(True)
        Catch ex As UnauthorizedAccessException
            MessageBox.Show("The port is already in use or access was denied.")
        Catch ex As IOException
            MessageBox.Show("Windows could not open the selected serial device.")
        Catch ex As ArgumentException
            MessageBox.Show("One or more serial-port settings are invalid.")
        Catch ex As InvalidOperationException
            MessageBox.Show("The serial port is already open.")
        End Try
    End Sub

    Private Sub btnDisconnect_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles btnDisconnect.Click
        CloseSerialPort()
    End Sub

    Private Sub btnSend_Click(ByVal sender As System.Object,
                              ByVal e As System.EventArgs) Handles btnSend.Click
        If Not SerialPort1.IsOpen Then
            MessageBox.Show("Connect to a COM port before sending data.")
            Return
        End If

        Try
            SerialPort1.Write(txtTransmit.Text)
        Catch ex As TimeoutException
            MessageBox.Show("The serial write operation timed out.")
        Catch ex As InvalidOperationException
            MessageBox.Show("The serial port is closed.")
            SetConnectedState(False)
        End Try
    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As Object,
                                         ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Try
            Dim incoming As String = SerialPort1.ReadExisting()
            If incoming.Length > 0 Then
                rtbReceived.BeginInvoke(New Action(Of String)(AddressOf AppendReceivedText), incoming)
            End If
        Catch ex As InvalidOperationException
            'The port may have been closed while the event was being processed.
        End Try
    End Sub

    Private Sub AppendReceivedText(ByVal text As String)
        rtbReceived.AppendText(text)
        rtbReceived.SelectionStart = rtbReceived.TextLength
        rtbReceived.ScrollToCaret()
    End Sub

    Private Sub SetConnectedState(ByVal connected As Boolean)
        btnConnect.Enabled = Not connected
        btnDisconnect.Enabled = connected
        btnSend.Enabled = connected
        cmbPort.Enabled = Not connected
        cmbBaud.Enabled = Not connected
    End Sub

    Private Sub CloseSerialPort()
        Try
            If SerialPort1.IsOpen Then
                SerialPort1.Close()
            End If
        Finally
            SetConnectedState(False)
        End Try
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As Object,
                                    ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing
        CloseSerialPort()
    End Sub

End Class

The completed code editor should resemble the original project view below.

Visual Basic serial code, Connect and Disconnect handlers, send operation, received data handler
Figure: Original serial-terminal source view; use the revised code in the tutorial for the current example.

How the Serial Port Code Works

Discovering COM Ports

SerialPort.GetPortNames() returns the serial port names known to Windows. The order is not guaranteed, so the example sorts the array before placing it in cmbPort. It also checks whether the list contains an item. This avoids the out-of-range error that occurs when code selects item zero on a computer with no detected serial port.

Opening the Connection

The Connect handler copies the selected port name and baud rate to SerialPort1, explicitly sets the remaining 8N1 parameters and calls Open(). A serial port is an exclusive resource in most normal desktop use. If another terminal, programmer or instance of this application already owns it, Windows may reject the request with an access error.

Once the port opens, the program disables the port settings. Changing PortName, BaudRate or related properties while the port is open can raise an exception, and it can also make the interface state misleading.

Sending Text

SerialPort1.Write(txtTransmit.Text) transmits the entered characters without automatically appending a line ending. If the receiving device expects a command terminated by carriage return and line feed, set SerialPort1.NewLine = vbCrLf and use SerialPort1.WriteLine(txtTransmit.Text). Choose the terminator required by your protocol rather than assuming every device uses the same one.

The example uses ASCII encoding because it is common in simple embedded command protocols. If you need characters outside ASCII, both endpoints must agree on an encoding and on how message boundaries are identified. Binary protocols should use byte arrays and explicit lengths rather than converting arbitrary bytes to text.

Receiving Data on the Correct Thread

The DataReceived event runs on a secondary thread. Windows Forms controls belong to the thread that created them, so writing directly to rtbReceived from that event can cause a cross-thread exception. Microsoft therefore requires the update to be marshalled to the form thread through Invoke or BeginInvoke.

Our event handler reads the characters currently available through ReadExisting() and passes the resulting string to AppendReceivedText with BeginInvoke. The helper then runs on the user-interface thread and safely appends the text. The event is not guaranteed to occur once for every complete message or every byte, so a real protocol must accumulate data until it finds a delimiter, fixed length or another complete-frame condition.

Step 6: Build and Run the Project

  1. Select Build, Build SerialPortInterface.
  2. Correct any compiler errors, paying close attention to control names.
  3. Press F5 to start the application under the debugger.
  4. Select the correct COM port and the same baud rate used by the attached device.
  5. Select Connect, enter a short test message and select Send.
Visual Studio Build menu, serial terminal designer, project build command, Windows Forms controls
Figure: Build the project after adding the controls and serial-port code.

The build command creates the executable as part of the project output. During development, you normally run the Debug build from a path similar to bin\Debug. A deployment package is a separate concern; copying only the executable may be insufficient if an application has additional files or framework requirements.

Test the Terminal with a Loopback

A loopback test is the simplest way to separate a PC software problem from a remote-device problem. On a compatible USB-to-UART adapter, disconnect external circuitry and join the adapter TX pin to its RX pin. Do not short a conventional RS-232 connector until you have identified the correct pins and interface type.

  1. Insert the adapter and note the COM port assigned by Windows Device Manager.
  2. Start the application and select that port.
  3. Select 9600 baud and connect.
  4. Enter a distinctive message such as Loopback 123.
  5. Select Send. The same text should appear in the received-data box.
serial terminal window, COM port selector, baud rate selector, transmit and receive fields
Figure: The original terminal interface includes connection controls and separate areas for transmitting and receiving text.

If the text returns correctly, Windows, the adapter, the COM-port settings and the main send/receive path are working together. Remove the loopback wire before connecting the target device.

Common Serial Port Problems

SymptomLikely causeWhat to check
No COM ports appearAdapter is disconnected or its driver is unavailableCheck Device Manager, reconnect the adapter, then restart or add a refresh-port button
Access denied when connectingAnother program has opened the portClose other terminals, debuggers and duplicate application instances
Unreadable charactersBaud rate, parity, data bits or stop bits do not matchSet both endpoints to the same complete frame format
Transmission works only one wayTX and RX wiring is incorrect or a common ground is missingCross TX with RX and verify the electrical interface
Received text arrives in piecesSerial data is a stream and event boundaries are not message boundariesBuffer data and parse it using the protocol delimiter or expected length
Device ignores a typed commandRequired line ending was not sentUse the documented terminator and WriteLine when appropriate
Cross-thread operation errorThe receive event updated a form control directlyUse Invoke or BeginInvoke to update the UI
Application remains connected after closingThe port was not closed during shutdownClose it in the form-closing event as shown above

Practical Review

We created a Visual Basic Windows Forms serial terminal that enumerates COM ports, configures an 8N1 link, transmits text and displays received data. The most important design detail is the separation between the serial receive thread and the user-interface thread. Once you understand that boundary, you can extend this project with timestamps, a clear button, hexadecimal display, file logging or a protocol parser.

Keep the protocol separate from the graphical interface as the project grows. For example, a line-oriented sensor can buffer characters until it receives a newline, while a binary device may use a header, length field, payload and checksum. A visible chunk in DataReceived should never be assumed to equal one complete application message.

Frequently Asked Questions

Can I use this code with Visual Studio 2022 or a newer release?

The same concepts apply, but the project target and package requirements may differ. For a new application, create a supported Visual Basic Windows Forms project and consult the current System.IO.Ports documentation. The screenshots and designer workflow in this tutorial specifically show Visual Studio 2010.

Why does my COM port number change?

Windows assigns COM-port names to detected devices and interfaces. Moving some USB adapters to another socket, reinstalling a driver or using a different adapter can produce a different number. Select the port shown for your device in Device Manager rather than hard-coding COM1.

Should I use Write or WriteLine?

Use Write when the protocol expects exactly the supplied characters or bytes. Use WriteLine when the receiver expects a line terminator, and set the NewLine property to the required sequence. The choice belongs to the device protocol.

Why does DataReceived return only part of a message?

A serial port delivers a byte stream. Operating-system buffering, device timing and event scheduling determine how many characters are available during a particular event. Store incoming data in a buffer and extract messages only after the protocol's completion condition is present.

Can this terminal receive binary data?

Yes, but ReadExisting() is intended for decoded text. For binary communication, read bytes, preserve their exact values and implement the framing rules defined by the device protocol. Avoid mixing text and binary reads without a clear boundary.

Do I need hardware flow control?

Not for the simple three-wire example. Some modems and high-throughput devices require RTS/CTS hardware control or XON/XOFF software control. Set the Handshake property to match the equipment documentation; enabling it on only one side can stop transmission.

Why should the port be closed when the form exits?

Closing releases the Windows handle and allows another program to use the device. It also reduces the chance that a late receive event will try to interact with controls while the form is being destroyed.

You now have a useful foundation for PC-to-microcontroller communication in Visual Basic. Test the software with a loopback first, match all serial settings at both ends and then add your device-specific commands one step at a time.


Comments

95

Join the conversation

Reply3

saim_lodhi89@hotmail.com
this is my id please send the code to my email id
i have subscribed to the newsletter really need this one
thanks in advance

Reply4

@kashif Thanks bro for appreciation and yups try it and let me know howz you find it.

@Seol This Invoke function is used actually to automatically called every time a data is received at the Serial Port. Its kind of an interrupt for the coming data.

@saim lodhi The code and the software has been sent bro, check your email id. and stay connected ... :))

2 replies
1 reply
1 reply
Reply7.1
Replying to adiono

Check the last line of Step4 ..... " Lastly and i think its the most important part of this tutorial, add a Serial Port Block into your forum. It will appear at the bottom. Don't change any of its parameters just leave it as it is."

I think you didn't add the serial port block in your project that's what causing problem and if you have added then make sure the name of your serial port block is SerialPort1 .... you can change it in the properties.

1 reply
Reply7.1.1
Replying to adiono

I also did same mistake. Now corrected it. But facing another problem... Com port sends data( led on usb converter blinked) but is not received on hyperterminal.. Also from other side if i send some data then vb application is not receiving data

1 reply
1 reply
Reply10

Hi,
my name is Laurentiu and just joined the site today. I am also interested to obtain the above code. Could you please sent it to me at: vj_lau@yahoo.com

Many thanks in advance !!!

1 reply
Reply12

I'm have a problem: When I start your program there are no ports in the pulldown. I have tried using the 'myPort = IO.Ports.SerialPort.GetPortNames()' before without getting any ports.
Could this be computer related?

3 replies
Reply12.1
Replying to adiono

Before running the project .... make sure that you have connected the COM Port with your computer .... As it automatically detects all the ports so if there's no port already available then it creates problem.

Moreover, have you changed the name of Form1 to frmMain ? Double check it.

If still having problem, let me know.

Reply12.3
Replying to adiono

Yeah it will detect that usb port .... I think you are using serial to usb converter .... make sure that you have installed the drivers correctly and some COM has been assigned to your cable like COM3 etc ....

The best way to test the software is via virtual port .... the port you are taking is not virtual .... virtual is actually a software port which doesn't exist but operates virtually (software level) ...

1 reply
Reply14

Hi. Can i ask something. I already follow all your instructions. I can debug the code. But when i click on Connect button, error message popup stated that "UnauthorizedAccessException was unhandled. Access to the port 'COM4' is denied. It is because i used virtual serial port? I used proteus, eltima virtual serial port and microc pro for PIC.

3 replies
1 reply
Reply16

Hi bro,
i am using visual studio 2010 c++,i have try to made terminal using c++ windows form applications.i tried run exe file on other pc which don't have studio it showing errors.i changed the settings project->properties-> cofiguration->c++->codegeneration->multi threaded(mt). after changing settings also i'm getting errors.what is the solution for this? give reply asap.
thanks

1 reply
Reply17

Hi Nasir,

I have got this problem as below,
The PortName cannot be empty.
Parameter name: PortName
The list of com port does not drop down as well. It is blank when I run the program. I really appreciate your help.

Regards,
Teh

1 reply
Reply17.1
Replying to adiono

Hi,

Actually you are getting the problem because you haven't attached any COM Port with the computer on which you are running it .....

So, before running this software first attach some COM Port or create a virtual COM Port.

Thanks.

Reply18

Hi,
My name is Nimal Rathnaweera and just joined the site today. I am also interested to obtain the above code. Could you please sent it to me at: nratnaweera@gmail.com

Many thanks in advance !!!

Nimal

1 reply
Reply20

hii

i want .exe file for above mentioned terminal. my email id is pardeep_acet74@yahoo.com.

i want to receive data sent from my micro controller unit to system via serial port db9. and the sore in the data base of system in excel file or in other former..
plz help
thanks..

Reply21

hii

i want .exe file for above mentioned terminal. my email id is pardeep_acet74@yahoo.com.

i want to receive data sent from my micro controller unit to system via serial port db9. and the store in the data base of system in excel file or in other formet..
plz help
thanks..

Reply22

Hi
Sir I follow the procedure and make the program and compile it successfully, but before that i miss to rename the transmit text box, however after compiling the program i start the program but it does not shows any thing in combo box nor port no neither baud rate, i also try virtual serial port but it does not works, i repast the whole code again and i got an error and form in design tab also vanishes.
I just forget the what error was because while writing this i repast and test it, and it works launch the program it works, i wonder what happens, Its like charm , Can u explain what happened, first it does not work but later it works

1 reply
Reply22.1
Replying to adiono

change this code
myPort = IO.Ports.SerialPort.GetPortNames()

to
myPort = SerialPort.GetPortNames()

Also the transmit is not included Character return and line feed...so if you are using modem it doesn't work.
Please add the character return yourself. ....I am testing the receiving part, since I can get message response

1 reply
Reply23

This is really pretty cool, i compiled and controlled Arduino succesifully. But make sure the port is short circuited/or there is handshake between the transmitter and the receiver in order to see how it send as well as it receive data.

Reply25

I have tried code using VB2010 on Windows 7, the program runs perfectly without any error BUT its NOT detecting any serial/com ports on my machine. Checking the Device Manager, under (PORTS & LPT) communication port (COM1) is listed there.

What do I missed?

Please help.

Thanks

1 reply
1 reply
Reply29

Hi Syed Zain Nasir,

This is a very interesting tutorial/project. for learning purposes, can I have a copy of this project? thanks! my email add is akatoybits@hotmail.com

Thanks,
Albert

Reply30

This is a very interesting tutorial/project. for learning purposes, can I have a copy of this project? thanks! my email add is ddprasad [at] gmail [dot] com

Thanks,

1 reply
Reply32

Hi Im working with FT232r
After I finished your tutorial and Implement it with Visual basic All the section except Received field work currently
I shortened Rx and Tx pins of Ft232r but What I sent through "Send button did not appear In Received Field
Both Received and Transmit LED on FT232r module became on when I sent my string but why I couldn't see any string in Received Text?

Thanks in advance

1 reply
Reply33

Sir I Using PLC With Port Connection, But When I Connect Using COM1 The Device Connection Is Off.., When I Closed Connection, Device Connection Is On...
Why...??
Can You Give me Solution..??
Thankyou...

1 reply
1 reply
1 reply
1 reply
Reply38

I compiled this code fine. Connect it to an Arduino board project.
On initial connection there seems to be trash characters being sent to the Arduino. After about 3 or 4 seconds it stops. Happens every time the connection is established. After that it works great.
Any ideas what might cause such a thing? I have not modified the code in any way.
This behaviour does not happen if I connect with Putty to the Arduino board.

2 replies
1 reply
Reply44

Sorry my last comment was incomplete.. I am sending a pic to you.. I want to create this form.. Can you tell me what will be code?? How can I store data coming from usb??

1 reply
1 reply
Reply51

Hi Syed, liked your tutorial, I did everything you said, but the comm port drop down box is empty, does not pick up any ports and there are definetly ports open on my PC , I can open them with Hyper terminal or Clear terminal, I use Windows7, what can be the problem?
Willie

Reply53

actually i want to send command from visual studio to xbee and receive data comming on serial port i need code for this purpose , i dont want to use ardujino for decrypt the receive string , i have to do all operation from visual studio related xbee please help me out ..
thanks ....

Reply55

where this code will come ?
and how to get SerialPortInterface that is the third tab

( Serial Port Receiving Code Starts Here ....
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
'Serial Port Receiving Code Ends Here ....

'Serial Port Receiving Code(Invoke) Starts Here ....
Private Sub ReceivedText(ByVal [text] As String)
If Me.rtbReceived.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.rtbReceived.Text &= [text]
End If
End Sub
'Serial Port Receiving Code(Invoke) Ends Here ....

'Com Port Change Warning Code Starts Here ....
Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
If SerialPort1.IsOpen = False Then
SerialPort1.PortName = cmbPort.Text
Else
MsgBox("Valid only if port is Closed", vbCritical)
End If
End Sub )

1 reply
1 reply