Hi Everyone
I'm trying to receive data from a serial port. I can do this quite fine when its just strings I'm receiving, but
this I need to receive bytes. The following code only allows for the first byte to receive then falls over
with
"An exception of type 'System.IndexOutOfRangeException' occurred in mk3CommTest.exe but was not handled in user code"
error. I have commented out the try statement so I see the error
Any help would be appreciated
Code:Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived 'Handles serial port data received events UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay) Dim n As Integer = SerialPort1.BytesToRead comBuffer = New Byte(n - 1) {} 'buffer SerialPort1.Read(comBuffer, 0, n) 'read data from the buffer Me.Invoke(UpdateFormDelegate1) 'delegate End Sub Private Sub UpdateDisplay() ' Try RvdTxtBox.Text = CStr(comBuffer(0)) ' Catch ex As Exception ' End Try End Sub




Reply With Quote
