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

📄 dlgextern.frm

📁 CH375作为usb从设备时的例子程序和调试工具 vb.vc
💻 FRM
字号:
VERSION 5.00
Begin VB.Form DLGEXTERN 
   Caption         =   "扩展命令"
   ClientHeight    =   5175
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7785
   LinkTopic       =   "Form1"
   ScaleHeight     =   5175
   ScaleWidth      =   7785
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Recieve 
      Caption         =   "接收"
      Height          =   375
      Left            =   4980
      TabIndex        =   8
      Top             =   3720
      Width           =   1065
   End
   Begin VB.CommandButton OnButtonSend 
      Caption         =   "发送"
      Height          =   375
      Left            =   3900
      TabIndex        =   7
      Top             =   3720
      Width           =   1065
   End
   Begin VB.TextBox IBuff 
      Height          =   1725
      Left            =   360
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   6
      Text            =   "DLGEXTERN.frx":0000
      Top             =   1710
      Width           =   6855
   End
   Begin VB.TextBox Para4 
      Height          =   375
      Left            =   6210
      TabIndex        =   5
      Text            =   "Text6"
      Top             =   1170
      Width           =   975
   End
   Begin VB.TextBox Para3 
      Height          =   375
      Left            =   4460
      TabIndex        =   4
      Text            =   "Text5"
      Top             =   1170
      Width           =   975
   End
   Begin VB.TextBox Para2 
      Height          =   375
      Left            =   2715
      TabIndex        =   3
      Text            =   "Text4"
      Top             =   1170
      Width           =   975
   End
   Begin VB.TextBox Para1 
      Height          =   375
      Left            =   970
      TabIndex        =   2
      Text            =   "Text3"
      Top             =   1170
      Width           =   975
   End
   Begin VB.TextBox ILeng 
      Height          =   375
      Left            =   6210
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   690
      Width           =   975
   End
   Begin VB.TextBox ICmdcode 
      Height          =   375
      Left            =   2715
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   690
      Width           =   975
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      Caption         =   "参数4"
      Height          =   180
      Left            =   5595
      TabIndex        =   14
      Top             =   1260
      Width           =   450
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "参数3"
      Height          =   180
      Left            =   3850
      TabIndex        =   13
      Top             =   1260
      Width           =   450
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "参数2"
      Height          =   180
      Left            =   2105
      TabIndex        =   12
      Top             =   1260
      Width           =   450
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "参数1"
      Height          =   180
      Left            =   360
      TabIndex        =   11
      Top             =   1260
      Width           =   450
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "长度(<=38H)"
      Height          =   180
      Left            =   5070
      TabIndex        =   10
      Top             =   750
      Width           =   990
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "输入命令码 / 输出状态码"
      Height          =   180
      Left            =   360
      TabIndex        =   9
      Top             =   750
      Width           =   2070
   End
End
Attribute VB_Name = "DLGEXTERN"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command2_Click()
    'CXRAMPage m_xram;
    Dim Buffer(MAX_DATA_SIZE * 2) As Byte
    Dim Leng As Long
    Dim tems As String
    If (CH375DBG_Opened = False) Then
        MsgBox "设备未打开", vbOKCancel, "CH37XDBG"
        Exit Sub
    End If
   ' 写出命令块
        Leng = Len(USB_UP_PKT)
        If (CH375ReadData(CH375DBG_Index, Up, Leng) = True) Then
           ' 读取应答块
            If (Up.mCommandNot = Down.mCommandNot) Then   ' 操作成功
                '状态码
                m_Comm = Hex(Up.mStatus)
                '返回码1
                Text3.Text = hex2bit(Up.mReserved(0))
                '返回码2
                Text4.Text = hex2bit(Up.mReserved(1))
                '返回码3
                Text5.Text = hex2bit(Up.mReserved(2))
                '返回码4
                Text6.Text = hex2bit(Up.mReserved(3))
                '返回长度
                m_Len = hex2bit(Up.mLength)
                tems = ""
                For i = 0 To Up.mLength - 1
                    tems = hex2bit(Up.mBuffer(i))     ' 返回数据
                Next i
                Text7.Text = tems
            Else
                MsgBox "返回状态错误!", vbOKCancel, "CH37XDBG"
                Exit Sub
            End If
        Else
            MsgBox "读失败!", vbOKCancel, "CH37XDBG"
        End If
End Sub

Private Sub OnButtonSend_Click()
Dim m_Comm  As String
Dim m_Len  As String
Dim m_Para1  As String
Dim m_Para2  As String
Dim m_Para3  As String
Dim m_Para4  As String
Dim m_Buff  As String
Dim tems As String
    Dim Buffer(120) As Byte
    Dim Length As Byte
    Dim temh As Byte
    Dim Leng As Long
    m_Comm = Trim(Text1.Text)
    m_Len = Trim(Text2.Text)
    m_Para1 = Trim(Text3.Text)
    m_Para2 = Trim(Text4.Text)
    m_Para3 = Trim(Text5.Text)
    m_Para4 = Trim(Text6.Text)
    m_Buff = Trim(Text7.Text)
    If (CH375DBG_Opened = False) Then
        MsgBox "设备未打开", vbOKCancel, "CH37XDBG"
        Exit Sub
    End If
    '命令码
    If (Len(m_Comm) > 0) Then
        Down.mCommand = hextobcd(m_Comm)
    Else
        Down.mCommand = 0
    End If
    '反命令码
    Down.mCommandNot = Not Down.mCommand
    '参数1
    If (Len(m_Para1) > 0) Then
        Down.u.mByte(0) = hextobcd(m_Para1)
    Else
        Down.u.mByte(0) = 0
    End If
    '参数2
    If (Len(m_Para2) > 0) Then
        Down.u.mByte(1) = hextobcd(m_Para2)
    Else
        Down.u.mByte(1) = 0
    End If
    '参数3
    If (Len(m_Para3) > 0) Then
        Down.u.mByte(2) = hextobcd(m_Para3)
    Else
        Down.u.mByte(3) = 0
    End If
    '参数4
    If (Len(m_Para4) > 0) Then
        Down.u.mByte(4) = hextobcd(m_Para4)
    Else
        Down.u.mByte(4) = 0
    End If
    '长度
    If (Len(m_Len) > 0) Then
        Down.mLength = hextobcd(m_Len)
    Else
        Length = 0
    End If
    
    If (m_buf <> "") Then
        For i = 0 To Down.mLength - 1
            tems = Trim(Mid(m_buf, (i * 2 + 1), 2))
            If tems = "" Then
               temh = 0
            Else
               temh = hextobcd(tems)
            End If
            Down.mBuffer(i) = temh
        Next i
    End If
    'len = mOFFSET( USB_DOWN_PKT, mBuffer ) + down.mLength
    Leng = Len(USB_DOWN_PKT) + Down.mLength
    
    '发送数据
    If (CH375Writedata(CH375DBG_Index, Down, Leng) = False) Then
        MsgBox "发送失败", vbOKCancel, "CH37XDBG"
        Exit Sub
    End If
    
End Sub

Private Sub Text7_KeyPress(KeyAscii As Integer)
  Text7.SelLength = 1
  If KeyAscii > 96 And KeyAscii < 123 Then
     KeyAscii = KeyAscii - 32  '字母小写转成大写
  End If
  If KeyAscii > 70 And KeyAscii < 91 Or (KeyAscii >= 0 And KeyAscii <= 7) Or (KeyAscii >= 11 And KeyAscii <= 12) _
      Or (KeyAscii >= 14 And KeyAscii <= 47) Or (KeyAscii >= 58 And KeyAscii <= 64) Or (KeyAscii >= 91 And KeyAscii <= 96) _
     Or (KeyAscii >= 123 And KeyAscii <= 127) Then   '非有效进制值为0
     KeyAscii = 48
  End If
  If KeyAscii <> 8 And KeyAscii <> 13 Then
    Text7.SelText = Chr(KeyAscii)   '将输入的字符显示出来
    KeyAscii = 0   '屏蔽系统显示前面 Text4.SelText = Chr(KeyAscii)已经显示出来
  End If
End Sub

⌨️ 快捷键说明

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