本文介绍了串口线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我正在制作一个与pic微控制器配合使用的计数器。我已经做了计数器,它的工作原理,但我通过串口与pic微控制器给出的脉冲是非常快的计数器不计...我想在计数器的帮助不想错过任何脉冲.. plz帮助。
我的代码如下: -
hello
i am making a counter which works with pic micro controller. i have made counter and it works but the pulses i gave to counter through serial port with pic micro controller is very fast the counter doesn't count... i want help in counter do not want to miss any of the pulse.. plz help.
my code is following:-
Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Public Class Form1
Delegate Sub SetTextCallback(ByVal [text] As Char)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "COM50"
SerialPort1.BaudRate = "2600"
SerialPort1.Open()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As Char)
If Me.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(Text)})
Else
If Text = "A" Then
Label1.Text = Label1.Text + 1
Label1.Refresh()
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label1.Text = "0000"
End Sub
End Class
请帮助
谢谢
please help
Thanks
推荐答案
这篇关于串口线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!