Thread: Serial Oddity

  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Somewhere in the vicinity of Betelgeuse
    Rep Power

    Serial Oddity

    This is the meat of my serial receive:

    vb Code:
    Private Sub mySerialPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
            'Handles serial port data received events 
            UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay)
            Dim n As Integer = mySerialPort.BytesToRead 'find number of bytes in buf 
            comBuffer = New Byte(n - 1) {} 're dimension storage buffer 
            mySerialPort.Read(comBuffer, 0, n) 'read data from the buffer 
            Me.Invoke(UpdateFormDelegate1) 'call the delegate
        End Sub

    Now, what I have talking to this program is a PIC24H. I push a button and it sends:

    The issue that I'm having is that when I push the button and send the string, I'll get an incomplete string and occasionally I'll get the whole's a crapshoot. Have I over complicated things? Is there a better way to do this? This program only needs to receive data from the PIC24. Thanks.
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Rep Power
    I don't do serial port programming in VB but I suspect you should look for some event that fires when the read buffer is complete, and not read the input string until that event fires.
    Doug G
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton

IMN logo majestic logo threadwatch logo seochat tools logo