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

📄 main.frm

📁 VB代码
💻 FRM
📖 第 1 页 / 共 4 页
字号:

Private Sub Cmd_DeviceSelect_Click()
    Cmd_DeviceSelect.Enabled = False
    Call MNU_Device_DeviceSelect_Click
    Cmd_DeviceSelect.Enabled = True
    
End Sub

Private Sub Cmd_DeviceSignature_Click()
    Cmd_DeviceSignature.Enabled = False
    
    Call MNU_ReadDeviceSignature_Click
    Cmd_DeviceSignature.Enabled = True
End Sub

Private Sub Cmd_DeviceVerify_Click()
    Cmd_DeviceVerify.Enabled = False
    Call MNU_Device_Verify_Click
    Cmd_DeviceVerify.Enabled = True
End Sub

Private Sub Cmd_FileOpen_Click()
    Cmd_FileOpen.Enabled = False
    Call MNU_File_FileOpen_Click
    Cmd_FileOpen.Enabled = True
End Sub

Private Sub Cmd_FileSave_Click()
    Cmd_FileSave.Enabled = False
    Call MNU_File_FileSave_Click
    Cmd_FileSave.Enabled = True
End Sub

Private Sub CmdTestDelay_Click()
                                                                                     Dim iCount  As Integer
    
    CmdTestDelay.Enabled = False
 '   Txt_SysInfoDisp.Text = "Start Delay"
    'Call Delay(10000)
    'Call Delay(2048)
    For iCount = 0 To 100 Step 1
       Call Delay(60)           '入口参数60以上时定时正确
    Next iCount
    
  '  Txt_SysInfoDisp.Text = "Delay End"
    CmdTestDelay.Enabled = True
    

End Sub

Private Sub CmdVerifyMuchTimes_Click()
    Dim ucVerifyTimeCount As Byte
    Dim ucCount As Byte
    
 '   FrmMain.lblVerifyCountDisp.Visible = True
 '   CmdVerifyMuchTimes.Enabled = False
  '  ucVerifyTimeCount = CByte(FrmMain.TxtVerifyTimesInput.Text)
   ' For ucCount = 0 To ucVerifyTimeCount Step 1
    '    FrmMain.lblVerifyCountDisp.Caption = CStr(ucCount)
    '    MNU_Device_Verify_Click
    'Next ucCount
    'FrmMain.lblVerifyCountDisp.Visible = False
  '  CmdVerifyMuchTimes.Enabled = True
    
End Sub

Private Sub Form_Load()
    Dim bReturnValue As Boolean
    Dim ucComPortSetting As Byte
    
    PGM_Register.AppName = App.Title
    PGM_Register.Section = "SysInfo"
    PGM_Register.Key = "DeviceID"
    
    Call PGM_Register.RegGet
    iCurrentDeviceID = Val(PGM_Register.Setting)
    'iCurrentDeviceID = c_DeviceCompleteIDNumber_AT89C2051
    Call InitProgramDeviceLib
    
    
    PGM_Register.Key = "ComPortSetting"
    Call PGM_Register.RegGet
    ucComPortSetting = Val(PGM_Register.Setting)
    
    bComInitStatus = False
    'bReturnValue = SetComPortNumber(5)
    bReturnValue = SetComPortNumber(ucComPortSetting)
 '   bComInitStatus = bReturnValue
    
    'MainForm.ComProgram.PortOpen = True
    Me.Show
  
  '  If (TestProgramDeviceHardWare()) Then
            
  '  Else
  '      FrmStart.LblSysInfo.Visible = False
  '      FrmStart.lblErrDisp.Visible = True
  '      FrmStart.CmdCheckErr.Visible = True
  '      FrmStart.Show vbModal, FrmMain
        
  '  End If
    
    Call InitSysForNewDevice
    Call RefreshPGMSysInfo
    
    UserDefineAutoExecOption.bReadDeviceSignature = True
    UserDefineAutoExecOption.bEraseChip = True
    UserDefineAutoExecOption.bCheckBank = True
    UserDefineAutoExecOption.bProgramCode = True
    UserDefineAutoExecOption.bVerify = True
    UserDefineAutoExecOption.bLockBits = True
    
    ucCurrentLockLevel = c_LockType_LockLevel3
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    PGM_Register.AppName = App.Title
    PGM_Register.Section = "SysInfo"
    
    PGM_Register.Key = "DeviceID"
    PGM_Register.Setting = Str(iCurrentDeviceID)
    Call PGM_Register.RegSave
    
    PGM_Register.Key = "ComPortSetting"
    PGM_Register.Setting = Str(ucCurrentComPortNumber)
    Call PGM_Register.RegSave
    
End Sub

Private Sub MNU_AutoExec_Click()
    Dim bReturnValue As Boolean
    Dim ucSignatureDataBuff As String
    Dim iUserSelectValue As Integer
    Dim bVerifyResult As Boolean

    
    FrmMain.LblOperationInfoDisp.Caption = "开始执行自动编程操作......"
    
    If (UserDefineAutoExecOption.bReadDeviceSignature) Then
    
        FrmMain.LblOperationInfoDisp.Caption = "开始读取设备特征字......"
        bReturnValue = CMD_ReadSignature(ucSignatureDataBuff)
        If (StrComp(ucSignatureDataBuff, sCurrentDeviceSignatureString) <> 0) Then
            iUserSelectValue = MsgBox("特征字与编程器件不符,是否退出?", vbQuestion + vbYesNo + vbDefaultButton1, "请选择")
            If (iUserSelectValue = vbYes) Then
                GoTo lblFunctionEnd
            End If
        End If
        FrmMain.LblOperationInfoDisp.Caption = "读取到的设备特征字为:" & ucSignatureDataBuff
        
    End If
    
    If (UserDefineAutoExecOption.bEraseChip) Then
    
        FrmMain.LblOperationInfoDisp.Caption = "开始进行芯片擦除操作......"
        If (CMD_EraseChip()) Then
            FrmMain.LblOperationInfoDisp.Caption = "芯片擦除操作成功。"
        Else
            FrmMain.LblOperationInfoDisp.Caption = "芯片擦除操作失败!"
            GoTo lblFunctionEnd
        End If
        
    End If
    
    If (UserDefineAutoExecOption.bCheckBank) Then
    
        FrmMain.LblOperationInfoDisp.Caption = "开始查空操作"
        If (CMD_CheckBank(0, lMaxCodeLength)) Then
            FrmMain.LblOperationInfoDisp.Caption = "器件为空"
        Else
            FrmMain.LblOperationInfoDisp.Caption = "器件非空!"
            GoTo lblFunctionEnd
        End If
        
    End If
    
    If (UserDefineAutoExecOption.bProgramCode) Then
        
        FrmMain.LblOperationInfoDisp.Caption = "开始进行编程操作...编程缓冲区的起始6单元为:" _
        & CStr_Hex(ucDataBuff(0)) & " " & CStr_Hex(ucDataBuff(1)) & " " & CStr_Hex(ucDataBuff(2)) _
        & " " & CStr_Hex(ucDataBuff(3)) & " " & CStr_Hex(ucDataBuff(4)) & " " & CStr_Hex(ucDataBuff(5))
    
        
        If (CMD_WriteProgramMemory(lMaxCodeLength)) Then
        
            FrmMain.LblOperationInfoDisp.Caption = "编程操作成功."
        Else
            FrmMain.LblOperationInfoDisp.Caption = "编程操作失败!"
            GoTo lblFunctionEnd
        End If
        
    End If
    
    If (UserDefineAutoExecOption.bVerify) Then
        
        FrmMain.LblOperationInfoDisp.Caption = "开始进行编程数据的校验操作......"
        bVerifyResult = CMD_PageVerifyProgramMemory(lMaxCodeLength)
        If (bVerifyResult) Then
            FrmMain.LblOperationInfoDisp.Caption = "校验通过。"
        Else
            FrmMain.LblOperationInfoDisp.Caption = "校验失败!"
            GoTo lblFunctionEnd
        End If
        
    End If
    
    If (UserDefineAutoExecOption.bLockBits) Then
    
         If (ucCurrentLockLevel = c_LockType_LockLevel1) Then
             
             FrmMain.LblOperationInfoDisp.Caption = "进行 1 级加密操作"
             If (CMD_WriteLockBits(c_LockType_LockLevel1)) Then
                 FrmMain.LblOperationInfoDisp.Caption = "1 级加密操作成功."
             Else
                 FrmMain.LblOperationInfoDisp.Caption = "1 级加密位操作失败!"
             End If
         End If
         
        If (ucCurrentLockLevel = c_LockType_LockLevel2) Then
            FrmMain.LblOperationInfoDisp.Caption = "进行 2 级加密操作"
            If (CMD_WriteLockBits(c_LockType_LockLevel2)) Then
                FrmMain.LblOperationInfoDisp.Caption = "2 级加密操作成功"
            Else
                FrmMain.LblOperationInfoDisp.Caption = "2 级加密操作失败!"
            End If
        End If
         
        If (ucCurrentLockLevel = c_LockType_LockLevel3) Then
        
            FrmMain.LblOperationInfoDisp.Caption = "进行 3 级加密"
            If (CMD_WriteLockBits(c_LockType_LockLevel3)) Then
            
                FrmMain.LblOperationInfoDisp.Caption = "3 级加密操作成功。"
            Else
                FrmMain.LblOperationInfoDisp.Caption = "3 级加密操作失败!"
            End If
            
         End If
         
    End If
    
lblFunctionEnd:
   
End Sub

Private Sub MNU_Device_CheckBank_Click()
    Dim bReturnValue As Boolean
    Dim lStartAddress As Long
    Dim lCheckBankDataLength As Long
    Dim ucSignatureDataBuff As String
    Dim iUserSelectValue As Integer
  
    
    FrmMain.LblOperationInfoDisp.Caption = "开始查空操作"
    
    lStartAddress = 0
    lCheckBankDataLength = lMaxCodeLength
    
    If (bReadDeviceSignatureFlag = False) Then
        bReturnValue = CMD_ReadSignature(ucSignatureDataBuff)
        If (StrComp(ucSignatureDataBuff, sCurrentDeviceSignatureString) <> 0) Then
            iUserSelectValue = MsgBox("读取到的设备特征字与编程器件不符,是否退出?", vbQuestion + vbYesNo + vbDefaultButton1, "请选择")
            If (iUserSelectValue = vbNo) Then
                Call CMD_CheckBank(lStartAddress, lCheckBankDataLength)
                FrmMain.LblOperationInfoDisp.Caption = "完成查空操作"
            End If
        Else
            bReadDeviceSignatureFlag = True
            lblDeviceName.ForeColor = vbBlue
            

            Call CMD_CheckBank(lStartAddress, lCheckBankDataLength)
            FrmMain.LblOperationInfoDisp.Caption = "完成查空操作"
        End If
    Else
        Call CMD_CheckBank(lStartAddress, lCheckBankDataLength)
        FrmMain.LblOperationInfoDisp.Caption = "完成查空操作"
    End If

End Sub

Private Sub MNU_Device_DeviceSelect_Click()
    Dim iOldDeviceID As Integer
    
    FrmMain.LblOperationInfoDisp.Caption = "开始执行选择编程芯片操作"
    
    iOldDeviceID = iCurrentDeviceID
    FrmSelectDevice.Show vbModal, FrmMain
    
    If (iOldDeviceID <> iCurrentDeviceID) Then
        Call InitSysForNewDevice
    End If
End Sub

Private Sub MNU_Device_Erase_Click()
    Dim bReturnValue As Boolean
    Dim ucSignatureDataBuff As String
    Dim iUserSelectValue As Integer
    
    FrmMain.LblOperationInfoDisp.Caption = "开始擦除芯片"
    
    If (bReadDeviceSignatureFlag = False) Then
        bReturnValue = CMD_ReadSignature(ucSignatureDataBuff)
        If (StrComp(ucSignatureDataBuff, sCurrentDeviceSignatureString) <> 0) Then
            iUserSelectValue = MsgBox("读取到的设备特征字与编程器件不符,是否退出?", vbQuestion + vbYesNo + vbDefaultButton1, "请选择")
            If (iUserSelectValue = vbNo) Then
                If (CMD_EraseChip()) Then
                    FrmMain.LblOperationInfoDisp.Caption = "擦除操作成功。"
                Else
                    FrmMain.LblOperationInfoDisp.Caption = "擦除操作失败!"
                End If
            End If
        Else
            bReadDeviceSignatureFlag = True
            lblDeviceName.ForeColor = vbBlue
            

            If (CMD_EraseChip()) Then
                    FrmMain.LblOperationInfoDisp.Caption = "擦除操作成功。"
                Else
                    FrmMain.LblOperationInfoDisp.Caption = "擦除操作失败!"
            End If
        End If
    Else
        If (CMD_EraseChip()) Then
                FrmMain.LblOperationInfoDisp.Caption = "擦除操作成功。"
        Else
                FrmMain.LblOperationInfoDisp.Caption = "擦除操作失败!"
        End If
    End If
End Sub

Private Sub MNU_Device_Lock_Click()
    Dim bReturnValue As Boolean
    Dim ucSignatureDataBuff As String
    Dim iUserSelectValue As Integer
     
    If (bReadDeviceSignatureFlag = False) Then
        bReturnValue = CMD_ReadSignature(ucSignatureDataBuff)
        If (StrComp(ucSignatureDataBuff, sCurrentDeviceSignatureString) <> 0) Then

            iUserSelectValue = MsgBox("读取到的设备特征字与编程器件不符,是否退出?", vbQuestion + vbYesNo + vbDefaultButton1, "请选择")
            If (iUserSelectValue = vbNo) Then
                FrmMain.LblOperationInfoDisp.Caption = "加密操作终止"
            End If
        Else
            bReadDeviceSignatureFlag = True
            lblDeviceName.ForeColor = vbBlue
            
            FrmMain.LblOperationInfoDisp.Caption = "开始写加密位1"
            If (CMD_WriteLockBits(c_LockType_LockLevel1)) Then
                FrmMain.LblOperationInfoDisp.Caption = "写加密位1操作成功。"
            Else
                FrmMain.LblOperationInfoDisp.Caption = "写加密位1操作失败!"
            End If
            
            FrmMain.LblOperationInfoDisp.Caption = "开始写加密位2"
            If (CMD_WriteLockBits(c_LockType_LockLevel2)) Then
                FrmMain.LblOperationInfoDisp.Caption = "写加密位2操作成功。"
            Else
                FrmMain.LblOperationInfoDisp.Caption = "写加密位2操作失败!"
            End If
            
            FrmMain.LblOperationInfoDisp.Caption = "开始写加密位3"
            If (CMD_WriteLockBits(c_LockType_LockLevel3)) Then
                FrmMain.LblOperationInfoDisp.Caption = "写加密位3操作成功。"
            Else
                FrmMain.LblOperationInfoDisp.Caption = "写加密位3操作失败!"
            End If
            

⌨️ 快捷键说明

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