VB.NET SerialPort 串口DataReceived事件,超过五十分钟后无法触发
PrivateSubbtnKeiRyo_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handles...
Private Sub btnKeiRyo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnv_nJ.Click
If SerialPortHaKaRi IsNot Nothing Then
If SerialPortHaKaRi.IsOpen = True Then
SerialPortHaKaRi.Close()
End If
If SerialPortHaKaRi.IsOpen = False Then
SerialPortHaKaRi.Open()
'TCY
SerialPortHaKaRi.ReceivedBytesThreshold = 1
End If
SerialPortHaKaRi.WriteLine(haKaRi_temp)
End If
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPortHaKaRi.DataReceived
Dim strRecvData As String = ""
strRecvData = SerialPortHaKaRi.ReadExisting
Call disPlayComData(strRecvData)
If SerialPortHaKaRi IsNot Nothing Then
If SerialPortHaKaRi.IsOpen = True Then
SerialPortHaKaRi.Close()
End If
End If
End Sub
但是把程序重新启动,就又能触发了。
感觉时间长之后,程序好像变得慢了
Delegate Sub callback(ByVal strT As String) '定义委托
Sub showString(ByVal comdata As String) '显示结果
strHaKaRi_TEMP = comdata
F_ハカリ_设定()
End Sub
Sub disPlayComData(ByVal strTmp As String) '判定是否为跨线程
If Me.lbl入力値.InvokeRequired Then
Dim d As New callback(AddressOf showString)
Me.Invoke(d, New Object() {strTmp})
Else
strHaKaRi_TEMP = strTmp
F_ハカリ_设定()
End If
End Sub
如能解决,可加分啊。帮帮忙~ 展开
If SerialPortHaKaRi IsNot Nothing Then
If SerialPortHaKaRi.IsOpen = True Then
SerialPortHaKaRi.Close()
End If
If SerialPortHaKaRi.IsOpen = False Then
SerialPortHaKaRi.Open()
'TCY
SerialPortHaKaRi.ReceivedBytesThreshold = 1
End If
SerialPortHaKaRi.WriteLine(haKaRi_temp)
End If
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPortHaKaRi.DataReceived
Dim strRecvData As String = ""
strRecvData = SerialPortHaKaRi.ReadExisting
Call disPlayComData(strRecvData)
If SerialPortHaKaRi IsNot Nothing Then
If SerialPortHaKaRi.IsOpen = True Then
SerialPortHaKaRi.Close()
End If
End If
End Sub
但是把程序重新启动,就又能触发了。
感觉时间长之后,程序好像变得慢了
Delegate Sub callback(ByVal strT As String) '定义委托
Sub showString(ByVal comdata As String) '显示结果
strHaKaRi_TEMP = comdata
F_ハカリ_设定()
End Sub
Sub disPlayComData(ByVal strTmp As String) '判定是否为跨线程
If Me.lbl入力値.InvokeRequired Then
Dim d As New callback(AddressOf showString)
Me.Invoke(d, New Object() {strTmp})
Else
strHaKaRi_TEMP = strTmp
F_ハカリ_设定()
End If
End Sub
如能解决,可加分啊。帮帮忙~ 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询