Question How to receive a character/byte from PC serial port

YVQN9945

New member
Joined
Dec 17, 2013
Messages
2
Programming Experience
Beginner
I have to receive a Character 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. Thank you.Code: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
 
Your code is all but unreadable so you might try again tp post it and format it appropriate, pasting it as plain text inside a [xcode=vb] tag.

As for the question, think about it a bit. Let's say that I give you instructions on how to go to the supermarket and buy some groceries and then put them away in the fridge when you get home. If you now want to buy groceries to make a meal immediately, are you going to need me to provide a whole new set of instructions? Of course not. It's only the last part that changes, i.e. what you do with the groceries once you get them home. The same goes here. What you do with the data once you've got it has no bearing on how you get the data in the first place. Getting data from a SerialPort is the same no matter what you intend to do with it. If you want to assign that data to a variable then go ahead and do so. Presumably you know how to assign something to a variable. How that's done doesn't change regardless of what the something is and where it came from.
 
Back
Top