Serial port (com port) reading data
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Serial port (com port) reading data

  1. #1
    Join Date
    Aug 2008
    Posts
    82

    Exclamation Serial port (com port) reading data

    I have a valentine 1 radar and also the V1Connect (bluetooth adaptor) for it hooked to my PC via a Virtual Serial Port (COM 16).

    I am trying to read the data coming from it but all i am getting is gibberish.

    My VB.net code is this:
    Code:
        Private pendingMsg As New stringbuilder
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For Each s In System.IO.Ports.SerialPort.GetPortNames()
                lstPorts.Items.Add(s)
            Next s
        End Sub
    
        Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            Dim completedMsg As String
            completedMsg = String.Empty
            pendingMsg.Append(SerialPort1.BytesToRead())
    
            If pendingMsg.Length >= 24 Then
                completedMsg = pendingMsg.ToString
                Debug.Print(completedMsg)
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SerialPort1.BaudRate = 57600
            SerialPort1.DataBits = 8
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.PortName = "COM16" 'lstPorts.SelectedItem.ToString
            SerialPort1.Open()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            SerialPort1.Close()
            txtReceived.Text = ""
        End Sub
    and the gibberish output is this:
    Code:
    71919383957767795114129133
    71919383957767795114129133152
    71919383957767795114129133152167
    71919383957767795114129133152167171
    71919383957767795114129133152167171190
    71919383957767795114129133152167171190191
    71919383957767795114129133152167171190191209
    71919383957767795114129133152167171190191209228
    71919383957767795114129133152167171190191209228229
    71919383957767795114129133152167171190191209228229247
    71919383957767795114129133152167171190191209228229247266
    71919383957767795114129133152167171190191209228229247266280
    71919383957767795114129133152167171190191209228229247266280285
    71919383957767795114129133152167171190191209228229247266280285304
    71919383957767795114129133152167171190191209228229247266280285304311
    71919383957767795114129133152167171190191209228229247266280285304311323
    71919383957767795114129133152167171190191209228229247266280285304311323342
    71919383957767795114129133152167171190191209228229247266280285304311323342343
    71919383957767795114129133152167171190191209228229247266280285304311323342343361
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382399
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382399418
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382399418419
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382399418419437
    71919383957767795114129133152167171190191209228229247266280285304311323342343361380382399418419437456
    The datasheets for the V1 are:










    The full PDF for the ESP can be found http://www.valentine1.com/eula/eula.asp?d

  2. #2
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,832

    Re: Serial port (com port) reading data

    That is not gibberish. It is formatted numeric data. You need to write your code so that it picks up the start and end characters and grab the data that is between those characters rather than just dumping it all into a text box. Sometimes you will see a partial string in any given read and sometimes you will see more than 1 string or even more depending on how the device is sending data and what your program is doing.

    Typically when i write something that is going to be receiving data be it serial or TCP I will append the data to a buffer var then I will check that buffer var for the terminator character/sequence.
    If there is a terminator there then I pull the data from the buffer var up to that terminator, put that in my Action var and save the rest back into the buffer var.
    Process the data in the action var
    Check the buffer for additional terminators and repeat until all items have been processed.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122

    Re: Serial port (com port) reading data

    Data miser is correct, this looks to be formatted data from the uits output buffer.

    Your code is just reading the output of the unit, and not actually getting the formatted data as the specification define. Typically, this is obtained by a command and responce system, i.e. you send a command and get a formatted responce data packet.

    Learn to send commands to the unit and then manually try to intepret the data from the specifications. Once you can do that, you can program your system accordingly.
    There are 10 types of people in the world, those that understand binary and those that don't.
    Using VS 2010

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center