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:
http://i.stack.imgur.com/IMIG2.jpg
http://i.stack.imgur.com/UnKUU.jpg
http://i.stack.imgur.com/vJpe6.jpg
http://i.stack.imgur.com/bJFar.jpg
http://i.stack.imgur.com/cTnhn.jpg
The full PDF for the ESP can be found http://www.valentine1.com/eula/eula.asp?d
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.
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.