简体   繁体   中英

VB.net: Send Live Data to Serial Port

I'm totally stuck at how to send the live data (continuously automatically change value) to serial port. For example in this code, i try to send 2 data together with time. I manage to send them out but they are not updated value. it is not continuously updated. See Private Sub Button2_Click:

'------------------------------------------------
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    'combined data = data1 + data2 + data3 + .....
    'Space is to allow space in between data
    RichTextBox1.Text = BasicLabel1.Text & Space(8) & BasicLabel2.Text & Space(8) & DateAndTime.TimeString
    SerialPort1.Write(RichTextBox1.Text & vbCr) 'concatenate with \n

End Sub

i finally found the solution:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    RichTextBox1.Text = BasicLabel1.Text & Space(8) & BasicLabel2.Text & Space(8) & DateAndTime.Now.ToString
    If SerialPort1.IsOpen Then
        SerialPort1.Write(RichTextBox1.Text + vbCr)
        Me.Refresh()
    End If

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM