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

📄 frmcomm.frm

📁 用VB编写的用于控制步进电机工作的上位机软件。
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmComm 
   Caption         =   "数据传输"
   ClientHeight    =   4755
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4695
   LinkTopic       =   "Form1"
   ScaleHeight     =   4755
   ScaleWidth      =   4695
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdStart 
      Caption         =   "启  动"
      Height          =   615
      Left            =   1800
      TabIndex        =   6
      Top             =   3240
      Width           =   1095
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   3720
      Top             =   2280
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
   End
   Begin VB.CommandButton cmdReturn 
      Caption         =   "返  回"
      Height          =   615
      Left            =   3120
      TabIndex        =   5
      Top             =   3240
      Width           =   1095
   End
   Begin VB.CommandButton cmdOutput 
      Caption         =   "发  送"
      Height          =   615
      Left            =   480
      TabIndex        =   4
      Top             =   3240
      Width           =   1095
   End
   Begin VB.TextBox txtInput2 
      Height          =   375
      Left            =   2880
      TabIndex        =   3
      Text            =   "0"
      Top             =   1680
      Width           =   855
   End
   Begin VB.TextBox txtInput1 
      Height          =   375
      Left            =   2880
      TabIndex        =   2
      Text            =   "0"
      Top             =   1080
      Width           =   855
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "请输入Y轴上的点数:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Left            =   720
      TabIndex        =   1
      Top             =   1800
      Width           =   1995
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "请输入X轴上的点数:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Left            =   720
      TabIndex        =   0
      Top             =   1200
      Width           =   1995
   End
End
Attribute VB_Name = "frmComm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdOutput_Click()
   msg1$ = "输入不能为空或0"
   msg2$ = "输入超出范围"
   msg3$ = "通信有误,请测试串口"
   Title1$ = "输入有误"
   Title2$ = "通信错误"
   
   MSComm1.PortOpen = True
   MSComm1.Output = Str(2)
   While (MSComm1.InBufferCount = 0)
   Wend
   If (MSComm1.Input <> "A") Then
      MsgBox msg3, 0, Title2
      GoTo Toend
   End If
   
   If (txtInput1.Text = "") Or (txtInput1.Text = 0) Or _
      (txtInput2.Text = "") Or (txtInput2.Text = 0) Then
      MsgBox msg1, 0, Title1
      GoTo Toend
   End If
   If (txtInput1.Text > 20) Or (txtInput2.Text > 20) Then
      MsgBox msg2, 0, Title1
      GoTo Toend
   End If
   
   MSComm1.Output = txtInput1.Text
   MSComm1.Output = "A"
   MSComm1.Output = txtInput2.Text
   MSComm1.Output = "A"
Toend:
End Sub

Private Sub cmdReturn_Click()
   If MSComm1.PortOpen Then MSComm1.PortOpen = False
   frmComm.Hide
   frmMain.Show
End Sub

Private Sub cmdStart_Click()
   If Not MSComm1.PortOpen Then MSComm1.PortOpen = True
   MSComm1.Output = Str(3)
   MSComm1.PortOpen = False
End Sub

Private Sub Form_Load()
   MSComm1.CommPort = sPort
   MSComm1.Settings = sBoud
   MSComm1.InputLen = 0
   txtInput1.Text = MSComm1.CommPort
End Sub

Private Sub MSComm1_OnComm()
   If MSComm1.Input = "B" Then
      MsgBox "通信成功!", 0, "通信"
      MSComm1.Output = "B"
   Else
      MsgBox "请检测端口,再发一次!", 0, "通信"
   End If
   If MSComm1.PortOpen Then MSComm1.PortOpen = False
End Sub

⌨️ 快捷键说明

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