| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 601 人关注过本帖, 1 人收藏
标题:串口接收数据程序
只看楼主 加入收藏
guomanjie
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2013-11-21
结帖率:88.89%
收藏(1)
 问题点数:0 回复次数:1 
串口接收数据程序
接收数据的代码,哪里有错?四路传感器采集数据,依次送到串口,得到的数据形式是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
搜索更多相关主题的帖子: 传感器 
2014-01-08 15:55
guomanjie
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2013-11-21
收藏
得分:0 
已经解决了
2014-01-08 19:13
快速回复:串口接收数据程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016750 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved