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

📄 form1.frm

📁 这是我们当时计算机接口与通信课程的时候编的两个程序之一
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmMain 
   Caption         =   "021104123 赵翰铭"
   ClientHeight    =   5700
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7545
   LinkTopic       =   "Form1"
   ScaleHeight     =   5700
   ScaleWidth      =   7545
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   4680
      Top             =   120
   End
   Begin MSComDlg.CommonDialog ctrCommonDialog 
      Left            =   2760
      Top             =   5280
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSCommLib.MSComm ctrMSComm 
      Left            =   2160
      Top             =   5280
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Frame fraSendFile 
      Caption         =   "发送文件"
      Height          =   1695
      Left            =   120
      TabIndex        =   10
      Top             =   3600
      Width           =   7215
      Begin VB.CommandButton cmdFileSend 
         Caption         =   "传送"
         Height          =   375
         Left            =   1680
         TabIndex        =   17
         Top             =   1200
         Width           =   1215
      End
      Begin VB.CommandButton cmdFileSave 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   16
         Top             =   720
         Width           =   1215
      End
      Begin VB.CommandButton cmdFileOpen 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   15
         Top             =   240
         Width           =   1215
      End
      Begin VB.TextBox txtReceiveDir 
         Height          =   375
         Left            =   1680
         TabIndex        =   14
         Top             =   720
         Width           =   3975
      End
      Begin VB.TextBox txtSendDir 
         Height          =   375
         Left            =   1680
         TabIndex        =   13
         Top             =   240
         Width           =   3975
      End
      Begin VB.OptionButton optReceive 
         Caption         =   "接受文件"
         Height          =   375
         Left            =   480
         TabIndex        =   12
         Top             =   720
         Width           =   1335
      End
      Begin VB.OptionButton optSend 
         Caption         =   "发送文件"
         Height          =   375
         Left            =   480
         TabIndex        =   11
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.TextBox txtIp 
      Enabled         =   0   'False
      Height          =   375
      Left            =   5880
      TabIndex        =   5
      Top             =   120
      Width           =   1455
   End
   Begin VB.CommandButton cmdSetPort 
      Caption         =   "设置串口"
      Height          =   375
      Left            =   3240
      TabIndex        =   3
      Top             =   120
      Width           =   1215
   End
   Begin VB.CommandButton cmdClosePort 
      Caption         =   "关闭串口"
      Height          =   375
      Left            =   1680
      TabIndex        =   2
      Top             =   120
      Width           =   1215
   End
   Begin VB.CommandButton cmdOpenPort 
      Caption         =   "打开串口"
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   1215
   End
   Begin VB.Frame fraSendText 
      Caption         =   "发送信息"
      Height          =   2895
      Left            =   120
      TabIndex        =   0
      Top             =   600
      Width           =   7215
      Begin RichTextLib.RichTextBox rtfReceive 
         Height          =   1935
         Left            =   1680
         TabIndex        =   9
         Top             =   840
         Width           =   5295
         _ExtentX        =   9340
         _ExtentY        =   3413
         _Version        =   393217
         TextRTF         =   $"Form1.frx":0000
      End
      Begin VB.CommandButton cmdReceiveText 
         Caption         =   "自动发送"
         Height          =   375
         Left            =   120
         TabIndex        =   8
         Top             =   840
         Width           =   1455
      End
      Begin VB.TextBox txtSend 
         Height          =   375
         Left            =   1680
         TabIndex        =   7
         Top             =   240
         Width           =   5295
      End
      Begin VB.CommandButton cmdSendText 
         Caption         =   "发送"
         Height          =   375
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   1455
      End
   End
   Begin MSWinsockLib.Winsock ctrWinsock 
      Left            =   3240
      Top             =   5280
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Caption         =   "IP:"
      Height          =   375
      Left            =   5520
      TabIndex        =   4
      Top             =   120
      Width           =   255
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'************************************************
Dim intCommPort As Long         '串口号
Dim strCommSettings As String   '串口设置
Public time As Integer

Dim intOutBufferSize As Long    '发送缓冲区大小
Dim intInBufferSize As Long     '接收缓冲区大小
Dim intColorSet() As Long       '用于记录消息显示的格式
Dim intArrayCount As Long       '用于记录消息显示的格式
'************************************************



'*************************************************
'设置串行口
'为参数设置提供公共接口
'*************************************************

Public Sub SetComm(strSet As String, intPort As Long, intOutBuffer As Long)
    strCommSettings = strSet
    intCommPort = intPort
    intOutBufferSize = intOutBuffer
End Sub


'*************************************************
'获取串行口设置
'返回串口设置(波特率等)
'*************************************************

Public Function GetSettings() As String
    GetSettings = strCommSettings
    
End Function

'**************************************************
'获取当前串口号
'
'**************************************************

Public Function GetCommPort() As Long
    GetCommPort = intCommPort
    
End Function

'**************************************************
'获取当前发送缓冲区大小
'
'**************************************************

Public Function GetOutBuffer() As Long
    GetOutBuffer = intOutBufferSize
    
End Function

'*************************************************
'打开串行口
'
'*************************************************

Public Sub CommPortOpen()
    
    On Error GoTo PortError
    
    ctrMSComm.CommPort = intCommPort                        '设置串行口号
    
    If ctrMSComm.PortOpen = True Then
        ctrMSComm.PortOpen = False
    End If
    ctrMSComm.Settings = strCommSettings                    '设置波特率.奇偶校验位.数据位和停止位
    ctrMSComm.InBufferSize = intInBufferSize                '设置接收缓冲区的字节长度
    
    ctrMSComm.InBufferCount = 0                             '清除接收缓冲区数据
    
    ctrMSComm.OutBufferSize = intOutBufferSize              '设置发送缓冲区字节长度
    ctrMSComm.OutBufferCount = 0                            '清除发送缓冲区数据
    ctrMSComm.RThreshold = 1                                '每次接收到字符即产生OnComm事件
    'ctrMSComm.Handshaking = comRTSXOnXOff
    
    frmMain.ctrMSComm.InputLen = 100
    
    
        
    ctrMSComm.PortOpen = True

PortError:
    Select Case Err.Number
        Case 8005
            MsgBox ("该串口已经被占用,请换其它串口!")
    End Select

End Sub

'*************************************************
'关闭串行口
'
'*************************************************


Public Sub CommPortClose()
    
    Dim strTemp As String
    
    If ctrMSComm.PortOpen = True Then
        ctrMSComm.PortOpen = False
        strTemp = "设置:关闭串行口!"
        Call ReceiveDisplay(strTemp, 3)
    Else
        strTemp = "设置:串行口已关闭!"
        Call ReceiveDisplay(strTemp, 3)
        
    End If

⌨️ 快捷键说明

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