4

关于投票
vb编写的人型机器人控制程序(PC与AVR单片机通讯)

Dim a As Integer, l As Boolean, p As Boolean, a1 As Integer, a2 As Integer, r As Boolean
Dim datio(21) As Byte
Dim d As Integer
Dim i As Integer
Sub sendarray()
Text_se.Text = Trim(Text_se.Text)
      datio(0) = Val("&h" & Mid(Text_se.Text, 1, 3))
       datio(1) = Val("&h" & Mid(Text_se.Text, 4, 3))
        datio(2) = Val("&h" & Mid(Text_se.Text, 7, 3))
         datio(3) = Val("&h" & Mid(Text_se.Text, 10, 3))
     datio(4) = Val("&h" & Mid(Text_se.Text, 13, 3))
     datio(5) = Val("&h" & Mid(Text_se.Text, 16, 3))
     datio(6) = Val("&h" & Mid(Text_se.Text, 19, 3))
     datio(7) = Val("&h" & Mid(Text_se.Text, 22, 3))
     datio(8) = Val("&h" & Mid(Text_se.Text, 25, 3))
     datio(9) = Val("&h" & Mid(Text_se.Text, 28, 3))
     datio(10) = Val("&h" & Mid(Text_se.Text, 31, 3))
     datio(11) = Val("&h" & Mid(Text_se.Text, 34, 3))
     datio(12) = Val("&h" & Mid(Text_se.Text, 37, 3))
     datio(13) = Val("&h" & Mid(Text_se.Text, 40, 3))
     datio(14) = Val("&h" & Mid(Text_se.Text, 43, 3))
     datio(15) = Val("&h" & Mid(Text_se.Text, 46, 3))
     datio(16) = Val("&h" & Mid(Text_se.Text, 49, 3))
     datio(17) = Val("&h" & Mid(Text_se.Text, 52, 3))
     datio(18) = Val("&h" & Mid(Text_se.Text, 55, 3))
     datio(19) = Val("&h" & Mid(Text_se.Text, 58, 3))
     datio(20) = Val("&h" & Mid(Text_se.Text, 61, 3))
     datio(21) = Val("&h" & Mid(Text_se.Text, 64, 3))
     MSComm1.Output = datio()
   End Sub
'Dim b()
Sub kkk()                        '发送子程序
   Dim X As String, q As String, w As Integer
   'w = j
  ' Static s As Integer
'    If Not l Then
'      i = 1
'      l = True
'    End If
'Static i As Integer
i = List1.ListCount + 1
Dim str  As String, pp As String, jj As String
If Not MSComm1.PortOpen Then
   MSComm1.PortOpen = True
End If
If Text1(0).Text = "" Then
    MsgBox " 1号BOX没有输入"
    Exit Sub
End If
Text_se.Text = ""                       '发送数据
     'Text_se.Text = Text1(0).Text + Space(2) + Text2(0).Text + Space(2) + _
                    Text3(0).Text + Space(2) + Text4(0).Text + Space(2) + _
                    Text5(0).Text + Space(2) + Text6(0).Text + Space(2) + _
                    Text7(0).Text + Space(2) + Text8(0).Text + Space(2) + _
                    Text9(0).Text + Space(2) + Text10(0).Text + Space(2) + _
                    Text11(0).Text + Space(2) + Text12(0).Text + Space(2) + _
                    Text13(0).Text + Space(2) + Text14(0).Text + Space(2) + _
                    Text15(0).Text + Space(2) + Text16(0).Text + Space(2) + _
                    Text17(0).Text + Space(2) + Text18(0).Text + Space(2) + _
                    Text19(0).Text + Space(2) + Text20.Text + Space(2) + _
                    Text21.Text + Space(2) + Text22.Text
                     
     Dim sstr(21) As String
     Dim dat(21) As Byte
    
     Dim h As Byte
    
     h = 0
     dat(0) = Val(Text1(0).Text)
     'Text_se.Text = dat(0)
     dat(1) = Val(Text2(0).Text)
     dat(2) = Val(Text3(0).Text)
     dat(3) = Val(Text4(0).Text)
     dat(4) = Val(Text5(0).Text)
     dat(5) = Val(Text6(0).Text)
     dat(6) = Val(Text7(0).Text)
     dat(7) = Val(Text8(0).Text)
     dat(8) = Val(Text9(0).Text)
     dat(9) = Val(Text10(0).Text)
     dat(10) = Val(Text11(0).Text)
     dat(11) = Val(Text12(0).Text)
     dat(12) = Val(Text13(0).Text)
     dat(13) = Val(Text14(0).Text)
     dat(14) = Val(Text15(0).Text)
     dat(15) = Val(Text16(0).Text)
     dat(16) = Val(Text17(0).Text)
     dat(17) = Val(Text18(0).Text)
     dat(18) = Val(Text19(0).Text)
     dat(19) = Val(Text20.Text)
     dat(20) = Val(Text21.Text)
     dat(21) = Val(Text22.Text)
     While h < 22
      sstr(h) = dat(h)
      h = h + 1
      Wend
      h = 0
      While h < 22
      If dat(h) < 16 Then
      sstr(h) = "0" & Hex(dat(h))
      End If
      If dat(h) >= 16 Then
      sstr(h) = Hex(dat(h))
      End If
      h = h + 1
      Wend
      h = 0
      While h < 22
      Text_se.Text = Text_se.Text & sstr(h) & Space(1)
      h = h + 1
      Wend

 
     Call sendarray
    
     pp = i & Space(2) & Text_se.Text
     i = i + 1
     jj = Trim(Text_se.Text)
    str = Text_se.Text
  If jj = "" Then
   X = MsgBox("发送不能为空", 16)
  Exit Sub
  End If

If Check1.Value = False Then                        ' 是否保存
    Dim file As Integer
    file = FreeFile
    Open "D:\zhu.txt" For Append As #file
    Print #file, pp
    Close #file
    List1.AddItem pp
End If

  

 


'发送
TimeDelay

'If Check3.Value = 1 Then                            '等待接收
''   Do
''   Timer1.Enabled = True                           '启动计数器
''      q = M