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

📄 form2.frm

📁 用vb编写的工程控制程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            IMEMode         =   1  'ON
            Left            =   2280
            TabIndex        =   14
            Text            =   "0.8"
            Top             =   240
            Width           =   1095
         End
         Begin VB.Label Label8 
            Caption         =   "滤波参数a值:"
            Height          =   255
            Left            =   360
            TabIndex        =   15
            Top             =   360
            Width           =   1215
         End
      End
      Begin VB.Frame Frame1 
         Height          =   2055
         Left            =   -74760
         TabIndex        =   1
         Top             =   480
         Width           =   4935
         Begin VB.TextBox Text1 
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1200
            TabIndex        =   5
            Text            =   "1.5"
            Top             =   480
            Width           =   975
         End
         Begin VB.TextBox Text2 
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1200
            TabIndex        =   4
            Text            =   "2"
            Top             =   1440
            Width           =   975
         End
         Begin VB.TextBox Text3 
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   3720
            TabIndex        =   3
            Text            =   "0.05"
            Top             =   480
            Width           =   975
         End
         Begin VB.TextBox Text4 
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   3720
            TabIndex        =   2
            Text            =   "55"
            Top             =   1440
            Width           =   975
         End
         Begin VB.Label Label1 
            Caption         =   "Kp 值:"
            Height          =   255
            Left            =   480
            TabIndex        =   9
            Top             =   480
            Width           =   735
         End
         Begin VB.Label Label2 
            Caption         =   "Ti 值:"
            Height          =   255
            Left            =   360
            TabIndex        =   8
            Top             =   1560
            Width           =   735
         End
         Begin VB.Label Label3 
            Caption         =   "Td 值:"
            Height          =   495
            Left            =   2760
            TabIndex        =   7
            Top             =   480
            Width           =   735
         End
         Begin VB.Label Label5 
            Caption         =   "T值:"
            Height          =   375
            Left            =   2880
            TabIndex        =   6
            Top             =   1440
            Width           =   615
         End
      End
      Begin CoolButton.Button Button1 
         Height          =   495
         Left            =   -70920
         TabIndex        =   50
         Top             =   2640
         Width           =   735
         _ExtentX        =   1296
         _ExtentY        =   873
         BTYPE           =   3
         TX              =   "open"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BackColor       =   14215660
         BackOver        =   14215660
         ForeColor       =   0
         ForeOver        =   0
         MaskColor       =   12632256
         MPTR            =   1
         MICON           =   "Form2.frx":0074
         UseMaskColor    =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
         TTSBackColor    =   12648447
         TTSForeColor    =   0
         TTSFillColor1   =   16777215
         TTSFillColor2   =   12648447
         TTSIconType     =   2
         TTSStyleType    =   1
         TTSFillRect     =   1
         TTSShowTime     =   2
         TTSCloseTime    =   1000
         TTSTrans        =   100
         ToolTipString   =   ""
         ToolTipTitle    =   "系统提示"
      End
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private iFlow As Integer, mode As Integer, iTempEcho As Boolean
Sub LoadPropertySettings()  '载入窗体数据
    Dim i As Integer, Settings As String, Offset As Integer

    ' 载入端口设置
For i = 1 To 16
    cboPort.AddItem "Com" & Trim$(Str$(i))
Next i

' Load Speed Settings
cboSpeed.AddItem "110"
cboSpeed.AddItem "300"
cboSpeed.AddItem "600"
cboSpeed.AddItem "1200"
cboSpeed.AddItem "2400"
cboSpeed.AddItem "4800"
cboSpeed.AddItem "9600"
cboSpeed.AddItem "14400"
cboSpeed.AddItem "19200"
cboSpeed.AddItem "28800"
cboSpeed.AddItem "38400"
cboSpeed.AddItem "56000"
cboSpeed.AddItem "57600"
cboSpeed.AddItem "115200"
cboSpeed.AddItem "128000"
cboSpeed.AddItem "256000"

' 载入数据位设置
cboDataBits.AddItem "4"
cboDataBits.AddItem "5"
cboDataBits.AddItem "6"
cboDataBits.AddItem "7"
cboDataBits.AddItem "8"

' 载入奇偶检验设置
cboParity.AddItem "Even"
cboParity.AddItem "Odd"
cboParity.AddItem "None"
cboParity.AddItem "Mark"
cboParity.AddItem "Space"

' 载入停止位设置
cboStopBits.AddItem "1"
cboStopBits.AddItem "1.5"
cboStopBits.AddItem "2"

' 设置默认的设置

Settings = Form1.MSComm1.Settings

' 在大多数情况下,右边的大部分设置将为一个字符
' 除了可能出现的 1.5 停止位.
If InStr(Settings, ".") > 0 Then
    Offset = 2
Else
    Offset = 0
End If

cboSpeed.Text = Left$(Settings, Len(Settings) - 6 - Offset)
Select Case Mid$(Settings, Len(Settings) - 4 - Offset, 1)
Case "e"
    cboParity.ListIndex = 0
Case "m"
    cboParity.ListIndex = 1
Case "n"
    cboParity.ListIndex = 2
Case "o"
    cboParity.ListIndex = 3
Case "s"
    cboParity.ListIndex = 4
End Select

cboDataBits.Text = Mid$(Settings, Len(Settings) - 2 - Offset, 1)
cboStopBits.Text = Right$(Settings, 1 + Offset)
    
cboPort.ListIndex = Form1.MSComm1.CommPort - 1

optFlow(Form1.MSComm1.Handshaking).Value = True
Option1(Form1.mode - 1).Value = True
If Echo Then
    optEcho(1).Value = True
Else
    optEcho(0).Value = True
End If

End Sub

Private Sub Command1_Click()
    acpci.Kp = Text1.Text
    acpci.Ti = Text2.Text
    acpci.Td = Text3.Text
    acpci.T = Text4.Text / 1000#
    acpci.Sr = Text5.Text
    acpci.A = Text6.Text
   '---------------------
  Dim OldPort As Integer, ReOpen As Boolean

On Error Resume Next

Echo = iTempEcho
OldPort = Form1.MSComm1.CommPort
NewPort = cboPort.ListIndex + 1

If NewPort <> OldPort Then                   ' 如果端口号被更改, 关闭原来的端口。
    If Form1.MSComm1.PortOpen Then
           Form1.MSComm1.PortOpen = False
           ReOpen = True
    End If

    Form1.MSComm1.CommPort = NewPort          ' 设置新的端口号。
    
    If err = 0 Then
        If ReOpen Then
            Form1.MSComm1.PortOpen = True
           
        End If
    End If
        
    If err Then
        MsgBox Error$, 48
        Form1.MSComm1.CommPort = OldPort
        Exit Sub
    End If
End If


Form1.MSComm1.Settings = Trim$(cboSpeed.Text) & "," & Left$(cboParity.Text, 1) _
    & "," & Trim$(cboDataBits.Text) & "," & Trim$(cboStopBits.Text)

If err Then
    MsgBox Error$, 48
    Exit Sub
End If

Form1.MSComm1.Handshaking = iFlow
    Form1.mode = mode
     CMD = &H22 '控制命令 输出
      D1 = Form1.mode
      D2 = 0
     Call send_data(CMD, D1, D2)

If err Then
    MsgBox Error$, 48
    Exit Sub
End If
'----------------保存到注册表-------
'???????????
    Unload Me
    
End Sub

Private Sub Command2_Click()
    On Error Resume Next
    openlog.Action = 0
    openlog.DialogTitle = "保存路径"
     openlog.FileName = "  "
    Dialog.ShowOpen
     openlog.CancelError = True
    acpci.filepath = Dialog.FileName
    filepath.Text = acpci.filepath
   
    
     
End Sub


Private Sub Command3_Click()
 Unload Me

End Sub

Private Sub Command4_Click()
    acpci.Kp = 1.6
    acpci.Ti = 1.5
    acpci.Td = 0
    acpci.T = 0.05
    acpci.Sr = 200
     acpci.A = 0.8

    Unload Me

    
End Sub

Private Sub Form_Load()
    LoadPropertySettings  '----------------
   Text1.Text = Format(acpci.Kp, "##0.0###")
    Text2.Text = Format(acpci.Ti, "##0.0###")
   Text3.Text = Format(acpci.Td, "##0.0###")
    Text4.Text = Format(acpci.T * 1000, "##0.0###")
   Text5.Text = Format(acpci.Sr, "##0.0###")
    Text6.Text = Format(acpci.A, "##0.0###")
    filepath.Text = acpci.filepath
   Form1.Enabled = False
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Form1.Enabled = True
End Sub

Private Sub optFlow_Click(Index As Integer)
    iFlow = Index
End Sub

Private Sub Option1_Click(Index As Integer)
    mode = Index + 1
End Sub

Private Sub optEcho_Click(Index As Integer)
If Index = 1 Then
    iTempEcho = True
Else
    iTempEcho = False
End If
End Sub
   
Private Sub Button1_Click()
 On Error Resume Next
  
   openlog.DialogTitle = "保存图形"
   openlog.Filter = "所有文件 (*.*)|*.*"
    openlog.CancelError = True
      openlog.InitDir = acpci.filepath & Tempname
      openlog.ShowOpen
       If err = cdlCancel Then
       cmdsave.Enabled = True
       Else
       cmdsave.Enabled = False
       acpci.OpenFile = openlog.FileName
    End If
End Sub

⌨️ 快捷键说明

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