|
-
May 7th, 2006, 07:17 AM
#1
Thread Starter
New Member
Analysis of Serial port data using a text file
Hi All,
I need some real help. My programming experience is about 20 hour’s total. I am using visual basic express 2005. I want to create an application which opens a com port and references the received data to a text file or some other user editable file. I have created the application and the com port opens and I can see the data. I have then used some "if then" statements to check for certain bytes and display a message. This works; however for three days I have tried to understand how to reference a database or text file and out put the results: e.g. I receive T1380000A0005 on my serial line. I want to split the serial data as T138000 and 0005 "removing the 0A" then I want to reference each split in a files similar to the below:-
#T138000#Button Press 1#
#T138080#Button Release 1#
#0005#Bus 0#Unit ID 5#
#0004#Bus 0#Unit ID 4#
Then in a text box I want to output the result as:-
Button 1 Pressed on Unit 5 Bus 0
I have racked my brains on this with no luck, and remember it’s all Chinese to me, so any real world examples would be much appreciated.
Thanks in advance
Mike
-
May 7th, 2006, 06:33 PM
#2
Re: Analysis of Serial port data using a text file
Since VB 2005 is VB .net, you should be posting in Visual Basic .NET.
Look at (I believe it's still in VB 2005) the Split function. (It migt be a method of class String in 2005.) Also Mid$, Left$ and Right$ (which might also be methods now).
If you want to compare each input from the port to the entire user file, I'd suggest a small database (create an access table and use that from VB). Then you can "Select" just the entries with the text you want - T138000 or Button or whatever, without having to check every single entry.
-
May 7th, 2006, 06:40 PM
#3
Junior Member
Re: Analysis of Serial port data using a text file
Look at using a StringTokenizer class. You can do split things according to some delimiter.
You can copy this code:
VB Code:
'StringTokenizer Class
Private s As String, i As Integer
Private sep As String 'token separator
Private stokens() As String 'array of tokens
Public Sub init(ByVal st As String, ByVal seper As String)
s = st
sep = seper
setSeparator (seper)
End Sub
Public Sub setSeparator(ByVal sp As String)
sep = sp
stokens = Split(s, sp)
i = -1
End Sub
Public Function nextToken() As String
Dim tok As String
If i < UBound(stokens) Then
i = i + 1
tok = stokens(i)
Else
tok = ""
End If
nextToken = tok 'return token
End Function
ie. "T1380000A0005" using "0A" as the delimiter:
Use this way:
VB Code:
dim st as StringTokenizer
dim firstToken as String
dim secondToken as String
call st.init("T1380000A0005", "0A")
firstToken = st.nextToken 'Becomes: T1380000
secondToken = st.nextToken 'Becomes: 0005
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|