serial coms - again


Closed Thread
Results 1 to 40 of 58

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce, thanks for the prompt reply.

    I've tried commenting out all but the first vairiable so it is only expecting only one value, but that still caused the thing to run really really slowly ... as does removing the DEC modifier could you provide me with a quick example of how to to a time out to try?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Malc,

    There's an example in the manual, but it works like this;

    HSERIN 100,Timesup,[B0]

    Timesup:
    do something here is data not received

    If no character is received in B0 within 100mS it jumps to Timesup.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    cheers Bruce...

    Sorry, heat of the moment, quicker to ask than dig out the manual !

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    One other thing that has come to light is that I need clear the buffer after
    Code:
    HSEROUT [dec StopHour[0],dec StopMin[0],dec StopHour[1],dec StopMin[1],dec StopHour[2],dec StopMin[2],dec StopHour[3],dec StopMin[3]
    I gather this is required so that it places the correct variable in the right location in the application.

    Any ideas

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I'm not 100% sure what you're asking Malc?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    To be honest I'm not sure either - I thought if you sent A,B,C through the port it would just loop that over and over again... do PICs have buffers ? I thought they sent data straight out and in ? but then I'm really getting out of my depth with this.

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default VB Express 2008

    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.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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