Results 1 to 4 of 4

Thread: serialport.ReadExisting

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    42

    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

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: serialport.ReadExisting

    Take a look at Dick Griers site - there is a good example of using the serial port
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    42

    Re: serialport.ReadExisting

    Quote 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..

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width