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

📄 form1.frm

📁 是一款DA板卡的控制界面的原代码. 用VISUAL BASIC编程
💻 FRM
📖 第 1 页 / 共 4 页
字号:
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   12360
      TabIndex        =   49
      Top             =   3600
      Width           =   1095
   End
   Begin VB.Label Label11 
      Caption         =   "已运行时间:"
      Height          =   255
      Left            =   9480
      TabIndex        =   44
      Top             =   6480
      Width           =   1095
   End
   Begin VB.Label show_MV 
      Height          =   255
      Left            =   5280
      TabIndex        =   42
      Top             =   6480
      Width           =   855
   End
   Begin VB.Label show_PV 
      Height          =   255
      Left            =   3360
      TabIndex        =   41
      Top             =   6480
      Width           =   735
   End
   Begin VB.Label show_SV 
      Height          =   255
      Left            =   1560
      TabIndex        =   40
      Top             =   6480
      Width           =   735
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H0000C0C0&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H0000C0C0&
      Height          =   135
      Index           =   2
      Left            =   4440
      Shape           =   4  'Rounded Rectangle
      Top             =   6720
      Width           =   495
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H00FF0000&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H00FF0000&
      Height          =   135
      Index           =   1
      Left            =   2520
      Shape           =   4  'Rounded Rectangle
      Top             =   6720
      Width           =   495
   End
   Begin VB.Shape Shape1 
      BackColor       =   &H000000FF&
      BackStyle       =   1  'Opaque
      BorderColor     =   &H000000FF&
      FillColor       =   &H000000FF&
      Height          =   135
      Index           =   0
      Left            =   720
      Shape           =   4  'Rounded Rectangle
      Top             =   6720
      Width           =   495
   End
   Begin VB.Label runtime 
      Caption         =   "运行时间"
      Height          =   255
      Left            =   10680
      TabIndex        =   39
      Top             =   6480
      Width           =   855
   End
   Begin VB.Label Label12 
      Caption         =   "输出值PV"
      Height          =   255
      Left            =   2520
      TabIndex        =   38
      Top             =   6480
      Width           =   735
   End
   Begin VB.Label Label14 
      Caption         =   "给定值SV"
      Height          =   255
      Left            =   720
      TabIndex        =   37
      Top             =   6480
      Width           =   735
   End
   Begin VB.Label Label13 
      Caption         =   "控制值MV"
      Height          =   255
      Left            =   4440
      TabIndex        =   36
      Top             =   6480
      Width           =   855
   End
   Begin VB.Label Label15 
      BorderStyle     =   1  'Fixed Single
      Height          =   615
      Left            =   480
      TabIndex        =   35
      Top             =   6360
      Width           =   11175
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const strformat = "#0.00"

Dim SV, MV, Tc As Single              '过程参数,Tc:控制周期
Dim Kp, Ti, Td As Single              'PID参数
Dim MH, ML, K As Single               '一些与PID控制相关的设定参数:输出限幅、变增益控制K
Dim Tp, Kpp, L, Ts, m As Single         '对象参数

Dim MV0, MV1 As Single                'MV0-本次控制量;MV1-上一次控制量
Dim MV_his(20) As Single              '存放历史控制量,供计算pv使用,针对延时环节
Dim PV0, PV1 As Single                'PV0-本次测量值;PV1-上一次测量值
Dim e0, e1, de, el As Single          'e0,e1:不同时刻的误差值;el:误差上限
Dim Un, Un_1 As Single                '不完全微分PID中的微分项
Dim delay As Integer                  'MV延时多少个单元 delay=L/Ts

Dim minutes, seconds As Integer       '运行时间参数
Dim cmode As Integer                  '控制模式标志
Dim N_sh, Nc, N As Integer            '软件定时器:参数取得恰当的话满足N=Nc*N_sh

Dim x1(2), y1(2), x2(2), y2(2) As Integer         '一些绘图要用到的中间变量
Dim Y_SV, Y_PV, Y_MV As Integer
Dim count2 As Integer
Dim flag_run As Boolean
Dim Tab1, Tab2, totaltime As Integer            '* Tab1:点间隔;Tab2:刻度间隔;runtime:运行时间长度
Dim runmode As Integer                          '* runmode=1:16'  ;   runmode=2:11'

Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Private Sub bt_exit_Click()           '退出运行
     End
End Sub

Private Sub bt_refresh_Click()
      Dim i As Integer
      
      bt_refresh.Enabled = False       '*
      Picture1.Cls: drawCoordinate     ' 清除画面,重画坐标
      PV0 = 0: PV1 = 0
      MV0 = 0: MV1 = 0
      Un = 0: Un_1 = 0
      x1(0) = 500: y1(0) = 4800 - SV / 8 * 4000    'SV
      x1(1) = 500: y1(1) = 4800 - PV0 / 8 * 4000   'PV
      x1(2) = 500: y1(2) = 4800 - MV0 / 8 * 4000   'MV
      
      Timer2.Enabled = False: N_sh = 0: Nc = 0: N = 0
      
      minutes = 0: seconds = 0         'init statusbar
      runtime.Caption = CStr(Format(minutes, "00")) + ":" + CStr(Format(seconds, "00"))
      Label17.Caption = "当前模式:自动"
      
      flag_run = False: bt_run.Caption = "开始运行": bt_run.Enabled = True
      
      Command1.Caption = "修改"
      Command1.Enabled = True
      Command2.Enabled = False
      
      Option1.Value = True: Option2.Value = False
      MV = 0: edit_man.Text = CStr(Format(MV, strformat))
            
      For i = 0 To 20     '清除历史记录
        MV_his(i) = 0
      Next i
      
      Combo2.Enabled = True   '* 允许修改运行时间
            
End Sub

Private Sub bt_run_Click()
    Static run As Integer
    
   If Command1.Caption = "确定" Then
      MsgBox "无法运行:参数设置尚未确定,请检查!", 0 + 48 + 0 + 0, "运行错误"
   
   Else
      Combo2.Enabled = False
      If flag_run = False Then
         flag_run = True                                    '设运行开始标志
         x1(0) = 500: y1(0) = 4800 - SV / 8 * 4000    'SV   '首次运行起点初始化
         x1(1) = 500: y1(1) = 4800 - PV0 / 8 * 4000   'PV
         x1(2) = 500: y1(2) = 4800 - MV0 / 8 * 4000   'MV
         run = 0
        
      End If
    
      If run = 0 Then
       bt_run.Caption = "停止运行"
       run = 1
       Timer2.Enabled = True
      Else
       bt_run.Caption = "开始运行"
       run = 0
       Timer2.Enabled = False
     End If
     bt_refresh.Enabled = True
     
    End If
    
End Sub

Private Sub Combo1_Click()
      Select Case Combo1.ListIndex
      Case 0
        Timer2.Interval = 1000 * Ts
      Case 1
        Timer2.Interval = 200 * Ts
      Case 2
        Timer2.Interval = 100 * Ts
      End Select
      
End Sub

Private Sub Combo2_Click()                          '*
      Select Case Combo2.ListIndex
      Case 0
         Tab1 = 10: Tab2 = 500
         totaltime = 16
      Case 1
         Tab1 = 15: Tab2 = 600
         totaltime = 11
      End Select
      Picture1.Cls: drawCoordinate     ' 清除画面,重画坐标

End Sub                                             '*

Private Sub Command1_Click()         '参数设置——修改/确定按钮
    Static flag As Integer
    
    If flag = 0 Then
   '-------------------------------- 一键复用
       flag = 1
       Command1.Caption = "确定"
       Command2.Enabled = True
       If cmode = 1 Then
          change_allow                        '各编辑框允许被修改
       Else
          change_forbid
          edit_Tc.Enabled = True
          edit_Ts.Enabled = True
          Obj_L.Enabled = True
          Obj_Tp.Enabled = True
          Obj_Kp.Enabled = True
          
       End If
       
    Else
       flag = 0
       Command1.Caption = "修改"
       Command2.Enabled = False
       change_forbid
       load_value                    '各编辑框的当前值赋给相关变量
        
     End If
     
End Sub

Private Sub Command2_Click()           '参数设置——默认值按钮(用于恢复默认设定)
       
       PID(0).Text = CStr(Format(0.05, strformat))
       PID(1).Text = CStr(Format(2, strformat))
       PID(2).Text = CStr(Format(0.2, strformat))
       
       edit_Tc.Text = CStr(Format(5, strformat))
       edit_Ts.Text = CStr(Format(1, strformat))
       edit_K.Text = CStr(Format(0.25, strformat))
       
       Obj_L.Text = CStr(Format(20, strformat))
       Obj_Tp.Text = CStr(Format(40, strformat))
       Obj_Kp.Text = CStr(Format(1, strformat))
       
       edit_MH.Text = CStr(Format(6, strformat))
       edit_ML.Text = CStr(Format(1, strformat))
       
       
End Sub



Private Sub edit_man_LostFocus()
     If edit_man.Text = "" Then
       MsgBox "有参数未设定,请设定完全!", 0 + 48 + 0 + 0, "参数设置错误"
       edit_man.Text = CStr(Format(MV, strformat))
     End If
     
     If CSng(edit_man.Text) > 8 Then edit_man.Text = CStr(Format(8, strformat))
     ScrollBar1.Value = CInt(CSng(edit_man.Text) * 100)
     MV = CSng(edit_man.Text)
    
End Sub

Private Sub edit_sv_LostFocus()
     If edit_sv.Text = "" Then
       MsgBox "有参数未设定,请设定完全!", 0 + 48 + 0 + 0, "参数设置错误"
       edit_sv.Text = CStr(Format(SV, strformat))
     End If
     
     If CSng(edit_sv.Text) > 7 Then edit_sv.Text = CStr(Format(7, strformat))
     ScrollBar2.Value = CInt(CSng(edit_sv.Text) * 100)
     SV = CSng(edit_sv.Text)
     
End Sub

Private Sub Form_Initialize()
     
     '----------------------------------初始值设置-----------------
     
     Kp = 0.15: Ti = 2: Td = 0.2     'PID control items
     MH = 5.5: ML = 1
     el = 1: m = 15
     
     SV = 5: MV = 0
     PV0 = 0: PV1 = 0
     MV0 = 0: MV1 = 0
     e0 = 0: e1 = 0
     Un = 0: Un_1 = 0
     
     Tc = 5: K = 0.25
     Tp = 40: Ts = 1: L = 20: Kpp = 1
     Tab1 = 10: Tab2 = 500: totaltime = 16        '*
     
     delay = CInt(L / Ts)
     N_sh = 0: Nc = 0: N = 0
     '--------------------------------初始控制设置-----------------
     cmode = 1
     count2 = 0
     minutes = 0: seconds = 0
     flag_run = False
     
    '-------------------------------- 与时间相关 ------------------
     Timer2.Interval = 1000 * Ts
     Combo1.ListIndex = 2
     Combo2.ListIndex = 0             '* 运行16分钟
     
    '-------------------------------- 界面初始化 --------------------------
     
     runtime.Caption = CStr(Format(minutes, "00")) + ":" + CStr(Format(seconds, "00"))
     Option1.Value = True         '自动状态
     Option2.Value = False
     edit_man.Enabled = False
     edit_sv.Enabled = True
     ScrollBar1.Enabled = False
     ScrollBar2.Enabled = True

⌨️ 快捷键说明

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