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

📄 frmsim_modem.frm

📁 监控类的开发
💻 FRM
📖 第 1 页 / 共 2 页
字号:

    ' 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"

    ' Load Data Bit Settings
    cboDataBits.AddItem "7"
    cboDataBits.AddItem "8"
    
    ' Load Stop Bit Settings
    cboStopBits.AddItem "1"
    cboStopBits.AddItem "2"
    
    ' Load Parity Settings
    cboParity.AddItem "Even"
    cboParity.AddItem "Odd"
    cboParity.AddItem "None"
    cboParity.AddItem "Mark"
    cboParity.AddItem "Space"
  
    'Load Timer Data
    cboTimer.AddItem "1"
    cboTimer.AddItem "2"
    cboTimer.AddItem "3"
    cboTimer.AddItem "4"
    cboTimer.AddItem "5"
    cboTimer.AddItem "6"
    cboTimer.AddItem "7"
    cboTimer.AddItem "8"
    cboTimer.AddItem "9"
      
    ' Set Default Settings
    With MSComm1
      If CheckFile(strPath) Then
          strtmp = ReadTxtFile(strPath)
          .Settings = GetNoString(strtmp, "/", 0)
          .CommPort = Val(GetNoString(strtmp, "/", 1))
          
          nSample = Val(GetNoString(strtmp, "/", 2))
          
          cboTimer.ListIndex = Val(GetNoString(strtmp, "/", 3)) - 1
      Else
          cboTimer.ListIndex = 0
      End If
    
      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
      StatusBar1.Panels("ComStatus").Text = "COM" + Trim(Str(.CommPort)) + ": " + .Settings
    End With
  
    strtmp = App.Path + "\BaseCode.txt"
    If CheckFile(strtmp) Then
        strtmp = ReadTxtFile(strtmp)
        If CheckLegalChars(strtmp, "0123456789") And Len(strtmp) >= 4 Then
            strHead_No = Mid(strtmp, 1, Len(strtmp) - 2)
            nEnd_No = Val(Mid(strtmp, Len(strtmp) - 1))
        Else
            If nSample = 1 Then _
                MsgBox "BaseCode.txt 中包含非数字符号或长度小于4!", vbExclamation + vbOKOnly, "提示"
        End If
    End If
    
    If strHead_No = "" Then nSample = 0
    chkSample.Value = nSample
    
    Randomize
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim strFile As String
    Dim nTmp As Integer
    On Error Resume Next

    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
    End If
  
    timer_Send_Interval.Enabled = False
    timer_Times_Interval.Enabled = False
    timer_Comm.Enabled = False
  
    If nOptInterval < 1 Or nOptInterval > 9 Then nOptInterval = 1
  
    With MSComm1
        strFile = .Settings + "/" + Str(.CommPort) + "/" + Str(chkSample.Value) + "/" + _
                  Str(nOptInterval) + "/"
        
        WriteStringToTxt strFile, App.Path & "\Setup.ini"
    End With
End Sub

Private Sub imgConnected_Click()
    On Error Resume Next
    
    With MSComm1
        If .PortOpen = True Then
            .PortOpen = False
        End If
    End With
    
    timer_Times_Interval.Enabled = False
    imgNotConnected.ZOrder
End Sub

Private Sub imgNotConnected_Click()
    Dim nPort As Integer
    On Error Resume Next
    
    strInBuffers = ""
  
    With MSComm1
        nPort = cboPort.ListIndex + 1
        .Settings = Trim$(cboSpeed.Text) & "," & Left$(cboParity.Text, 1) _
              & "," & Trim$(cboDataBits.Text) & "," & Trim$(cboStopBits.Text)
        .CommPort = nPort
    
        If Err Then
            MsgBox Error$, vbExclamation + vbOKOnly
            GoTo ERROR_MARK
        End If
    
        StatusBar1.Panels("ComStatus").Text = "COM" + Trim(Str(nPort)) + ": " + .Settings
    
        If .PortOpen = False Then
            .PortOpen = True
            
            If Err.Number <> 0 Then
              MsgBox Error$, vbCritical + vbOKOnly
              GoTo ERROR_MARK
            End If
    
            timer_Times_Interval.Enabled = bValid
        End If
    End With
  
    imgConnected.ZOrder

ERROR_MARK:
End Sub

Private Sub MSComm1_OnComm()
    Dim vInBuffer As Variant
    Dim strRecChars As String
    On Error Resume Next
  
    If MSComm1.CommEvent = comEvReceive Then
        If bStartComm = False Then strInBuffers = ""
        vInBuffer = MSComm1.Input
        strRecChars = HexCharsToString(VariantToHexChars(vInBuffer))
        strInBuffers = strInBuffers + UCase(strRecChars)

        If bStartComm = False Then
            bStartComm = True
        End If
        
        If bStartComm = True Then
            timer_Comm.Enabled = False
            timer_Comm.Enabled = True
        End If
    End If
End Sub

Private Sub timer_Comm_Timer()
    On Error Resume Next
    
    timer_Comm.Enabled = False
    bStartComm = False
    
    If bDial = True Then
        timer_Comm.Enabled = False
        bDial = False
        MSComm1.Output = vbCrLf + "OK" + vbCrLf
        timer_Comm.Interval = 100
        Exit Sub
    End If
      
    If (Mid(strInBuffers, 1, 2) = "AT") And (Right(strInBuffers, 1) = Chr(13)) Then
        MSComm1.Output = strInBuffers
        If InStr(1, strInBuffers, "DT") = 0 Then
            MSComm1.Output = vbCrLf + "OK" + vbCrLf
        Else
            bDial = True
            timer_Comm.Interval = 9000
            timer_Comm.Enabled = True
        End If
        
        If InStr(1, strInBuffers, "#CID=1", vbTextCompare) = 0 Then
            bValid = False
            StatusBar1.Panels("Modem").Text = "Modem: out of service"
        Else
            bValid = True
            timer_Times_Interval.Enabled = bValid
            StatusBar1.Panels("Modem").Text = "Modem: in service"
        End If
      
    End If
End Sub

Private Sub timer_Send_Interval_Timer()
    Dim strNo As String
    Dim strtmp As String
    On Error Resume Next
    
    If nSample = 1 Then
        strtmp = ts(nEnd_No + Int(Rnd * TOTAL_NO))
        If Len(strtmp) = 3 Then strtmp = Mid(strtmp, 2)
        strNo = strHead_No + strtmp
    Else
        strNo = Right(Trim(Str(GetTickCount())), 7)
        If Len(strNo) < 7 Then strNo = String(7 - Len(strNo), "8") + strNo
    End If
        
    If nCount = 2 Then
        MSComm1.Output = GetTwoRing(strNo)
    Else
        MSComm1.Output = strRing
    End If
    
    If CheckFile(strSound) Then PlaySound strSound, 0, SND_ASYNC
    
    nCount = nCount + 1
    If nCount > 4 Then
        timer_Send_Interval.Enabled = False
        nCount = 0
    End If
End Sub

Private Sub timer_Times_Interval_Timer()
    Dim strtmp As String
    Dim nMinute As Integer
    Dim nSecond As Integer
    
    strtmp = Format(Time, "HH:MM:SS:")
    nSecond = Val(GetNoString(strtmp, ":", 2))
    If nSecond = 0 And nCount = 0 Then
        nMinute = Val(GetNoString(strtmp, ":", 1))
        If nMinute Mod nOptInterval = 0 Then
           nCount = 1
           timer_Send_Interval.Enabled = True
        End If
    End If
End Sub

⌨️ 快捷键说明

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