frmmain.frm

来自「10句话就可以写一个利用MSComm进行rs232通行的vb程序」· FRM 代码 · 共 76 行

FRM
76
字号
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "数据接收"
   ClientHeight    =   405
   ClientLeft      =   4515
   ClientTop       =   2820
   ClientWidth     =   5235
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   8.25
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "frmCommWizard"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   405
   ScaleWidth      =   5235
   Begin VB.TextBox txtHexEditHex 
      Height          =   255
      Left            =   480
      TabIndex        =   0
      Top             =   0
      Width           =   4455
   End
   Begin MSCommLib.MSComm ctrMSComm 
      Left            =   3600
      Top             =   120
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      InputLen        =   8
   End
   Begin VB.Label Label1 
      Caption         =   "接收:"
      Height          =   375
      Left            =   0
      TabIndex        =   1
      Top             =   120
      Width           =   495
   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 ctrMSComm_OnComm()
    Dim bytInput() As Byte
    Select Case frmMain.ctrMSComm.CommEvent
           Case comEvReceive
                frmMain.ctrMSComm.InputMode = comInputModeBinary
                bytInput = frmMain.ctrMSComm.Input
                frmMain.txtHexEditHex.Text = frmMain.txtHexEditHex.Text & bytInput(0)
    End Select
End Sub

Private Sub Form_Load()
            frmMain.ctrMSComm.CommPort = 1
            frmMain.ctrMSComm.Settings = "9600,n,8,1"
            frmMain.ctrMSComm.PortOpen = True
            frmMain.ctrMSComm.RThreshold = 1
End Sub


⌨️ 快捷键说明

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