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

📄 串行通信_数据传输_发送端f.frm

📁 VB做的串口通讯的例子
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "数据传输"
   ClientHeight    =   3645
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3060
   LinkTopic       =   "Form1"
   ScaleHeight     =   3645
   ScaleWidth      =   3060
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "结    束"
      Height          =   375
      Left            =   720
      TabIndex        =   3
      Top             =   2880
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Appearance      =   0  'Flat
      Height          =   975
      Left            =   360
      MultiLine       =   -1  'True
      TabIndex        =   0
      Text            =   "串行通信_数据传输_发送端F.frx":0000
      Top             =   600
      Width           =   2415
   End
   Begin VB.CommandButton Command1 
      Caption         =   "发    送"
      Height          =   375
      Left            =   720
      TabIndex        =   1
      Top             =   1920
      Width           =   1815
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   1440
      Top             =   2280
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "放送数据区"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   600
      TabIndex        =   2
      Top             =   240
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'发送数据
'在代码中凡以****作为注释的,在以后的实时通信工程中必须删除
Option Explicit
Dim Cst() As Byte


Private Sub Form_Load()
    
    Cst = "this is test string"
    
    
    MSComm1.CommPort = 1            '指定Com1口作为通信端口
    MSComm1.PortOpen = True         '打开串行端口
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.InputLen = 0            'default
    MSComm1.InputMode = comInputModeBinary
    
    
    MSComm1.OutBufferCount = 0
    Text1.Text = Cst
    
    MSComm1.Output = Cst      '将输入字符串写入发送缓冲区
   
    Debug.Print MSComm1.OutBufferCount, MSComm1.OutBufferSize
    
End Sub

Private Sub Command1_click()
Dim aaa(100) As Byte
aaa(0) = Hex(104)
'aaa(1) = Hex(161)
Debug.Print aaa
Debug.Print aaa(0)
    MSComm1.Output = aaa ' Cst         '将输入字符串写入发送缓冲区
    Debug.Print MSComm1.OutBufferCount, MSComm1.OutBufferSize
'如果有串口连线作实时传输,下面这条语句是不用的
'将发送字符串也送到注册数据库
 '  SaveSetting "TestMSComm", "SEC1", "Key1", strOut    '****
End Sub

Private Sub Command2_Click()
    MSComm1.PortOpen = False        '关闭端口
    Unload Me
End Sub

⌨️ 快捷键说明

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