VERSION 5.00
Begin VB.Form frmProper 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "串口通讯设置"
   ClientHeight    =   3915
   ClientLeft      =   4140
   ClientTop       =   1665
   ClientWidth     =   6015
   Icon            =   "Frmprops.frx":0000
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3915
   ScaleWidth      =   6015
   ShowInTaskbar   =   0   'False
   Begin VB.Frame fraSettings 
      BorderStyle     =   0  'None
      Height          =   3015
      Left            =   255
      TabIndex        =   1
      Top             =   570
      Width           =   5445
      Begin VB.Frame Frame1 
         Caption         =   "端口:"
         Height          =   870
         Index           =   1
         Left            =   180
         TabIndex        =   18
         Top             =   30
         Width           =   1800
         Begin VB.ComboBox cboPort 
            Height          =   300
            Left            =   240
            Style           =   2  'Dropdown List
            TabIndex        =   19
            Top             =   360
            Width           =   1425
         End
      End
      Begin VB.CommandButton cmdCancel 
         Caption         =   "取消"
         Height          =   300
         Left            =   4545
         TabIndex        =   17
         Top             =   465
         Width           =   855
      End
      Begin VB.Frame Frame1 
         Caption         =   "波特率:"
         Height          =   870
         Index           =   0
         Left            =   2160
         TabIndex        =   15
         Top             =   30
         Width           =   2280
         Begin VB.ComboBox cboSpeed 
            Height          =   300
            Left            =   120
            Style           =   2  'Dropdown List
            TabIndex        =   16
            Top             =   330
            Width           =   1695
         End
      End
      Begin VB.Frame fraConnection 
         Caption         =   "连接参数"
         Height          =   1770
         Left            =   180
         TabIndex        =   8
         Top             =   1035
         Width           =   2580
         Begin VB.ComboBox cboStopBits 
            Height          =   300
            Left            =   1305
            Style           =   2  'Dropdown List
            TabIndex        =   11
            Top             =   1260
            Width           =   1140
         End
         Begin VB.ComboBox cboParity 
            Height          =   300
            Left            =   1305
            Style           =   2  'Dropdown List
            TabIndex        =   10
            Top             =   810
            Width           =   1140
         End
         Begin VB.ComboBox cboDataBits 
            Height          =   300
            Left            =   1305
            Style           =   2  'Dropdown List
            TabIndex        =   9
            Top             =   330
            Width           =   1140
         End
         Begin VB.Label Label5 
            Caption         =   "停止位:"
            Height          =   285
            Left            =   120
            TabIndex        =   14
            Top             =   1260
            Width           =   1005
         End
         Begin VB.Label Label4 
            AutoSize        =   -1  'True
            Caption         =   "奇偶校验:"
            Height          =   180
            Left            =   105
            TabIndex        =   13
            Top             =   810
            Width           =   810
         End
         Begin VB.Label Label3 
            Caption         =   "数据位:"
            Height          =   285
            Left            =   120
            TabIndex        =   12
            Top             =   330
            Width           =   1065
         End
      End
      Begin VB.CommandButton cmdOK 
         Caption         =   "确定"
         Default         =   -1  'True
         Height          =   300
         Left            =   4545
         MaskColor       =   &H00000000&
         TabIndex        =   7
         Top             =   75
         Width           =   855
      End
      Begin VB.Frame Frame5 
         Caption         =   "流量控制(&F)"
         Height          =   1770
         Left            =   2820
         TabIndex        =   2
         Top             =   1050
         Width           =   1620
         Begin VB.OptionButton optFlow 
            Caption         =   "None"
            Height          =   255
            Index           =   0
            Left            =   180
            MaskColor       =   &H00000000&
            TabIndex        =   6
            Top             =   345
            Width           =   855
         End
         Begin VB.OptionButton optFlow 
            Caption         =   "Xon/Xoff"
            Height          =   255
            Index           =   1
            Left            =   180
            MaskColor       =   &H00000000&
            TabIndex        =   5
            Top             =   645
            Width           =   1095
         End
         Begin VB.OptionButton optFlow 
            Caption         =   "RTS"
            Height          =   255
            Index           =   2
            Left            =   180
            MaskColor       =   &H00000000&
            TabIndex        =   4
            Top             =   945
            Width           =   735
         End
         Begin VB.OptionButton optFlow 
            Caption         =   "Xon/RTS"
            Height          =   255
            Index           =   3
            Left            =   180
            MaskColor       =   &H00000000&
            TabIndex        =   3
            Top             =   1245
            Width           =   1155
         End
      End
   End
   Begin VB.PictureBox tabSettings 
      Height          =   3705
      Left            =   90
      ScaleHeight     =   3645
      ScaleWidth      =   5760
      TabIndex        =   0
      Top             =   105
      Width           =   5820
   End
End
Attribute VB_Name = "frmProper"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private iFlow As Integer, iTempEcho As Boolean

Sub LoadPropertySettings()
Dim i As Integer, settings As String, Offset As Integer

' Load Port Settings
For i = 1 To 4
    cboPort.AddItem "Com" & Trim$(str$(i))
Next i

' Load Speed Settings
Cbospeed.AddItem "1200"
Cbospeed.AddItem "2400"
Cbospeed.AddItem "4800"
Cbospeed.AddItem "9600"
Cbospeed.AddItem "19200"

' Load Data Bit Settings
cboDataBits.AddItem "4"
cboDataBits.AddItem "5"
cboDataBits.AddItem "6"
cboDataBits.AddItem "7"
cboDataBits.AddItem "8"

' Load Parity Settings
cboParity.AddItem "Even"
cboParity.AddItem "Odd"
cboParity.AddItem "None"
cboParity.AddItem "Mark"
cboParity.AddItem "Space"

' Load Stop Bit Settings
cboStopBits.AddItem "1"
cboStopBits.AddItem "1.5"
cboStopBits.AddItem "2"

' Set Default Settings

settings = frmComm.MSComm1.settings

' In all cases the right most part of Settings will be 1 character
' except when there are 1.5 stop bits.
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 = frmComm.MSComm1.CommPort - 1

optFlow(frmComm.MSComm1.Handshaking).Value = True

End Sub

Private Sub cmdCancel_Click()
   Unload Me
End Sub

Private Sub cmdOK_Click()
Dim OldPort As Integer, ReOpen As Boolean

On Error Resume Next

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

If NewPort <> OldPort Then                   ' If the port number changes, close the old port.
    If frmComm.MSComm1.PortOpen Then
           frmComm.MSComm1.PortOpen = False
           ReOpen = True
    End If

    frmComm.MSComm1.CommPort = NewPort          ' Set the new port number.
    
'    If Err = 0 Then
'        If ReOpen Then
'            comm.MSComm1.PortOpen = True
'            comm.mnuOpen.Checked = comm.MSComm1.PortOpen
'            comm.mnuSendText.Enabled = comm.MSComm1.PortOpen
'            comm.tbrToolBar.Buttons("TransmitTextFile").Enabled = comm.MSComm1.PortOpen
'        End If
'    End If
        
    If Err Then
        MsgBox Error$, 48
        frmComm.MSComm1.CommPort = OldPort
        Exit Sub
    End If
End If


frmComm.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

frmComm.MSComm1.Handshaking = iFlow
If Err Then
    MsgBox Error$, 48
    Exit Sub
End If

SaveSetting App.Title, "Properties", "Settings", frmComm.MSComm1.settings
SaveSetting App.Title, "Properties", "CommPort", frmComm.MSComm1.CommPort
SaveSetting App.Title, "Properties", "Handshaking", frmComm.MSComm1.Handshaking
SaveSetting App.Title, "Properties", "Echo", Echo

Unload Me

End Sub

Private Sub Form_Load()

' Set the form's size
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2

' Size the frame to fit in the tabstrip control
'fraSettings.Move tabSettings.ClientLeft, tabSettings.ClientTop

' Make sure the frame is the top most control
'fraSettings.ZOrder

' Load current property settings
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


