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

📄 frmterminal.frm

📁 rs232通信调试
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmTerminal 
   Caption         =   "VISUAL BASIC 终端"
   ClientHeight    =   4470
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   6705
   LinkTopic       =   "Form1"
   ScaleHeight     =   4470
   ScaleWidth      =   6705
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer2 
      Interval        =   2000
      Left            =   375
      Top             =   2265
   End
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   360
      Top             =   1815
   End
   Begin MSComctlLib.StatusBar sbrStatus 
      Align           =   2  'Align Bottom
      Height          =   360
      Left            =   0
      TabIndex        =   2
      Top             =   4110
      Width           =   6705
      _ExtentX        =   11827
      _ExtentY        =   635
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            AutoSize        =   1
            Object.Width           =   8705
            Text            =   "通讯状态:"
            TextSave        =   "通讯状态:"
            Key             =   "Status"
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Text            =   "连接时间:"
            TextSave        =   "连接时间:"
            Key             =   "connectTime"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar tbrToolBar 
      Align           =   1  'Align Top
      Height          =   615
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   6705
      _ExtentX        =   11827
      _ExtentY        =   1085
      ButtonWidth     =   1455
      ButtonHeight    =   926
      Appearance      =   1
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   7
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "打开日志"
            Key             =   "OpenLogFile"
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Caption         =   "关闭日志"
            Key             =   "CloseLogFile"
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "拨号"
            Key             =   "DialPhoneNumber"
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Caption         =   "挂断"
            Key             =   "HangUpPhone"
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "端口属性"
            Key             =   "Properties"
         EndProperty
         BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Caption         =   "发送文件"
            Key             =   "TransmitTextFile"
         EndProperty
      EndProperty
   End
   Begin VB.TextBox txtTerm 
      Appearance      =   0  'Flat
      Height          =   3285
      Left            =   2055
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Text            =   "frmTerminal.frx":0000
      Top             =   630
      Width           =   4335
   End
   Begin MSComDlg.CommonDialog OpenLog 
      Left            =   300
      Top             =   1320
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   315
      Top             =   705
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Menu File 
      Caption         =   "文件"
      Begin VB.Menu mnuOpenLog 
         Caption         =   "打开登录文件"
      End
      Begin VB.Menu mnuCloseLog 
         Caption         =   "关闭登录文件"
         Enabled         =   0   'False
      End
      Begin VB.Menu mnuFileExit 
         Caption         =   "退出"
      End
   End
   Begin VB.Menu CommPort 
      Caption         =   "通讯端口"
      Begin VB.Menu mnuOpen 
         Caption         =   "打开/关闭"
      End
      Begin VB.Menu mnuProperties 
         Caption         =   "属性设置"
      End
   End
   Begin VB.Menu MSComm 
      Caption         =   "通讯"
      Begin VB.Menu mnuSettings 
         Caption         =   "通讯参数设置"
      End
      Begin VB.Menu mnuSendText 
         Caption         =   "发送文本文件"
         Enabled         =   0   'False
      End
   End
   Begin VB.Menu Call 
      Caption         =   "呼叫"
      Begin VB.Menu mnuDial 
         Caption         =   "拨号"
      End
      Begin VB.Menu mnuHangup 
         Caption         =   "挂断"
         Enabled         =   0   'False
      End
   End
End
Attribute VB_Name = "frmTerminal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Ret As Integer
Dim Temp As String
Dim hLogFile As Integer
Dim StartTime As Date

Private Sub Form_Load()
Dim CommPort As String    '存放通讯端口的字符串变量
Dim Handshaking As String  '存放通讯协议的字符串变量
Dim Settings As String    '存放设定通讯参数的字符串变量
On Error Resume Next
txtTerm.SelLength = Len(txtTerm.Text)
txtTerm.SelText = ""
txtTerm.ForeColor = vbBlue
App.Title = "VISUAL BASIC 终端"
'调整窗体的位置使其处于整个屏幕的中心
frmTerminal.Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
'从Windows的注册表读取上次通讯参数的设置
Settings = GetSetting(App.Title, "Properties", "Settings", "")
If Settings <> "" Then
'设置MSComm控件的通讯参数
     MSComm1.Settings = Settings
     If Err Then
         MsgBox Error$, 48
         Exit Sub
      End If
End If
'从注册表读取通讯端口的设置
CommPort = GetSetting(App.Title, "Properties", "CommPort", "")
If CommPort <> "" Then MSComm1.CommPort = CommPort
'从注册表中读取通讯协议的设置
Handshaking = GetSetting(App.Title, "Properties", "Handshaking", "")
If Handshaking <> "" Then
     MSComm1.Handshaking = Handshaking
     If Err Then
          MsgBox Error$, 48
          Exit Sub
     End If
End If
Echo = GetSetting(App.Title, "Properties", "Echo", "")
On Error GoTo 0
End Sub

Private Sub Form_Resize()
'调整主窗体中文本框txtTerm的大小,使得尽量的充满整个窗体
txtTerm.Move 0, tbrToolBar.Height, frmTerminal.ScaleWidth, frmTerminal.ScaleHeight - sbrStatus.Height - tbrToolBar.Height
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim Counter As Long
If MSComm1.PortOpen Then
    Counter = Timer + 10
    Do While MSComm1.OutBufferCount
         Ret = DoEvents()
         If Timer > Counter Then
         '弹出msgbox-终止,重试,忽略
             Select Case MsgBox("数据无法发送......", 34)
                 Case 3
                 '选择终止
                     Cancel = True
                     Exit Sub
                 Case 4
                 '选择重试
                     Counter = Timer + 10
                 Case 5
                 '选择忽略
                     Exit Do
             End Select
        End If
    Loop
'关闭通讯端口
MSComm1.PortOpen = False
End If
'关闭登录文件的句柄
If hLogFile Then mnuCloseLog_Click
End
End Sub

Private Sub mnuCloseLog_Click()
'关闭登录文件的句柄,设置相应菜单和按扭的状态
Close hLogFile
hLogFile = 0
mnuOpenLog.Enabled = True
tbrToolBar.Buttons("OpenLogFile").Enabled = True
mnuCloseLog.Enabled = False
tbrToolBar.Buttons("CloseLogFile").Enabled = False
frmTerminal.Caption = "VISUAL BASIC 终端"
End Sub

Private Sub mnuDial_Click()
'提示输入电话号码进行拨号
On Local Error Resume Next
Static Num As String
Num = "80909908"
'从用户处获取电话号码
Num = InputBox$("请输入电话号码:", "拨号号码:", Num)
If Num = "" Then Exit Sub
'如果端口没有打开则打开它
If Not MSComm1.PortOpen Then
     mnuOpen_Click
     If Err Then Exit Sub
End If
'悬挂电话按钮及菜单项可用。
mnuHangup.Enabled = True
tbrToolBar.Buttons("HangUpPhone").Enabled = True
'拨打电话号码
MSComm1.Output = "ATDT" & Num & vbCrLf
'启动端口计时器
StartTiming
End Sub

Private Sub mnuFileExit_Click()
'选择退出程序时,如果通讯端口没有关闭,则禁止退出程序
'如果通讯端口关闭,则使用Form_Unload来退出程序
'在Form_Unload事件中包含代码用来检查未发送数据及打开的登录文件。
Form_Unload Ret
End Sub

Private Sub mnuHangup_Click()
On Error Resume Next
'切换控件MSComm的属性DTREnable来挂断电话
MSComm1.Output = "ATH"
Ret = MSComm1.DTREnable
MSComm1.DTREnable = True
MSComm1.DTREnable = False
MSComm1.DTREnable = Ret
'设置相应菜单及按扭的状态
mnuHangup.Enabled = False
tbrToolBar.Buttons("HangUpPhone").Enabled = False
End Sub

Private Sub mnuOpen_Click()
'切换端口状态,打开或关闭
On Error Resume Next
Dim OpenFlag
MSComm1.PortOpen = Not MSComm1.PortOpen
If Err Then MsgBox Error$, 48
OpenFlag = MSComm1.PortOpen
    mnuOpen.Checked = OpenFlag
    mnuSendText.Enabled = OpenFlag
    tbrToolBar.Buttons("TransmitTextFile").Enabled = OpenFlag
    If MSComm1.PortOpen Then
        '使拨号按钮及菜单项可用
        mnuDial.Enabled = True
        tbrToolBar.Buttons("DialPhoneNumber").Enabled = True
        '使挂断按钮及菜单项可用
        mnuHangup.Enabled = True
        tbrToolBar.Buttons("HangUpPhone").Enabled = True
        sbrStatus.Panels("Settings").Text = "Settings:" & MSComm1.Settings
        StartTiming
    Else
       '使拨号按钮及菜单项可用
       mnuDial.Enabled = True
       tbrToolBar.Buttons("DialPhoneNumber").Enabled = True
       '禁用挂断按钮及菜单项
       mnuHangup.Enabled = False
       tbrToolBar.Buttons("HangUpPhone").Enabled = False
       sbrStatus.Panels("Settings").Text = "Settings:"
       Stoptiming
    End If
    
End Sub

⌨️ 快捷键说明

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