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

📄 form3.frm

📁 MCS-51单片机双机通信实现程序原代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form3 
   Caption         =   "Form3"
   ClientHeight    =   3075
   ClientLeft      =   60
   ClientTop       =   465
   ClientWidth     =   5730
   LinkTopic       =   "Form3"
   ScaleHeight     =   3075
   ScaleWidth      =   5730
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdCancel 
      Caption         =   "取消"
      Height          =   375
      Left            =   3000
      TabIndex        =   12
      Top             =   2400
      Width           =   1095
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "确定"
      Height          =   375
      Left            =   1320
      TabIndex        =   11
      Top             =   2400
      Width           =   1095
   End
   Begin VB.Frame Frame1 
      Caption         =   "串口设置"
      Height          =   1815
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   5175
      Begin VB.ComboBox ComboStop 
         Height          =   300
         Left            =   1200
         TabIndex        =   10
         Top             =   1320
         Width           =   1095
      End
      Begin VB.ComboBox cmbParity 
         Height          =   300
         Left            =   3600
         TabIndex        =   8
         Top             =   840
         Width           =   1335
      End
      Begin VB.ComboBox ComboData 
         Height          =   300
         Left            =   1200
         TabIndex        =   6
         Top             =   840
         Width           =   1095
      End
      Begin VB.ComboBox cmbBaudRate 
         Height          =   300
         Left            =   3600
         TabIndex        =   4
         Top             =   360
         Width           =   1335
      End
      Begin VB.ComboBox ComboSerial 
         Height          =   300
         Left            =   1200
         TabIndex        =   2
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "停 止 位"
         Height          =   255
         Left            =   360
         TabIndex        =   9
         Top             =   1320
         Width           =   735
      End
      Begin VB.Label Label4 
         Caption         =   " 校验位"
         Height          =   255
         Left            =   2760
         TabIndex        =   7
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label3 
         Caption         =   "数 据 位"
         Height          =   375
         Left            =   360
         TabIndex        =   5
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label2 
         Caption         =   "波特率"
         Height          =   255
         Left            =   2880
         TabIndex        =   3
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "串  口"
         Height          =   255
         Left            =   360
         TabIndex        =   1
         Top             =   360
         Width           =   735
      End
   End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Dim BaudRate As String
Dim Parity As String
Dim Data As String
Dim Serial As String
Dim StopBit As String
Private Sub cmbBaudRate_Scroll()
        BaudRate = cmbBaudRate.Text
End Sub

Private Sub cmbParity_Scroll()
        Parity = cmbParity.Text
End Sub

Private Sub cmdCancel_Click()
      Unload Me
End Sub
Private Sub ComboData_Change()
        Data = ComboData.Text
End Sub

Private Sub ComboSerial_Change()
        Serial = ComboSerial.Text

End Sub

Private Sub ComboStop_Change()
        StopBit = ComboStop.Text
End Sub

Private Sub cmdOK_Click()
     BaudRate = cmbBaudRate.Text
     Parity = cmbParity.Text

  '  Dim port As Integer
    
 '   If (frmZong.Comm.CommPort = 1) Then
 '       port = 0
 '   End If
    
 '   port = frmZong.Comm.CommPort
 '   frmZong.Comm.PortOpen = False
 '
 '   If optCom1.Value = True Then
 '       If (frmZong.Comm.CommPort = 1) = True Then
 '           frmZong.Comm.PortOpen = True
 '       End If
 '   End If
    
 '   If optCom2.Value = True Then
 '       If (frmZong.Comm.CommPort = 2) = True Then
 '           frmZong.Comm.PortOpen = True
 '       End If
 '   End If
     Data = ComboData.Text
     Serial = ComboSerial.Text
     StopBit = ComboStop.Text
     
    If Serial = "COM1" Then
'    Form1.MSComm1.PortOpen = False

    Form1.MSComm1.CommPort = 1
    'Form1.MSComm1.PortOpen = True
    End If
    If Serial = "COM2" Then
    'Form1.MSComm1.PortOpen = False
    Form1.MSComm1.CommPort = 2
    'Form1.MSComm1.PortOpen = True
    End If
    If Serial = "COM3" Then
    ' Form1.MSComm1.PortOpen = False
    Form1.MSComm1.CommPort = 3
    'Form1.MSComm1.PortOpen = True
    End If
      If Serial = "COM4" Then
    ' Form1.MSComm1.PortOpen = False
    Form1.MSComm1.CommPort = 4
    'Form1.MSComm1.PortOpen = True
    End If
 '   frmZong.Comm.PortOpen = False
    Form1.MSComm1.Settings = BaudRate + "," + Parity + "," + Data + "," + StopBit
   '    frmZong.Comm.Settings = "9600" + "," + "N" + ",8" + ",1"
      '  frmZong.Comm.Settings = "9600,N,8,1"
'    frmZong.Comm.PortOpen = True
   Form3.Hide
   
   
End Sub


Private Sub Form_Load()
    cmbBaudRate.AddItem (1200)
    cmbBaudRate.AddItem (2400)
    cmbBaudRate.AddItem (4800)
    cmbBaudRate.AddItem (9600)
    cmbBaudRate.AddItem (115200)
   

    ComboSerial.AddItem ("COM1")
    ComboSerial.AddItem ("COM2")
    ComboSerial.AddItem ("COM3")
    ComboSerial.AddItem ("COM4")

    ComboData.AddItem (8)
    ComboData.AddItem (7)
    ComboData.AddItem (6)
    ComboData.AddItem (5)
    ComboData.AddItem (4)


    ComboStop.AddItem (1)
    ComboStop.AddItem (1.5)
    ComboStop.AddItem (2)
'ComboStop.AddItem (4)

    cmbParity.AddItem ("O")
    cmbParity.AddItem ("E")
    cmbParity.AddItem ("None")
    cmbParity.AddItem ("M")
    cmbParity.AddItem ("N")
    cmbParity.AddItem ("S")

    ComboSerial.Text = "COM1"
    cmbBaudRate.Text = 115200
    ComboData.Text = 8
    ComboStop.Text = 1
    cmbParity.Text = "N"
End Sub

⌨️ 快捷键说明

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