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

📄 form1.frm

📁 VC++ 和VB串并口开发技术工程应用实例导航》一书的配套源代码串口编程
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8190
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10170
   LinkTopic       =   "Form1"
   ScaleHeight     =   8190
   ScaleWidth      =   10170
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text1 
      Height          =   495
      Left            =   3720
      TabIndex        =   6
      Top             =   1200
      Width           =   1935
   End
   Begin VB.CommandButton Command2 
      Caption         =   "结束"
      Height          =   495
      Left            =   4200
      TabIndex        =   3
      Top             =   4200
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "运行"
      Height          =   495
      Left            =   1800
      TabIndex        =   2
      Top             =   4200
      Width           =   1215
   End
   Begin VB.TextBox Text3 
      Height          =   495
      Left            =   3720
      TabIndex        =   1
      Top             =   3240
      Width           =   1815
   End
   Begin VB.TextBox Text2 
      Height          =   495
      Left            =   3720
      TabIndex        =   0
      Top             =   2280
      Width           =   1815
   End
   Begin VB.Timer Timer2 
      Interval        =   60000
      Left            =   6480
      Top             =   2400
   End
   Begin VB.Timer Timer1 
      Interval        =   30000
      Left            =   6480
      Top             =   1440
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   7800
      Top             =   1920
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label1 
      Caption         =   "发送触发命令"
      Height          =   615
      Left            =   1680
      TabIndex        =   7
      Top             =   1320
      Width           =   1575
   End
   Begin VB.Label Label3 
      Caption         =   "采集的数据"
      Height          =   615
      Left            =   1680
      TabIndex        =   5
      Top             =   2400
      Width           =   1815
   End
   Begin VB.Label Label2 
      Caption         =   "当前日期"
      Height          =   615
      Left            =   1680
      TabIndex        =   4
      Top             =   3240
      Width           =   1695
   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 av As Variant '串口读取保存变量
Dim temperature As Single '温度值
Dim result As Long '中间转换变量
Dim perial As Integer '采样总时间

Private Sub Command1_Click()

'Dim aaa(0 As Byte '定义一个字节型一维数组aaa
'aaa(0) = "&h" + Text1.Text '组合16进制以便发送
Dim aaa As String
aaa = "&H" + Text1.Text

MSComm1.OutBufferCount = 0 '清空输出寄存器
MSComm1.Output = aaa '发送aaa

End Sub



Private Sub Form_Load()

With MSComm1
.CommPort = 1
.Settings = "14400,N,8,1"  '通讯参数 波特率 奇偶校验 数据位 停止位
.PortOpen = True
.SThreshold = 3
.RThreshold = 13
.InputLen = 256


End With

End Sub

Private Sub MSComm1_OnComm()
Dim evmsg As String

Dim b As String '

Select Case MSComm1.CommEvent

Case comEvReceive
     b = MSComm1.Input
' MSComm1.InBufferCount = 0
 'dstart = LBound(receivebyte)
 'dend = UBound(receivebyte)
 'For i = 0 To 256
 'shu(i) = CInt(receivebyte(dstar + i))
 'Next i
 
     Text2.Text = b
Case comFrame
     evmsg$ = "监测到文件结束"
Case comEvEOF
     evmsg$ = "帧出错"
Case comRxParity
     evmsg$ = "奇偶错"
     
End Select
 
End Sub

























⌨️ 快捷键说明

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