Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to receive a char from PC serial port

Status
Not open for further replies.

yvqn9945

Newbie level 4
Newbie level 4
Joined
Aug 19, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
50
I have to receive a charecter sent form MCU to PC and I have to write a function to receive data in vb.net since I am a biginer in vb.net unable to code. I have googled and find the following code but this is for receiving and displaying on RichTextBox but I have to receive and assign it to a variable for further use. For which how to write a function. Please help me. Please give coding. Thank you.

Code:

Code vb.net - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        ReceivedText(SerialPort.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.RichTextBox_rxdata.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})
        Else
            Me.RichTextBox_rxdata.Text &= [text]
        End If
    End Sub

 
Last edited by a moderator:

hi.. i ussually use "timer" to handle the incoming data. here is the example i can give. it not the real code.

Code:
dim rx_data as string

Private Sub SerialPort_DataReceived()
rx_data = serialport1.readexisting
end sub

private sub timer1_tick
textbox1.text = rx_data
end sub
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top