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

📄 form1.frm

📁 自己编写的
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5265
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6075
   LinkTopic       =   "Form1"
   ScaleHeight     =   5265
   ScaleWidth      =   6075
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text3 
      Height          =   2055
      Left            =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   6
      Top             =   3120
      Width           =   5535
   End
   Begin VB.CommandButton btnSend 
      Caption         =   "发送"
      Height          =   495
      Left            =   2400
      TabIndex        =   5
      Top             =   240
      Width           =   855
   End
   Begin VB.TextBox Text2 
      Height          =   1815
      Left            =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   1200
      Width           =   5535
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   3360
      TabIndex        =   2
      Top             =   360
      Width           =   2415
   End
   Begin VB.CommandButton btnClosePort 
      Caption         =   "关闭端口"
      Height          =   495
      Left            =   1320
      TabIndex        =   1
      Top             =   240
      Width           =   975
   End
   Begin VB.CommandButton btnOpenPort 
      Caption         =   "打开端口"
      Height          =   495
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   975
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   840
      Width           =   5535
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub btnClosePort_Click()

  If hCommTest > 0 Then
    mvComClose hCommTest
    Label1.Caption = "端口已关闭。"
    btnOpenPort.Enabled = True
  Else: Label1.Caption = "端口未打开。"
  End If

End Sub

Private Sub btnOpenPort_Click()

  Dim backWords As String
  hCommTest = mvComOpen(("COM1:9600,N,8,1"), 0, 1024, 1024)
  If hCommTest > 0 Then
    Label1.Caption = "端口已打开。"
    btnOpenPort.Enabled = False
  Else: Label1.Caption = "端口打开失败,请重试。"
  End If

End Sub

Private Sub btnSend_Click()

  Dim number As Long
  Dim words, backWords As String
  Dim i, length As Integer
  Dim tmp1, tmp2, tmp3 As String
  If hCommTest = 0 Then
    Label1.Caption = "端口未打开。"
    Exit Sub
  End If
  words = Text1.Text
  words = ToHexString(words, number)
  backWords = mvComSendHexString(hCommTest, words, delay)
  
  If Len(words) = 1 Then
    words = "0" + words
  End If
  length = Len(words)
  For i = 1 To length Step 2
  tmp3 = Mid(words, i, 2)
  tmp2 = tmp2 + tmp3 + " "
  Next i
  words = tmp2
  
  Text2.Text = Text2.Text + words
  Text3.Text = Text3.Text + backWords
  Text1.Text = ""

End Sub

Private Sub Form_Load()

  Text2.Text = "已发送消息:" + vbCrLf
  Text3.Text = "收到信息:" + vbCrLf

End Sub

⌨️ 快捷键说明

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