关于VB串口接收温湿度数据的问题 10
图为DTH11湿度传感器串口通信部分的C程序我用VB写了一个串口接收此传感器温湿度数据的界面,但是好像接收不到数据总是没能在listbox中显示出数据来,希望各位高手大神...
图为DTH11湿度传感器串口通信部分的C程序
我用VB写了一个串口接收此传感器温湿度数据的界面,但是好像接收不到数据总是没能在listbox中显示出数据来,希望各位高手大神能帮我指点一下哪里有问题
其中串口事件如下:
Private Sub MSComm1_OnComm() Dim recv() As Byte Dim recv_data As String Dim recv_buf As String Dim n As Integer Dim stmCon As New Stream Dim j As Integer counter = counter + 1 Text2.Text = CStr(counter) Select Case MSComm1.CommEvent Case comEvReceive MSComm1.RThreshold = 0 n = MSComm1.InBufferCount ReDim recv(n) MSComm1.InputLen = n recv = MSComm1.Input For i = 0 To n - 1 recv_buf = Hex(recv(i)) recv_data = recv_data + recv_buf Next i recv_buf = "" recv_buf = CStr(Time) + "的温度是" + Left(recv_data, 3) + "." + Right(recv_data, 1) + "℃" List1.AddItem recv_buf Case comEventRxOver List1.Clear Text2.Text = "" Case comEventTxFull List1.Clear Text2.Text = "" End Select MSComm1.RThreshold = 1End Sub 展开
我用VB写了一个串口接收此传感器温湿度数据的界面,但是好像接收不到数据总是没能在listbox中显示出数据来,希望各位高手大神能帮我指点一下哪里有问题
其中串口事件如下:
Private Sub MSComm1_OnComm() Dim recv() As Byte Dim recv_data As String Dim recv_buf As String Dim n As Integer Dim stmCon As New Stream Dim j As Integer counter = counter + 1 Text2.Text = CStr(counter) Select Case MSComm1.CommEvent Case comEvReceive MSComm1.RThreshold = 0 n = MSComm1.InBufferCount ReDim recv(n) MSComm1.InputLen = n recv = MSComm1.Input For i = 0 To n - 1 recv_buf = Hex(recv(i)) recv_data = recv_data + recv_buf Next i recv_buf = "" recv_buf = CStr(Time) + "的温度是" + Left(recv_data, 3) + "." + Right(recv_data, 1) + "℃" List1.AddItem recv_buf Case comEventRxOver List1.Clear Text2.Text = "" Case comEventTxFull List1.Clear Text2.Text = "" End Select MSComm1.RThreshold = 1End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询