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

📄 frmcomtotcp.frm

📁 这是一本学习串口编程喝计算机监控的好书里面是用VB开发的源代码
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Serial Port to TCP Port"
   ClientHeight    =   5310
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6600
   Icon            =   "frmComToTcp.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   5310
   ScaleWidth      =   6600
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdNetClose 
      Caption         =   "Close"
      Height          =   375
      Left            =   3240
      TabIndex        =   13
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "Connect"
      Height          =   375
      Left            =   2280
      TabIndex        =   12
      Top             =   1080
      Width           =   975
   End
   Begin VB.Timer StatusTimer 
      Interval        =   500
      Left            =   4680
      Top             =   600
   End
   Begin MSWinsockLib.Winsock tcpSock 
      Left            =   2520
      Top             =   600
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin MSComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   255
      Left            =   0
      TabIndex        =   11
      Top             =   5055
      Width           =   6600
      _ExtentX        =   11642
      _ExtentY        =   450
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   2118
            MinWidth        =   2118
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   1588
            MinWidth        =   1588
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   2734
            MinWidth        =   2734
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton cmdClose 
      Caption         =   "Close"
      Height          =   375
      Left            =   1560
      TabIndex        =   2
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton cmdOpen 
      Caption         =   "Open"
      Height          =   375
      Left            =   960
      TabIndex        =   1
      Top             =   1080
      Width           =   615
   End
   Begin VB.TextBox txtHex 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   960
      TabIndex        =   4
      Top             =   120
      Width           =   5535
   End
   Begin VB.CommandButton cmdFind 
      Caption         =   "Find"
      Height          =   375
      Left            =   5040
      TabIndex        =   8
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton cmdCharToHex 
      Caption         =   "Char/Hex"
      Height          =   375
      Left            =   3960
      TabIndex        =   7
      Top             =   1080
      Width           =   975
   End
   Begin VB.CommandButton cmdClear 
      Caption         =   "Clear"
      Height          =   375
      Left            =   5760
      TabIndex        =   9
      Top             =   1080
      Width           =   735
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   3240
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   0   'False
      OutBufferSize   =   1024
      RThreshold      =   1
      SThreshold      =   1
      InputMode       =   1
   End
   Begin VB.TextBox txtResult 
      Height          =   3495
      Left            =   120
      MultiLine       =   -1  'True
      OLEDropMode     =   2  'Automatic
      ScrollBars      =   3  'Both
      TabIndex        =   5
      TabStop         =   0   'False
      Top             =   1560
      Width           =   6375
   End
   Begin VB.TextBox txtChars 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   960
      TabIndex        =   3
      Top             =   600
      Width           =   5535
   End
   Begin VB.CommandButton cmdSetup 
      Caption         =   "Setup"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   1080
      Width           =   735
   End
   Begin VB.Label Label2 
      Caption         =   "Char:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   10
      Top             =   720
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "Hex:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   6
      Top             =   240
      Width           =   735
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub setStatusBar(tcpSock As Control)
  Dim strSock As String
  Dim strCom As String
  On Error Resume Next
  
  strCom = "COM" + Trim(Str(MSComm1.CommPort)) + ": "
  If MSComm1.PortOpen = True Then
    strCom = strCom + "Open"
  Else
    strCom = strCom + "Close"
  End If
  
  With tcpSock
    Select Case .State
      Case 0
        strSock = "Closed"
      Case 1
        strSock = "Open"
      Case 2
        strSock = "Listening"
      Case 3
        strSock = "Connection pending"
      Case 4
        strSock = "Resolving host"
      Case 5
        strSock = "Host resolved"
      Case 6
        strSock = "Connecting"
      Case 7
        strSock = "Connected"
      Case 8
        strSock = "Peer is closing the connection"
      Case 9
        strSock = "Error"
    End Select
    
    StatusBar1.Panels(1).Text = strCom
    StatusBar1.Panels(2).Text = .LocalHostName
    StatusBar1.Panels(3).Text = .LocalIP
    StatusBar1.Panels(4).Text = .RemoteHostIP
    StatusBar1.Panels(5).Text = strSock
  End With
End Sub

Private Sub cmdCharToHex_Click()
  If txtChars.Text = "" And txtHex.Text = "" Then
    MsgBox "You must input some characters in the either TextBox!", vbExclamation + vbOKOnly
    Exit Sub
  End If
    
  If txtChars.Text <> "" And txtHex.Text <> "" Then
    MsgBox "You must not input characters in the both TextBoxes!", vbExclamation + vbOKOnly
    Exit Sub
  End If
    
  If txtHex.Text = "" Then
    txtHex.Text = StringToHexChars(txtChars.Text)
  Else
    txtChars.Text = HexCharsToString(txtHex.Text)
  End If
End Sub

Private Sub cmdClear_Click()
  If Len(Trim(txtHex.SelText)) > 0 Then
    txtHex.Text = ""
    Exit Sub
  End If
    
  If Len(Trim(txtChars.SelText)) > 0 Then
    txtChars.Text = ""
    Exit Sub
  End If
    
  If Len(Trim(txtResult.SelText)) > 0 Then
    txtResult.Text = ""
    ResultString = ""
    Exit Sub
  End If

⌨️ 快捷键说明

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