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

📄 frmproperties.frm

📁 rs232通信调试
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmProperties 
   Caption         =   "通讯端口属性设置"
   ClientHeight    =   3720
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6465
   LinkTopic       =   "Form1"
   ScaleHeight     =   3720
   ScaleWidth      =   6465
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame Frame5 
      Height          =   750
      Left            =   255
      TabIndex        =   20
      Top             =   405
      Width           =   4395
      Begin VB.ComboBox cboPort 
         Height          =   300
         ItemData        =   "frmProperties.frx":0000
         Left            =   2040
         List            =   "frmProperties.frx":0002
         TabIndex        =   22
         Text            =   "cboPort"
         Top             =   315
         Width           =   1980
      End
      Begin VB.Label Label4 
         Caption         =   "通讯端口:"
         Height          =   255
         Left            =   450
         TabIndex        =   21
         Top             =   315
         Width           =   1020
      End
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "取消"
      Height          =   450
      Left            =   4905
      TabIndex        =   6
      Top             =   1830
      Width           =   1320
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "确认"
      Height          =   450
      Left            =   4905
      TabIndex        =   5
      Top             =   1215
      Width           =   1320
   End
   Begin VB.Frame Frame4 
      Caption         =   "握手通讯协议:"
      Height          =   1530
      Left            =   2580
      TabIndex        =   4
      Top             =   2055
      Width           =   2040
      Begin VB.OptionButton optFlow 
         Caption         =   "XON/RTS"
         Height          =   255
         Index           =   3
         Left            =   90
         TabIndex        =   19
         Top             =   1155
         Width           =   1875
      End
      Begin VB.OptionButton optFlow 
         Caption         =   "RTS"
         Height          =   255
         Index           =   2
         Left            =   90
         TabIndex        =   18
         Top             =   855
         Width           =   1875
      End
      Begin VB.OptionButton optFlow 
         Caption         =   "XON/XOFF"
         Height          =   255
         Index           =   1
         Left            =   90
         TabIndex        =   17
         Top             =   555
         Width           =   1875
      End
      Begin VB.OptionButton optFlow 
         Caption         =   "无"
         Height          =   255
         Index           =   0
         Left            =   90
         TabIndex        =   16
         Top             =   255
         Width           =   1875
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "通讯设置:"
      Height          =   1515
      Left            =   210
      TabIndex        =   3
      Top             =   2040
      Width           =   2310
      Begin VB.ComboBox cboStopBits 
         Height          =   300
         Left            =   960
         TabIndex        =   12
         Text            =   "cboStopBits"
         Top             =   1110
         Width           =   1170
      End
      Begin VB.ComboBox cboParity 
         Height          =   300
         Left            =   960
         TabIndex        =   11
         Text            =   "cboParity"
         Top             =   682
         Width           =   1170
      End
      Begin VB.ComboBox cboDataBits 
         Height          =   300
         Left            =   960
         TabIndex        =   10
         Text            =   "cboDataBits"
         Top             =   255
         Width           =   1170
      End
      Begin VB.Label Label3 
         Alignment       =   1  'Right Justify
         Caption         =   "停止位"
         Height          =   285
         Left            =   30
         TabIndex        =   15
         Top             =   1050
         Width           =   840
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         Caption         =   "数据校验"
         Height          =   285
         Left            =   30
         TabIndex        =   14
         Top             =   645
         Width           =   840
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "数据位数"
         Height          =   285
         Left            =   30
         TabIndex        =   13
         Top             =   255
         Width           =   840
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "回响:"
      Height          =   765
      Left            =   2595
      TabIndex        =   2
      Top             =   1215
      Width           =   2025
      Begin VB.OptionButton optEcho 
         Caption         =   "开"
         Height          =   285
         Index           =   1
         Left            =   990
         TabIndex        =   9
         Top             =   360
         Width           =   705
      End
      Begin VB.OptionButton optEcho 
         Caption         =   "关"
         Height          =   225
         Index           =   0
         Left            =   180
         TabIndex        =   8
         Top             =   390
         Width           =   750
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "通讯波特率:"
      Height          =   750
      Left            =   240
      TabIndex        =   1
      Top             =   1215
      Width           =   2295
      Begin VB.ComboBox cboSpeed 
         Height          =   300
         Left            =   165
         TabIndex        =   7
         Text            =   "cboSpeed"
         Top             =   300
         Width           =   1680
      End
   End
   Begin MSComctlLib.TabStrip TabStrip1 
      Height          =   3660
      Left            =   0
      TabIndex        =   0
      Top             =   15
      Width           =   6405
      _ExtentX        =   11298
      _ExtentY        =   6456
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   1
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "属性设置"
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmProperties"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private iFlow As Integer
Private iTempEcho As Boolean
Sub LoadPropertySettings()
Dim i As Integer
Dim Settings As String
Dim Offset As Integer
'添加通讯端口,从Com1-Com16,计算机上常用的通讯端口为Com1和Com2
'其中Com1通常为鼠标所占用
For i = 1 To 16
    cboPort.AddItem "Com" & Trim$(Str$(i))
Next i
'为串口通讯设置通讯的波特率,通过Modem拨号的要选择与其相一致的
'通讯波特率
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 "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"
'返回波特率、奇偶校验、数据位、停止位参数。
'各参数间以逗号分开,如:"9600,N,8,1"
'表示通讯的波特率位9600,无数据校验,数据位数为8位,停止位数为1
Settings = frmTerminal.MSComm1.Settings
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 = frmTerminal.MSComm1.CommPort - 1
optFlow(frmTerminal.MSComm1.Handshaking).Value = True
If Echo Then
    optEcho(1).Value = True
Else
    optEcho(0).Value = True
End If
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()
Dim OldPort As Integer
Dim ReOpen As Boolean
Dim NewPort As Integer
On Error Resume Next
Echo = iTempEcho
OldPort = frmTerminal.MSComm1.CommPort
NewPort = cboPort.ListIndex + 1
If NewPort <> OldPort Then
    If frmTerminal.MSComm1.PortOpen Then
        frmTerminal.MSComm1.PortOpen = False
        ReOpen = True
    End If
    frmTerminal.MSComm1.CommPort = NewPort
    If Err = 0 Then
        If ReOpen Then
            frmTerminal.MSComm1.PortOpen = True
            frmTerminal.mnuOpen.Checked = frmTerminal.MSComm1.PortOpen
            frmTerminal.mnuSendText.Enabled = frmTerminal.MSComm1.PortOpen
            frmTerminal.tbrToolBar.Buttons("TransmitTextFile").Enabled = frmTerminal.MSComm1.PortOpen
        End If
    End If
    If Err Then
        MsgBox Error$, 48
        frmTerminal.MSComm1.CommPort = OldPort
        Exit Sub
    End If
End If
frmTerminal.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
frmTerminal.MSComm1.Handshaking = iFlow
If Err Then
    MsgBox Error$, 48
    Exit Sub
End If
'将通讯的设置参数写入到注册表中
SaveSetting App.Title, "Properties", "Settings", frmTerminal.MSComm1.Settings
SaveSetting App.Title, "Properties", "CommPort", frmTerminal.MSComm1.CommPort
SaveSetting App.Title, "Properties", "Handshaking", frmTerminal.MSComm1.Handshaking
SaveSetting App.Title, "Properties", "Echo", Echo
Unload Me
End Sub

Private Sub Form_Load()
'调整窗体使其居于屏幕的中心
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
'调用子程序设定各控件的值
LoadPropertySettings
End Sub

Private Sub optEcho_Click(Index As Integer)
If Index = 1 Then
    iTempEcho = True
Else
    iTempEcho = False
End If
End Sub

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

⌨️ 快捷键说明

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