⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 AVR原理与应用例程
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "音视频切换卡测试程序"
   ClientHeight    =   4470
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5715
   LinkTopic       =   "Form1"
   ScaleHeight     =   4470
   ScaleWidth      =   5715
   StartUpPosition =   2  '屏幕中心
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   1440
      TabIndex        =   11
      Text            =   "Text2"
      Top             =   3960
      Width           =   3495
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   3480
      Width           =   3495
   End
   Begin VB.Frame Frame1 
      Caption         =   "8to1 音视频切换卡功能测试"
      Height          =   3135
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   5295
      Begin VB.CommandButton Command1 
         Caption         =   "7号"
         Height          =   375
         Index           =   7
         Left            =   3840
         TabIndex        =   10
         Top             =   1560
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "读取切换卡状态"
         Height          =   375
         Index           =   8
         Left            =   2040
         TabIndex        =   9
         Top             =   2280
         Width           =   1455
      End
      Begin VB.CommandButton Command1 
         Caption         =   "6号"
         Height          =   375
         Index           =   6
         Left            =   2760
         TabIndex        =   8
         Top             =   1560
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "5号"
         Height          =   372
         Index           =   5
         Left            =   1680
         TabIndex        =   7
         Top             =   1560
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "4号"
         Height          =   372
         Index           =   4
         Left            =   600
         TabIndex        =   6
         Top             =   1560
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "3号"
         Height          =   375
         Index           =   3
         Left            =   3840
         TabIndex        =   5
         Top             =   720
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "2号"
         Height          =   375
         Index           =   2
         Left            =   2760
         TabIndex        =   4
         Top             =   720
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "1号"
         Height          =   372
         Index           =   1
         Left            =   1680
         TabIndex        =   3
         Top             =   720
         Width           =   975
      End
      Begin VB.CommandButton Command1 
         Caption         =   "0号"
         Height          =   375
         Index           =   0
         Left            =   600
         TabIndex        =   2
         Top             =   720
         Width           =   975
      End
   End
   Begin MSCommLib.MSComm Comm1 
      Left            =   3480
      Top             =   360
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label2 
      Caption         =   "接收命令字:"
      Height          =   255
      Left            =   240
      TabIndex        =   13
      Top             =   4080
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "发送命令字:"
      Height          =   255
      Left            =   240
      TabIndex        =   12
      Top             =   3600
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Dim receiveData() As Byte
    Dim sendData() As Byte
    
    Dim temp As Variant
    Dim buff As Variant
    
    Dim comName As Integer
    Dim readTimes As Integer
    Dim sendnumber, readnumber As Integer
    Dim bl As Byte
    Dim i As Integer

Private Sub Form_Load()
    comName = 1
    
    Comm1.OutBufferSize = 16
    Comm1.InBufferSize = 16
    Comm1.InputMode = comInputModeBinary
    
 End Sub

Private Sub Command1_Click(Index As Integer)
    
    ReDim Preserve sendData(5)
    sendData(0) = &HBB
    sendData(1) = &HA1
    sendData(4) = &HEE
    k = 1
    Select Case Index
        Case 0
            sendData(2) = &H0
        Case 1
            sendData(2) = &H1
        Case 2
            sendData(2) = &H2
        Case 3
            sendData(2) = &H3
        Case 4
            sendData(2) = &H4
        Case 5
            sendData(2) = &H5
        Case 6
            sendData(2) = &H6
        Case 7
            sendData(2) = &H7
        Case 8
            sendData(1) = &HA0
            sendData(2) = &H0
     End Select
     check = 0
     For i = 1 To 2
        check = check Xor sendData(i)
     Next i
     sendData(3) = check
     sendnumber = 5
     buff = sendData
     tempc = ""
     For i = 0 To sendnumber - 1
         If Len(Hex$(sendData(i))) = 1 Then
            ttc = "0" + Hex$(sendData(i))
         Else
            ttc = Hex$(sendData(i))
         End If
         temp_c = temp_c + " " + ttc
         
     Next i
     Text1.Text = temp_c
     commSend
End Sub

Private Sub commSend()
    Comm1.CommPort = comName
    Comm1.Settings = "9600,n,8,1"
    Comm1.OutBufferCount = 0
    Comm1.InBufferCount = 0
    Comm1.InputLen = 0
        
    readTimes = 0
    
    If Not Comm1.PortOpen Then Comm1.PortOpen = True
    
    If Comm1.PortOpen Then
        Comm1.Output = buff
    Else
       Text2.Text = "通讯口没打开"
    End If
   
    Do While Comm1.PortOpen And readTimes < 1000
        If Comm1.InBufferCount > 0 Then
            For kk = 0 To 500
                If Comm1.InBufferCount > 4 Then
                    Exit For
                End If
            Next kk
           
            If Comm1.InBufferCount = 5 Then
                temp = Comm1.Input
                receiveData = temp
           
                If receiveData(0) = &HBB Then
                    tempc = ""
                    For i = 0 To 4
                        If Len(Hex$(receiveData(i))) = 1 Then
                            ttc = "0" + Hex$(receiveData(i))
                        Else
                            ttc = Hex$(receiveData(i))
                        End If
                        temp_c = temp_c + " " + ttc
                    Next i
                End If
                Text2.Text = temp_c
            Else
                Text2.Text = "No!"
            End If
            
            Exit Do
        Else
            readTimes = readTimes + 1
            If readTimes > 999 Then
                Text2.Text = " 无回答!"
            End If
        End If
    Loop
    
    If Comm1.PortOpen Then Comm1.PortOpen = False
    
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -