SerialPort1_DataReceived and progressbar1 update...

dtvonly

Member
Joined
Jan 3, 2013
Messages
22
Programming Experience
5-10
Hi. I have VB.NET SerialPort1_DataReceived running to receive/transmit data from/to an (external) MCU. At the same time I want to update my progressbar to display the test progress. As is, the progressbar only updates once the test is completely done. I want it to update while the test is running.

I believed I have to delegate the progressbar1 object somehow inside the SerialPort1_DataReceived routine. I don't know the syntax for this.

I have successfully delegated Textboxes and labels and have tried to use the same syntax (exactly). This did not work. Please advise. thank you.
 
It is the same syntax exactly. If it didn't work then you did it wrong. If you show us what you did then we can determine what's wrong with it.

Here is my code:
VB.NET:
Dim Byte_RX as Integer
Dim progressbar1_count as byte

Private Sub SerialPort1_DataReceived(ByVal sender As Object, _
        ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        
    Byte_RX = SerialPort1.ReadByte()
              
    Me.Label3.Invoke(New label3_echo(AddressOf Label3_item), New Object() {})
    Me.TextBox3.Invoke(New Textbox3_echo(AddressOf TextBox3_item), New Object() {})
    Me.Timer1.Invoke(New Timer1_eho(AddressOf Timer1_Tick), New Object() {})
    
End Sub

Private Delegate Sub label3_echo()
Private Delegate Sub Textbox3_echo()
Private Delegate Sub Timer1_eho()

Private Sub Label3_item()

    Label3.Text = "Received byte"

End Sub

Private Sub TextBox3_item()

    TextBox3.Text = Byte_RX

End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    progressbar1_count += 10
    If (progressbar1_count > 99) Then
        progressbar1_count = 100
    End If
    ProgressBar1.Value = progressbar1_count
End Sub
 
Back
Top