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

📄 frmsetup.frm

📁 这是一本学习串口编程喝计算机监控的好书里面是用VB开发的源代码
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         TabIndex        =   28
         Top             =   360
         Width           =   615
      End
   End
   Begin VB.Label Label8 
      Caption         =   "S"
      Height          =   255
      Left            =   2640
      TabIndex        =   33
      Top             =   2400
      Width           =   255
   End
   Begin VB.Label Label7 
      Caption         =   "Interval"
      Height          =   255
      Left            =   1560
      TabIndex        =   32
      Top             =   2400
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "Port:"
      Height          =   315
      Left            =   1440
      TabIndex        =   22
      Top             =   3240
      Width           =   375
   End
End
Attribute VB_Name = "frmSetup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private iFlow As Integer

Private Sub LoadPropertySettings()
    'only for serial port
    Dim I As Integer
    Dim strSettings As String

    ' 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"
    
    ' Load Block Parities
    cboGroupParity.AddItem "None"
    cboGroupParity.AddItem "Xor"
    cboGroupParity.AddItem "Add"
    cboGroupParity.ListIndex = nBlockParity

    ' Set Default Settings
    With frmMain.MSComm1
        strSettings = .Settings
        cboSpeed.Text = GetNoString(strSettings, ",", 0)
      
        Select Case GetNoString(strSettings, ",", 1)
            Case "e"
                cboParity.ListIndex = 0
            Case "o"
                cboParity.ListIndex = 1
            Case "n"
                cboParity.ListIndex = 2
            Case "m"
                cboParity.ListIndex = 3
            Case "s"
                cboParity.ListIndex = 4
        End Select
        
        cboDataBits.Text = GetNoString(strSettings, ",", 2)
        cboStopBits.Text = GetNoString(strSettings + ",", ",", 3)
      
        cboPort.ListIndex = .CommPort - 1
    
        optFlow(.Handshaking).Value = True
        
        If .InputMode = comInputModeBinary Then
            optMode(1).Value = True
        Else
            optMode(0).Value = True
        End If
    End With
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim nOldPort As Integer
    Dim nNewPort As Integer
    Dim bReOpen As Boolean
    Dim strSettings As String
    Dim lInterval As Long
    Dim nADDress As Integer
    Dim bTimer As Boolean
    On Error Resume Next
    
    With frmMain.MSComm1
        nOldPort = .CommPort
        nNewPort = cboPort.ListIndex + 1

        If nNewPort <> nOldPort Then                   ' If the port number changes, close the old port.
            If .PortOpen Then
                .PortOpen = False
                
                strSettings = .Settings
                frmMain.SetComStatus
                bReOpen = True
            End If
        
            .CommPort = nNewPort          ' Set the new port number.
        End If

        .Settings = Trim$(cboSpeed.Text) & "," & Left$(cboParity.Text, 1) _
              & "," & Trim$(cboDataBits.Text) & "," & Trim$(cboStopBits.Text)
    
        If Err Then
            MsgBox Error$, vbExclamation + vbOKOnly
            GoTo ERROR_MARK
        End If
    
        .Handshaking = iFlow
        If iFlow >= 2 Then .RTSEnable = True
        
        If Err Then
            MsgBox Error$, vbExclamation + vbOKOnly
            GoTo ERROR_MARK
        End If

        strSettings = .Settings
        If bReOpen = True Then
            Call OpenAndAdjustPort(frmMain.MSComm1)
            
            If Err Then
                MsgBox Error$, vbCritical + vbOKOnly
                .CommPort = nOldPort
                GoTo ERROR_MARK
            End If
          
        End If
    End With
  
    frmMain.timerComm.Interval = nMaxChars * 10 * 1000 \ Val(GetNoString(strSettings, ",", 0)) + 100
    
    Select Case cboGroupParity.Text
        Case "None"
            nBlockParity = CHK_NONE
        Case "Xor"
            nBlockParity = CHK_XOR
        Case "Add"
            nBlockParity = CHK_ADD
    End Select
    
    SoundMark = IIf(chkSound.Value = 1, True, False)
    
    lInterval = Val(txtInterval.Text)
    If lInterval <= 2 Or lInterval > 60 Then lInterval = 20
    bTimer = frmMain.timerIn.Enabled
    If bTimer = True Then frmMain.timerIn.Enabled = False
    frmMain.timerIn.Interval = lInterval * 1000
    frmMain.timerIn.Enabled = bTimer
    
    nADDress = TwoHexCharsToByte(txtADDress.Text)
    If nADDress < 1 Or nADDress > 255 Then nADDress = 1
    strADDress = ByteToTwoHexChars(nADDress)
    
    SaveSetting App.Title, "Properties", "Settings", frmMain.MSComm1.Settings
    SaveSetting App.Title, "Properties", "CommPort", frmMain.MSComm1.CommPort
    SaveSetting App.Title, "Properties", "Handshaking", frmMain.MSComm1.Handshaking
    SaveSetting App.Title, "Properties", "EndMark", Str(nEndMark)
    SaveSetting App.Title, "Properties", "BlockParity", Str(nBlockParity)
    SaveSetting App.Title, "Properties", "Sound", IIf(SoundMark = True, "1", "0")
    SaveSetting App.Title, "Properties", "lInterval", lInterval
    SaveSetting App.Title, "Properties", "ADDress", strADDress
  
    bSwitch = True
ERROR_MARK:
    frmMain.SetComStatus
    Unload Me
End Sub

Private Sub Form_Load()
    ' Load current property settings
    LoadPropertySettings
    
    If strSoundPath = "" Then chkSound.Enabled = False
    
    chkSound.Value = IIf(SoundMark = True, 1, 0)
      
    Select Case nEndMark
        Case ADD_NONE
            optEndMark(0).Value = True
        Case ADD_CR
            optEndMark(1).Value = True
        Case ADD_CRLF
            optEndMark(2).Value = True
    End Select
    
    txtInterval.Text = frmMain.timerIn.Interval \ 1000
    txtADDress.Text = strADDress
    
    nReadLen = 6  'Bytes
    nWriteLen = 7
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If nBlockParity = CHK_NONE Then
        nReadLen = nReadLen - 1
        nWriteLen = nWriteLen - 1
    End If
    
    Select Case nEndMark
        Case ADD_NONE
            nReadLen = nReadLen - 2
            nWriteLen = nWriteLen - 2
        Case ADD_CR
            nReadLen = nReadLen - 1
            nWriteLen = nWriteLen - 1
    End Select
End Sub


Private Sub optEndMark_Click(Index As Integer)
    nEndMark = Index
End Sub

Private Sub optMode_Click(Index As Integer)
    With frmMain.MSComm1
        If Index = 1 Then
            .InputMode = comInputModeBinary
        Else
            .InputMode = comInputModeText
        End If
    End With
End Sub

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

⌨️ 快捷键说明

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