2 Replies - 13245 Views - Last Post: 04 March 2010 - 03:13 AM Rate Topic: -----

#1 Asadbutt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-January 09

Receive HEX data through serial port

Posted 05 January 2009 - 10:06 AM

Hello ,
I am trying to recieve HEX data from a seriall device.
Code is as below . but the required output is not correct. Some chracter code are not correct even in decimal . like for 80 i recieved 3F and for c0 also.
for example i recived a string .

10 02 3F 00 10 03 3F 61

but in actual data should be

10 02 80 00 10 03 c0 61

Public Sub DataSeriallReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        Dim buff As String

        Dim i As Short
        Dim c As Short
        Dim Response As String
        Dim part As String

        Response = ""
        Dim count As Integer
        count = SerialPort.BytesToRead
        Log(count.ToString, "recieved count", w)

        buff = SerialPort.ReadExisting
    
            For i = 1 To Len(buff)
                c = Asc(Mid(buff, i, 1))
                Response = Response & Hex©
            Next i
end sub



kindly anyone know what i am doing wrong.
waiting for positive replies.
Regards

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Receive HEX data through serial port

#2 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Receive HEX data through serial port

Posted 05 January 2009 - 11:10 AM

change the encoding. ?'s (&H3F) are what you get with the standard encoding.
this should fix the problem.

SerialPort1.Encoding = System.Text.Encoding.GetEncoding("Windows-1252")

This post has been edited by dbasnett: 05 January 2009 - 11:10 AM

Was This Post Helpful? 2

#3 Guest_Mathivanan*


Reputation:

Re: Receive HEX data through serial port

Posted 04 March 2010 - 03:13 AM

Thanks ... It helps me lot..
Was This Post Helpful? 0

Page 1 of 1