VB.Net Serial Port DataReceived Event not Reading a full incoming line RRS feed

  • Question

  • So in my VB.Net project, I have a DataReceived Event function to handle the incoming data through a serial port. I created some variables named

    buffer = SerialPort1.Readline()

    count = len(buffer)

    and i used a console.writeline for the count to be displayed when the DataReceived function occurs. The count first says its 124 and then it will say it is 748. But when it is initally shown as 124, the debugging session stops and I get an error for any line in my DataReceived function that uses the Substring(Buffer, 20, 1) or the Mid(Buffer, 20, 5) function. The console says that the starting index for my lines using those functions must be be greater than zero and is linked to the length of my buffer initally being an incorrect length.

    What functions can i use to make my code read only full incoming lines of data and not the middle of an incoming line of data. 

    • Edited by Hp2241 Saturday, August 11, 2018 7:53 PM
    Saturday, August 11, 2018 7:49 PM

All replies

  • Hi,

    Can you show me more code?The data received by serialport.DataReceived is incomplete?

    tyr to modify the code:buffer = SerialPort1.Readline()

     Dim buffer As Byte() = New Byte(n) {}
     serialPort1.Read(buffer, 0, n)

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, August 13, 2018 6:19 AM