Results 1 to 2 of 2

Thread: calling a different procudre in main thread from within the DataReceived procedure

Hybrid View

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    9

    calling a different procudre in main thread from within the DataReceived procedure

    Hi want to call the method HANDLEINPUT(BYVAL m_strInBuff) from the data received event.

    Please help.

    My code is:

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    Try
    If SerialPort1.BytesToRead >= 4 Then

    SerialPort1.ReadTimeout = 1000

    m_strInBuff = (SerialPort1.ReadTo(Chr(13)))

    'Show_Error("m_strInBuff = " & SerialPort1.ReadExisting)
    End If

    'data to UI thread
    'Me.Invoke(New EventHandler(AddressOf DoUpdate)) '//Commented oujt for test only
    Me.Invoke(New EventHandler(AddressOf HandleInput(m_strInBuff)))


    Catch ex As Exception
    MsgBox("read " & ex.Message)
    End Try
    'End If
    End Sub

    Please help how I can I modify the code here

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: calling a different procudre in main thread from within the DataReceived procedur

    Try this:

    Code:
    Private Delegate Sub delHandleInput(ByVal input As String) '<<< this line is new 
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
    
    Try
    If SerialPort1.BytesToRead >= 4 Then
    
    SerialPort1.ReadTimeout = 1000
    
    m_strInBuff = (SerialPort1.ReadTo(Chr(13)))
    
    'Show_Error("m_strInBuff = " & SerialPort1.ReadExisting)
    End If
    
    'data to UI thread
    
    Me.Invoke(New delHandleInput(AddressOf HandleInput), m_strBuffer) '<<< this line is changed
    
    
    Catch ex As Exception
    MsgBox("read " & ex.Message)
    End Try
    'End If
    End Sub
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

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