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

📄 form1.frm

📁 串口编程协议接收
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Frm 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   11115
   ScaleWidth      =   15240
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox txt 
      Height          =   615
      Left            =   360
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   480
      Width           =   4575
   End
   Begin MSCommLib.MSComm com 
      Left            =   7080
      Top             =   240
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
End
Attribute VB_Name = "Frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Dim bRecData(512) As Byte '接收字节数组
'Dim iRecNum As Integer      '字节存储的地址指针
'Dim bTrnData() As Byte      '发送字节的可变指针
Dim aa As String


Sub com_OnComm()
If txt.Text = "00 " Then
txt.Text = ""
End If
'MsgBox "oncom" '
 Select Case com.CommEvent
    Case comEvReceive          '接收事件中断
    'MsgBox "comEvReceive  "
    ' bRecData(iRecNum) = AscB(com.Input)          '从缓冲区取出一个字节,赋给bRecData
    aa = Hex(AscB(com.Input))
    If Len(aa) = 1 Then
    aa = "0" + aa
    End If
     txt.Text = txt.Text + aa + " "
    ' iRecNum = iRecNum + 1          '地址指针加一
    ' If iRecNum >= 512 Then          '地址指针清零
    '   iRecNum = 0          '
    ' End If
  End Select
 End Sub

Private Sub Form_Load()
With com
.CommPort = 1
'.InBufferCount = 512
'.OutBufferCount = 512
.InBufferSize = 1024
.Interval = 10     'int in 500 ms
.Settings = "9600,n,8,1"
.InputMode = 1          '二进制接收方式
.InputLen = 1          '每次接收一个字符
.RThreshold = 1          '每收到一个字符就产生中断
.SThreshold = 0          '禁止发送中断
If .PortOpen = False Then
.PortOpen = True          '如果串口未打开则打开
End If
End With

End Sub

⌨️ 快捷键说明

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