简体   繁体   English

VB.net:将实时数据发送到串口

[英]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.例如在这段代码中,我尝试将 2 个数据与时间一起发送。 I manage to send them out but they are not updated value.我设法将它们发送出去,但它们没有更新值。 it is not continuously updated.它不会持续更新。 See Private Sub Button2_Click:请参阅私人子按钮 2_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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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