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

📄 frmconfig.frm

📁 VB串口 云台镜头控制系统 完整源码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmConfig 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "控制端口的设置"
   ClientHeight    =   4305
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   6135
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4305
   ScaleWidth      =   6135
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame fraHole 
      Height          =   3975
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   5655
      Begin VB.CommandButton CancelButton 
         Caption         =   "取消"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   350
         Left            =   4320
         TabIndex        =   16
         Top             =   840
         Width           =   1215
      End
      Begin VB.OptionButton Option1 
         Caption         =   "通过串口发送控制码"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   120
         TabIndex        =   15
         Top             =   240
         Value           =   -1  'True
         Width           =   2055
      End
      Begin VB.Frame fraComm 
         Height          =   2655
         Left            =   360
         TabIndex        =   4
         Top             =   600
         Width           =   3735
         Begin VB.ComboBox cmbBoudRate 
            Height          =   315
            ItemData        =   "frmConfig.frx":0000
            Left            =   1080
            List            =   "frmConfig.frx":0002
            Style           =   2  'Dropdown List
            TabIndex        =   9
            Top             =   240
            Width           =   2415
         End
         Begin VB.ComboBox cmbParity 
            Height          =   315
            Left            =   1080
            Style           =   2  'Dropdown List
            TabIndex        =   8
            Top             =   720
            Width           =   2415
         End
         Begin VB.ComboBox cmbDatabits 
            Height          =   315
            Left            =   1080
            Style           =   2  'Dropdown List
            TabIndex        =   7
            Top             =   1200
            Width           =   2415
         End
         Begin VB.ComboBox cmbStopbits 
            Height          =   315
            Left            =   1080
            Style           =   2  'Dropdown List
            TabIndex        =   6
            Top             =   1680
            Width           =   2415
         End
         Begin VB.ComboBox cmbCom 
            Height          =   315
            Left            =   1080
            Style           =   2  'Dropdown List
            TabIndex        =   5
            Top             =   2160
            Width           =   2415
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            Caption         =   "波特率:"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   180
            Left            =   240
            TabIndex        =   14
            Top             =   300
            Width           =   630
         End
         Begin VB.Label Label2 
            AutoSize        =   -1  'True
            Caption         =   "校验位:"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   180
            Left            =   240
            TabIndex        =   13
            Top             =   780
            Width           =   630
         End
         Begin VB.Label Label3 
            AutoSize        =   -1  'True
            Caption         =   "数据位:"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   180
            Left            =   240
            TabIndex        =   12
            Top             =   1260
            Width           =   630
         End
         Begin VB.Label Label4 
            AutoSize        =   -1  'True
            Caption         =   "停止位:"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   180
            Left            =   240
            TabIndex        =   11
            Top             =   1740
            Width           =   630
         End
         Begin VB.Label Label5 
            AutoSize        =   -1  'True
            Caption         =   "串口号:"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   180
            Left            =   240
            TabIndex        =   10
            Top             =   2220
            Width           =   630
         End
      End
      Begin VB.OptionButton Option2 
         Caption         =   "通过I/O发送控制码"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   120
         TabIndex        =   3
         Top             =   3480
         Width           =   1935
      End
      Begin VB.CommandButton OKButton 
         Caption         =   "确定"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   350
         Left            =   4320
         TabIndex        =   2
         Top             =   360
         Width           =   1215
      End
      Begin VB.TextBox txtIO 
         Enabled         =   0   'False
         Height          =   285
         Left            =   2160
         TabIndex        =   1
         Text            =   "956"
         Top             =   3435
         Width           =   1575
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "(请输入10进制数)"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   180
         Left            =   3840
         TabIndex        =   17
         Top             =   3480
         Width           =   1620
      End
   End
End
Attribute VB_Name = "frmConfig"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'*******************************************
'声明
'*******************************************
Option Explicit
Private bInitialized As Boolean '初始化标志
Public bSerial As Boolean       '是否用串口通讯
'由类模块clsSerialPort定义的对象,用于存储串口通信参数
Public conSerialPort As New clsSerialPort
Public IoPort As Long           '存储IO端口
Public UserResult As VbMsgBoxResult '记录用户选则OK还是CANCEL
'********************************************
'声明结束
'********************************************

'********************************************
'功能:由外部(frmYuntai)传来的端口设置
'********************************************
Public Sub SetInitData(useSerial As Boolean, ByVal conPort As clsSerialPort, pPort As Long)
    bInitialized = True '标志已经初始化
    bSerial = useSerial
    '设置串口参数
    With conSerialPort
        .PortNr = conPort.PortNr
        .BaudRate = conPort.BaudRate
        .DataBits = conPort.DataBits
        .StopBits = conPort.StopBits
        .Parity = conPort.Parity
    End With
    '设置IO口参数
    IoPort = pPort
End Sub
'**********************************************
'应用由外部传来的设置
'**********************************************
Private Sub UseInitData()
    Dim Parity As String
    On Error Resume Next
    cmbBoudRate.Text = conSerialPort.BaudRate
    Select Case Chr(conSerialPort.Parity)
        Case "N"
            Parity = "NONE"
        Case "O"
            Parity = "ODD"
        Case "E"
            Parity = "EVEN"
        Case "M"
            Parity = "MARK"
        Case "S"
            Parity = "SPACE"
        Case Else
            Parity = "NONE"
    End Select
    cmbParity.Text = Parity
    cmbDatabits.Text = conSerialPort.DataBits
    cmbStopbits.Text = conSerialPort.StopBits
    cmbCom.Text = "COM" & (conSerialPort.PortNr)
    txtIO.Text = IoPort
    If bSerial Then
        fraComm.Enabled = True
        txtIO.Enabled = False
        Option1.Value = True
        Option2.Value = False
    Else
        fraComm.Enabled = False
        txtIO.Enabled = True
        Option1.Value = False
        Option2.Value = True
    End If
    
End Sub

'**************************************
'功能:为各组个框加载项目
'**************************************
Private Sub InitData()
    With cmbBoudRate
        .AddItem "19200"
        .AddItem "9600"
        .AddItem "2400"
        .AddItem "1200"
        .AddItem "300"
        .Text = "19200"
    End With

    With cmbParity
        .AddItem "NONE"
        .AddItem "ODD"
        .AddItem "EVEN"
        .AddItem "MARK"
        .AddItem "SPACE"
        .Text = "NONE"
    End With
    
    With cmbDatabits
        .AddItem "8"
        .AddItem "7"
        .AddItem "6"
        .Text = "8"
    End With
    
    With cmbStopbits
        .AddItem "1"
        .AddItem "1.5"
        .AddItem "2"
        .Text = "1"
    End With
    
    With cmbCom
        .AddItem "COM1"
        .AddItem "COM2"
        .AddItem "COM3"
        .AddItem "COM4"
        .Text = "COM1"
    End With
End Sub

Private Sub CancelButton_Click()
    UserResult = vbCancel
    Unload Me
End Sub

Private Sub Form_Load()
    '加载组合框中的项目
    InitData
    '如果已经初始化,则显示传入的设置
    If bInitialized Then
        UseInitData
    End If
End Sub

Private Sub OKButton_Click()
    '记录当前选项
    bSerial = Option1.Value
    With conSerialPort
        .Parity = Asc(Mid(cmbParity.Text, 1, 1))
        .BaudRate = CLng(cmbBoudRate.Text)
        .DataBits = CLng(cmbDatabits.Text)
        .StopBits = CSng(cmbStopbits.Text)
        .PortNr = CByte(Right(cmbCom.Text, 1))
    End With
    IoPort = CLng(txtIO)
    UserResult = vbOK
    Unload Me
End Sub

Private Sub Option1_Click()
    '启用串口,禁用IO口
    bSerial = True
    fraComm.Enabled = True
    txtIO.Enabled = False
End Sub

Private Sub Option2_Click()
    '启用IO,禁用串口
    bSerial = False
    fraComm.Enabled = False
    txtIO.Enabled = True
End Sub

⌨️ 快捷键说明

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