Thread: Serial Oddity

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

    Join Date
    Feb 2007
    Location
    Somewhere in the vicinity of Betelgeuse
    Posts
    121
    Rep Power
    9

    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:

    Code:
    123456789012
    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 thing...it'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
    Posts
    14,439
    Rep Power
    4539
    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
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo