|
-
Feb 20th, 2009, 04:31 PM
#1
Thread Starter
Member
serialport.ReadExisting
hi,
i have the serial open for reading data from a RFID reader.
because the data comes in Hex ASCII, so I did a code snippet to decode them to characters. below code, I need to click a button in order to decode, but it can only decode once because the text in the textbox wont be HEX anymore after one decode (get error) and I dont want to clear the txtbox after the 1st decode.
2nd is that I cant do it without a button click event, I wanted to do automatically when the data exist. but I can not put anything else in the updateTextBox() function, otherwise i'll get an error...
any ideas how to decode without error?
Serial port code:
public class
Dim updatefromdevice As String
Code:
Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialport.DataReceived
txtReceivedMessage.BeginInvoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub
Public Delegate Sub myDelegate()
Public Sub updateTextBox()
txtReceivedMessage.Text = serialport.ReadExisting & vbCrLf & txtReceivedMessage.Text 'Display received data to textbox
End Sub
decoder code:
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim hexnum As String
Dim converttohex As String
Dim hextonum As Integer
Dim chara As Char
updatefromdevice = txtReceivedMessage.Text
hexnum = updatefromdevice.Trim()
For i = 0 To Len(hexnum) - 1 Step 2
converttohex = hexnum.Substring(i, 2)
hextonum = Convert.ToInt32(converttohex, 16)
chara = Chr(hextonum)
txtReceivedMessage.Text += chara
Next i
End Sub
-
Feb 21st, 2009, 02:41 AM
#2
Frenzied Member
Re: serialport.ReadExisting
Take a look at Dick Griers site - there is a good example of using the serial port
-
Feb 23rd, 2009, 07:05 PM
#3
Thread Starter
Member
Re: serialport.ReadExisting
 Originally Posted by petevick
Take a look at Dick Griers site - there is a good example of using the serial port
i cant find the example in that site..
-
Feb 24th, 2009, 01:57 AM
#4
Frenzied Member
Re: serialport.ReadExisting
Go to the site, click on 'Software Downloads' and then Visual Studio 2005 Serial Terminal Example (uses the System.IO.Ports namespace). Download here. (Updated July 31, 2006) -- FREE
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
|