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

📄 date1.frm

📁 基于MSCOMM的炉温控制系统上位机程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
               Left            =   225
               TabIndex        =   11
               Top             =   1125
               Width           =   840
            End
            Begin VB.Label Label3 
               BackColor       =   &H00DEEBEF&
               Caption         =   "校检位"
               Height          =   390
               Left            =   225
               TabIndex        =   10
               Top             =   675
               Width           =   840
            End
            Begin VB.Label Label2 
               BackColor       =   &H00DEEBEF&
               Caption         =   "数据位"
               Height          =   315
               Left            =   225
               TabIndex        =   9
               Top             =   225
               Width           =   840
            End
         End
         Begin VB.Frame Frame2 
            BackColor       =   &H00DEEBEF&
            Caption         =   "波特率"
            Height          =   765
            Left            =   225
            TabIndex        =   3
            Top             =   825
            Width           =   2190
            Begin VB.ComboBox cbospeed 
               Height          =   300
               Left            =   225
               TabIndex        =   4
               Text            =   "Combo1"
               Top             =   225
               Width           =   1665
            End
         End
         Begin VB.ComboBox cboport 
            Height          =   300
            Left            =   900
            TabIndex        =   2
            Text            =   "cboport"
            Top             =   300
            Width           =   1065
         End
         Begin VB.Label Label1 
            BackColor       =   &H00DEEBEF&
            Caption         =   "端口"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   10.5
               Charset         =   134
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   375
            TabIndex        =   14
            Top             =   375
            Width           =   465
         End
      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, iTempEcho As Boolean
Private Sub CmdCancal_Click()
Unload Me
End Sub

Private Sub CmdOK_Click()
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 the port number changes, close the old port.
    If Form1.MSComm1.PortOpen Then
           Form1.MSComm1.PortOpen = False
           ReOpen = True
    End If

    Form1.MSComm1.CommPort = NewPort          ' Set the new port number.
    
    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
If Err Then
    MsgBox Error$, 48
    Exit Sub
End If

SaveSetting App.Title, "Properties", "Settings", Form1.MSComm1.Settings
SaveSetting App.Title, "Properties", "CommPort", Form1.MSComm1.CommPort
SaveSetting App.Title, "Properties", "Handshaking", Form1.MSComm1.Handshaking
Form1.Label2 = "[" & Form1.MSComm1.Settings & "]"
Form1.Label3 = Form1.MSComm1.CommPort
Form1.Label4 = Form1.MSComm1.Handshaking
Select Case Form1.MSComm1.Handshaking
    Case 0
       Form1.Label4.Caption = "不使用"
    Case 1
       Form1.Label4.Caption = "握手协议"
    Case 2
       Form1.Label4.Caption = "请求,清除"
    Case 3
       Form1.Label4.Caption = "两者"
End Select
Unload Me
End Sub

Private Sub Form_Load()
LoadPropertySettings
End Sub

Public Sub LoadPropertySettings()
Dim i As Integer, Settings As String, Offset As Integer

' Load Port Settings
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"

' 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 = Form1.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 = Form1.MSComm1.CommPort - 1

optFlow(Form1.MSComm1.Handshaking).Value = True
If Echo Then
    optEcho(1).Value = True
Else
    optEcho(0).Value = True
End If
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 + -