串口接收数据程序
接收数据的代码,哪里有错?四路传感器采集数据,依次送到串口,得到的数据形式是S1,S2,S3,S4,S1,S2,S3,S4......但是每组数据之间隔组零,这是什么回事?????
程序代码:
Private Sub MSComm1_OnComm() '串口通信,采集 Select Case '串口事件 Case comEvReceive '接收到数据 Dim I As Integer Dim Buffer(3) As String '数据数组 Dim UX1 As Double Dim UX2 As Double Dim UY1 As Double Dim UY2 As Double Dim a1 As Variant Dim b2 As Variant For I = 0 To 3 Buffer(I) = MSComm1.Input Select Case I Case 0 UX1 = Val(Buffer(0)) Case 1 UX2 = Val(Buffer(1)) Case 2 UY1 = Val(Buffer(2)) Case 3 UY2 = Val(Buffer(3)) End Select Next I Data3(num) = UX1 filedata3(num) = Format$(Data3(num), "0.00") Text1.Text = filedata3(num) Data4(num) = UY1 filedata4(num) = Format$(Data4(num), "0.00") Text2.Text = filedata4(num) Data5(num) = UY2 filedata5(num) = Format$(Data5(num), "0.00") Text3.Text = filedata5(num) Data6(num) = UX2 filedata6(num) = Format$(Data6(num), "0.00") Text4.Text = filedata6(num) Call theGmj1.gmj_gmj(2, a1, b2, UX1, UX2, UY1, UY2) '调用matlab Call theGmj2.x3(1, g, a1, b2) data1(num) = a1 filedata1(num) = Format$(data1(num), "0.00") Tu1.Text = filedata1(num) data2(num) = b2 filedata2(num) = Format$(data2(num), "0.00") Tu2.Text = filedata2(num) MSFlexGrid1.TextMatrix(num, 1) = filedata3(num) MSFlexGrid1.TextMatrix(num, 2) = filedata6(num) MSFlexGrid1.TextMatrix(num, 3) = filedata5(num) MSFlexGrid1.TextMatrix(num, 4) = filedata4(num) MSFlexGrid1.TextMatrix(num, 5) = filedata1(num) MSFlexGrid1.TextMatrix(num, 6) = filedata2(num) num = num + 1 If num > 199 Then Call renew Call draw Call tabinit End Select End Sub