Whilst undertaking several hours googling I came across a forum that contained a simple example from a two year old post of using VB.net to communicate with a PIC micro using PBP. So far I'm managing to adapt it to include a combo box to choose the comm port and retrieve a set of data from my PIC.
For reference here is the VB code
Code:
Imports System.IO
Imports System.IO.Ports
Imports System.Net
Imports System.Data
Imports System
Imports System.Windows.Forms
Imports System.Threading
Imports System.Text
Public Class mMain
Dim WithEvents serPort As New IO.Ports.SerialPort
Dim myStringBuilder As New StringBuilder
Private Sub mMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i As Byte = 0 To My.Computer.Ports.SerialPortNames.Count - 1
Me.ComboBox1.Items.Add(My.Computer.Ports.SerialPortNames(i))
Next i
serPort.BaudRate = 115200
serPort.DataBits = 8
serPort.Parity = Parity.None
serPort.StopBits = StopBits.One
butConnect.Enabled = True
butDisConnect.Enabled = False
End Sub
Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butConnect.Click
If (serPort.IsOpen = False) Then
Try
serPort.Open()
lstData.Items.Clear()
myStringBuilder = New StringBuilder 'Clear any old data
butConnect.Enabled = False
butDisConnect.Enabled = True
Catch ex As Exception
'Routine to process exceptions like port already open etc.
MsgBox("Exception error")
End Try
End If
End Sub
Private Sub butDisConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butDisConnect.Click
If (serPort.IsOpen = True) Then
serPort.Close()
butDisConnect.Enabled = False
butConnect.Enabled = True
End If
End Sub
Private Sub serPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serPort.DataReceived
Try
myStringBuilder.Append(serPort.ReadExisting())
Me.Invoke(New EventHandler(AddressOf update_Data))
Catch ex As Exception
MsgBox("Data Error")
End Try
End Sub
Private Sub update_Data()
lstData.Items.Add(myStringBuilder.ToString)
myStringBuilder = New StringBuilder 'Flush the old data
End Sub
End Class
I designed a form to suit the different buttons and combo boxes and this was the result.

The data in the list box came from this section of PBP code
Code:
Hserout [DEC Temperatures(0)]
Hserout [DEC Temperatures(1)]
Hserout [DEC Temperatures(2)]
Hserout [DEC Temperatures(3)]
hserout [10]
And as I only have one sensor out of four connected to the input associated with Temperature(2) in use the value of 002610, 002680 etc is right and reflects the 26.1C (rising).
However I would like to split this and place the result into 4 separate text boxes, ie so textbox1 will be updated with just Temperature(0), Textbox2 with Temperature(1) etc. Is there any modification I can do to the PBP code to separate the string to do this.
I know there has been some concerns about discussing VB code on this forum, but IMO when it's related to such a topic this thread covers I feel that it's justified.
Bookmarks