1 Replies - 6711 Views - Last Post: 10 November 2010 - 02:18 PM Rate Topic: -----

#1 Dezigner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-November 10

Incorrect Data is Received From Serial Port

Posted 10 November 2010 - 12:39 PM

Hi Everyone,

I am new to this forum and VB.net. I am current using VS2008 to write a little app to transmit hex data via the serial port to the target device and receive back data from it and display that on a text box.

The problem i am facing is receiving "read" data "hex" back from the serial port and displaying it. I am able to send data to the target system without any problem. For example, if i send this command "&H10, &H0, &H1, &H7E, &HFF, &H49" The LEDs on the system blink 10 times and it works every time. If i send this command "&H10, &H0, &H0, &HFF, &HD" i should get 5E back and I use Realterm to verify the communication and it works great. When i use my VB app it fails, instead of getting back 5E.I get "&H35, &H45, &HD, &HA" on the buffer
Could anyone give me some clues to why it's not working on my VB app but it works in Realterm

 Private Sub sendbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendbutton.Click
        Dim send_Buffer() As Byte = {&H10, &H0, &H0, &HFF, &HD}
        Dim receive_Buffer(255) As Byte
        Dim receive_data As String
        Dim display_txt As Integer
        If SerialPort.IsOpen = False Then
            SerialPort.Open()
        End If
        SerialPort.Write(send_Buffer, 0, send_Buffer.Length)

        'display_txt = SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        'SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        Display_box.Text = Convert.ToDecimal(receive_Buffer)


    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Incorrect Data is Received From Serial Port

#2 Dezigner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-November 10

Re: Incorrect Data is Received From Serial Port

Posted 10 November 2010 - 02:18 PM

View PostDezigner, on 10 November 2010 - 11:39 AM, said:

Hi Everyone,

I am new to this forum and VB.net. I am current using VS2008 to write a little app to transmit hex data via the serial port to the target device and receive back data from it and display that on a text box.

The problem i am facing is receiving "read" data "hex" back from the serial port and displaying it. I am able to send data to the target system without any problem. For example, if i send this command "&H10, &H0, &H1, &H7E, &HFF, &H49" The LEDs on the system blink 10 times and it works every time. If i send this command "&H10, &H0, &H0, &HFF, &HD" i should get 5E back and I use Realterm to verify the communication and it works great. When i use my VB app it fails, instead of getting back 5E.I get "&H35, &H45, &HD, &HA" on the buffer
Could anyone give me some clues to why it's not working on my VB app but it works in Realterm

 Private Sub sendbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendbutton.Click
        Dim send_Buffer() As Byte = {&H10, &H0, &H0, &HFF, &HD}
        Dim receive_Buffer(255) As Byte
        Dim receive_data As String
        Dim display_txt As Integer
        If SerialPort.IsOpen = False Then
            SerialPort.Open()
        End If
        SerialPort.Write(send_Buffer, 0, send_Buffer.Length)

        'display_txt = SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        'SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        SerialPort.Read(receive_Buffer, 0, receive_Buffer.Length)
        Display_box.Text = Convert.ToDecimal(receive_Buffer)


    End Sub
End Class


Here is my solution to the above problem
Dim str As String = SerialPort1.ReadExisting()


then display it in the text box
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1