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

📄 zlgcomport.frm

📁 嵌入式系统中一些外围设备驱动示例程序集
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Top             =   2685
         Width           =   735
      End
      Begin VB.Label Label3 
         Caption         =   "下载数据"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         Left            =   480
         TabIndex        =   2
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "起始地址"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         Left            =   480
         TabIndex        =   1
         Top             =   405
         Width           =   735
      End
   End
   Begin VB.Label Label8 
      Caption         =   "端口"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   360
      TabIndex        =   18
      Top             =   4185
      Width           =   375
   End
End
Attribute VB_Name = "FrmZlgComPort"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'            /*
'             *****************************************************************************
'             *
'             *  Copyright(c) 2002, 周立功单片机发展有限公司
'             *                   All rights reserved.
'             *
'             *     文   件: FrmZlgComPort
'             *
'             *     摘   要: 本程序主要是通过调用ZmpCom.dll动态连接库函数对 DP-51学习板
'             *              24WC02时行读写控制。
'             *
'             *
'             *     创建日期:  2002年10月26日
'             *
'             ******************************************************************************
'             */



Private Sub Ch1_Click()
        '------------------------------------------------------------
        '说明:  判断是否是输入十六时制数,而设定文本框数据接授长度
        '------------------------------------------------------------
    TDown = ""
    If Ch1.Value = 1 Then
      TDown.MaxLength = 256 * 3
    Else
      TDown.MaxLength = 256
    End If
End Sub

Private Sub ComExit_Click()
  Unload Me                                                      '退出
End Sub
Private Sub ComOpenPort_Click()
        '------------------------------------------------------------
        '说明:  打开及关闭串口
        '------------------------------------------------------------

        If ComOpenPort.Caption = "&O.打开端口" Then
               i = ComPro.ListIndex + 1
                stbl = SetCommPort(i)         '设置端口
                If stbl = False Then
                    MsgBox "请检查端口设置是否正确!", vbInformation, "提示"
                    Exit Sub
                End If
                
                st = OpenPort()                                  '打开串口
                If st <> 0 Then
                    MsgBox "打开串口失败!", vbInformation, "提示"
                    PortOpen = False
                    Exit Sub
                End If
               PortOpen = True
               ComOpenPort.Caption = "&C.关闭端口"
        Else
               st = ClosePort()
               If st <> 0 Then
                    MsgBox "关闭端口失败!", vbInformation, "提示"
                    Exit Sub
                End If
               ComOpenPort.Caption = "&O.打开端口"
        End If
            
        
End Sub

Private Sub ComRead_Click()
        '------------------------------------------------------------
        '说明:  先判断输入的数据是否符合要求,然后传给读函数
        '------------------------------------------------------------
        Dim BgnAdr_L As Integer
        Dim BgnAdr_H As Integer
        Dim nLen  As Integer
        Dim Str As String
        Dim str2 As String   '用于接收返回值
        
  On Error GoTo HaveErr
        If PortOpen = False Then
            MsgBox "端口没有打开!", vbInformation, "提示"
            Exit Sub
        End If
        
        If Len(Trim(TIAdd)) = 0 Then
            MsgBox "请输入读数据的起始地址!", vbInformation, "提示"
            Exit Sub
        End If
        
        If Len(Trim(Tlen)) = 0 Then
            MsgBox "请输入数据长度!", vbInformation, "提示"
            Exit Sub
        End If
        
        If Val(Trim(Tlen)) > 256 Then
            MsgBox "最多只能读取256个数据!", vbInformation, "提示"
            Exit Sub
        End If
        BgnAdr_L = HtoD(Trim(TDAdd))
        BgnAdr_H = 0
        nLen = Val(Trim(Tlen))
        
        str2 = ""
        str2 = ReadE2PRom(BgnAdr_L, BgnAdr_H, nLen)
        
        If Len(str2) <> 0 Then
          TIncept = ""
            If Ch2.Value = 1 Then
              TIncept = StoH(str2)
            Else
              TIncept = str2
            End If
            MsgBox "读E2PROM数据成功!", vbInformation, "提示"
        Else
           MsgBox "读E2PROM数据出错!", vbInformation, "提示"
        End If
        
      Exit Sub
HaveErr:
        MsgBox "对不起!系统出错,请重新操作。", vbInformation, "提示"
End Sub

Private Sub ComWrite_Click()
        '------------------------------------------------------------
        '说明:  先判断输入的数据是否符合要求,然后传给写函数
        '------------------------------------------------------------
        Dim BgnAdr_L As Integer
        Dim BgnAdr_H As Integer
        Dim Str As String
        Dim str2 As String
        
 On Error GoTo HaveErr
        If PortOpen = False Then
            MsgBox "端口没有打开!", vbInformation, "提示"
            Exit Sub
        End If
        
        If Len(Trim(TDAdd)) = 0 Then
            MsgBox "请输入写数据的起始地址!", vbInformation, "提示"
            Exit Sub
        End If
        
        If Len(Trim(TDown)) = 0 Then
            MsgBox "请输入要写入的数据!", vbInformation, "提示"
            Exit Sub
        End If
        
        BgnAdr_L = HtoD(Trim(TDAdd))
        BgnAdr_H = 0
        
         If Ch1.Value = 1 Then
           Str = HtoS(TDown)
         Else
           Str = Trim(TDown)
         End If
        
        st = WriteE2PRom(BgnAdr_L, BgnAdr_H, Str)
        If st <> 0 Then
            MsgBox "写数据有误,请重新操作!", vbInformation, "提示"
            Exit Sub
        End If
          MsgBox "写E2PROM数据成功!", vbInformation, "提示"
          
          
      Exit Sub
HaveErr:
        MsgBox "对不起!系统出错,请重新操作。", vbInformation, "提示"
        
End Sub

Private Sub Form_Load()

        '------------------------------------------------------------
        '说明:  初始化端口
        '------------------------------------------------------------
            ComPro.Clear
            ComPro.AddItem (" COM1")
            ComPro.AddItem (" COM2")
            ComPro.AddItem (" COM3")
            ComPro.AddItem (" COM4")
            ComPro.ListIndex = 0
          
                stbl = SetCommBaud(9600)                '波特率
                If stbl = False Then
                    MsgBox "请检查波特率设置是否正确!", vbInformation, "提示"
                End If
                
End Sub

Private Sub Form_Unload(Cancel As Integer)
        '------------------------------------------------------------
        '说明:  关闭串口释放串口资源
        '------------------------------------------------------------
        st = ClosePort()
End Sub



Private Sub TDAdd_KeyPress(KeyAscii As Integer)
        '------------------------------------------------------------
        ' 判断输入是否为有效字符符(十六进制数)
        '------------------------------------------------------------

    Select Case KeyAscii
       Case 8
       Case 48 To 57
       Case 65 To 70
       Case 97 To 102
       Case Else
       KeyAscii = 0
     End Select

End Sub
Private Sub TDown_KeyPress(KeyAscii As Integer)
        '------------------------------------------------------------
        ' 判断输入是否为有效字符符(十六进制数),及空格
        '------------------------------------------------------------
 If Ch1.Value = 1 Then
    Select Case KeyAscii
       Case 8
       Case 32              '空格
       Case 48 To 57
       Case 65 To 70
       Case 97 To 102
       Case Else
       KeyAscii = 0
     End Select
  End If
End Sub

Private Sub TIAdd_KeyPress(KeyAscii As Integer)
        '------------------------------------------------------------
        ' 判断输入是否为有效字符符(十六进制数)
        '------------------------------------------------------------
    Select Case KeyAscii
       Case 8
       Case 48 To 57
       Case 65 To 70
       Case 97 To 102
       Case Else
       KeyAscii = 0
     End Select
End Sub

Private Sub TIncept_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

Private Sub Tlen_KeyPress(KeyAscii As Integer)
        '------------------------------------------------------------
        ' 判断输入是否为有效字符符(十进制数)
        '------------------------------------------------------------
    Select Case KeyAscii
       Case 8
       Case 48 To 57
       Case Else
       KeyAscii = 0
     End Select
End Sub

⌨️ 快捷键说明

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