I'm trying to write a simple app for myself only, that can read continuous data coming into a serial port from a microcontroller. I eventually want to display it in a bunch of tachometer-like dials, but i'm a long ways from that point.
At this point, my trouble is i'm trying to learn how to read the incoming data, to make sure it's coming in successfully, and it's not.
I've doing a lot of surfing, and learning. I found plenty of stuff on how to read data from serial ports, including this tutorial that i followed: http://tiktakx.wordp...th-vb-net-2010/ That seems to work, but all i get in my output box is garbage: ??%?.???????? etc... I assume that's because i can't interpret hex that way.
I have been searching for how to read this data in hex, but all of the solutions i find online are too high-level for me to understand. I see people posting one-line code fixes, but i'm REALLY new, and i need more explanation on how to adjust them to match what i'm doing, and where to put them.
Here's the guts of my program, just like the tutorial shows:
Private Sub SerialPort1_DataReceived(sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the serialPort
End Sub
Private Sub ReceivedText(ByVal [text] As String)
'compares the ID of the creating Thread to the ID of the calling Thread
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
From reading online about hex data, I think i need to edit the first sub code to be
ReceivedText = Hex(SerialPort1.ReadExisting()
but i get an error: "Argument not specified for parameter 'text' of 'Private Sub ReceivedText(text As String)". I'm REALLY new, and don't understand what that means, so I click the autocorrect "Generate property stub...." which generates:
Private Property ReceivedText As Stringin the public class area at the top of my code.
That now gives me a different error on the second sub of "ReceivedText is already declared...." I do understand that i can't declare a variable twice, but my sub has the same name as my variable, and i can't figure out how to make "Private Property ReceivedText As String" and "Private Sub ReceivedText(ByVal [text] As String)" to do both things.
Sorry if this is something obvious i'm doing wrong, but i'm really new, and can't figure this out. I'm trying to learn here, so i'd appreciate low-level explanations of what i'm doing wrong, and/or how to fix it.
Thanks,
Mike

New Topic/Question
Reply



MultiQuote






|