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

📄 form1.frm

📁 读取FP23和SR23的数据
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{B6C10482-FB89-11D4-93C9-006008A7EED4}#1.0#0"; "Apisoft.ocx"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8070
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10800
   LinkTopic       =   "Form1"
   ScaleHeight     =   8070
   ScaleWidth      =   10800
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command7 
      Caption         =   "断开"
      Height          =   615
      Left            =   5280
      TabIndex        =   25
      Top             =   0
      Width           =   1575
   End
   Begin TeeChart.TChart TChart2 
      Height          =   2415
      Left            =   6480
      TabIndex        =   23
      Top             =   720
      Width           =   4215
      Base64          =   $"Form1.frx":0000
   End
   Begin TeeChart.TChart TChart1 
      Height          =   4095
      Left            =   120
      TabIndex        =   10
      Top             =   3360
      Width           =   10575
      Base64          =   $"Form1.frx":0350
   End
   Begin VB.CommandButton Command6 
      Caption         =   "form2"
      Height          =   495
      Left            =   5760
      TabIndex        =   24
      Top             =   7560
      Width           =   1455
   End
   Begin VB.TextBox Text14 
      Height          =   495
      Left            =   4440
      TabIndex        =   19
      Text            =   "Text14"
      Top             =   2640
      Width           =   1815
   End
   Begin VB.TextBox Text13 
      Height          =   495
      Left            =   4440
      TabIndex        =   18
      Text            =   "Text13"
      Top             =   2040
      Width           =   1815
   End
   Begin VB.TextBox Text12 
      Height          =   375
      Left            =   4440
      TabIndex        =   17
      Text            =   "Text12"
      Top             =   1560
      Width           =   1815
   End
   Begin VB.TextBox Text11 
      Height          =   375
      Left            =   4440
      TabIndex        =   16
      Text            =   "Text11"
      Top             =   1080
      Width           =   1815
   End
   Begin VB.TextBox Text10 
      Height          =   495
      Left            =   120
      TabIndex        =   15
      Text            =   "Text10"
      Top             =   2640
      Width           =   1935
   End
   Begin VB.TextBox Text9 
      Height          =   495
      Left            =   120
      TabIndex        =   14
      Text            =   "Text9"
      Top             =   2040
      Width           =   1935
   End
   Begin VB.TextBox Text8 
      Height          =   375
      Left            =   120
      TabIndex        =   13
      Text            =   "Text8"
      Top             =   1560
      Width           =   1935
   End
   Begin VB.TextBox Text7 
      Height          =   375
      Left            =   120
      TabIndex        =   12
      Text            =   "Text7"
      Top             =   1080
      Width           =   1935
   End
   Begin VB.CommandButton Command5 
      Caption         =   "停止"
      Height          =   615
      Left            =   8520
      TabIndex        =   11
      Top             =   0
      Width           =   1455
   End
   Begin VB.TextBox Text6 
      Height          =   375
      Left            =   9960
      TabIndex        =   9
      Text            =   "Text6"
      Top             =   120
      Width           =   735
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   9120
      Top             =   120
   End
   Begin VB.TextBox Text4 
      Height          =   495
      Left            =   2160
      TabIndex        =   7
      Text            =   "Text4"
      Top             =   2640
      Width           =   2175
   End
   Begin VB.TextBox Text3 
      Height          =   495
      Left            =   2160
      TabIndex        =   6
      Text            =   "Text3"
      Top             =   2040
      Width           =   2175
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   2160
      TabIndex        =   5
      Text            =   "Text2"
      Top             =   1080
      Width           =   2175
   End
   Begin VB.CommandButton Command4 
      Caption         =   "开始"
      Height          =   615
      Left            =   6960
      TabIndex        =   4
      Top             =   0
      Width           =   1575
   End
   Begin VB.CommandButton Command3 
      Caption         =   "连接"
      Height          =   615
      Left            =   3600
      TabIndex        =   3
      Top             =   0
      Width           =   1695
   End
   Begin VB.CommandButton Command2 
      Caption         =   "关闭"
      Height          =   615
      Left            =   1800
      TabIndex        =   2
      Top             =   0
      Width           =   1695
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   8640
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
      ParitySetting   =   2
      DataBits        =   7
   End
   Begin VB.CommandButton Command1 
      Caption         =   "打开"
      Height          =   615
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   2160
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   1560
      Width           =   2175
   End
   Begin VB.TextBox Text5 
      Height          =   375
      Left            =   5760
      TabIndex        =   8
      Text            =   "Text5"
      Top             =   240
      Width           =   1575
   End
   Begin VB.Label Label3 
      Caption         =   "SR23"
      Height          =   255
      Left            =   5040
      TabIndex        =   22
      Top             =   720
      Width           =   735
   End
   Begin VB.Label Label2 
      Caption         =   "SR23"
      Height          =   255
      Left            =   960
      TabIndex        =   21
      Top             =   720
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "FP23"
      Height          =   375
      Left            =   3000
      TabIndex        =   20
      Top             =   720
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Dim str1 As String * 18
Dim i As Long
Dim j As Long
Dim n As String
Dim p As Integer
Dim sstr1 As Variant
Dim lec As Integer
Private Sub Command1_Click()

MSComm1.InputLen = 0                              '控制器
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.InputMode = comInputModeText
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
If Err Then
MsgBox "1串口通讯无效"
Exit Sub
End If

End If
End Sub

Private Sub Command2_Click()

MSComm1.InputLen = 0                              '控制器
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.InputMode = comInputModeText
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False

If Err Then
MsgBox "1串口通讯无效"
Exit Sub
End If

End If
End Sub

Private Sub Command3_Click()
MSComm1.OutBufferCount = 0

MSComm1.Output = "@011W018C0,0001:" & Chr(&HD) '控制器
Sleep 1000
Text1.Text = MSComm1.Input

MSComm1.OutBufferCount = 0
Sleep 1000

MSComm1.Output = "@021W018C0,0001:" & Chr(&HD) '控制器
Sleep 1000
Text8.Text = MSComm1.Input
MSComm1.OutBufferCount = 0
Sleep 1000

MSComm1.Output = "@031W018C0,0001:" & Chr(&HD) '控制器
Sleep 1000
Text12.Text = MSComm1.Input


End Sub

Private Sub Command4_Click()
j = 0

Timer1.Enabled = True

End Sub

Private Sub Command5_Click()
Timer1.Enabled = False
End Sub

Private Sub Command6_Click()
Form2.Show
End Sub

Private Sub Command7_Click()
MSComm1.OutBufferCount = 0

MSComm1.Output = "@011W018C0,0000:" & Chr(&HD) '控制器
Sleep 1000
Text1.Text = MSComm1.Input

MSComm1.OutBufferCount = 0
Sleep 1000

MSComm1.Output = "@021W018C0,0000:" & Chr(&HD) '控制器
Sleep 1000
Text8.Text = MSComm1.Input
MSComm1.OutBufferCount = 0
Sleep 1000

MSComm1.Output = "@031W018C0,0000:" & Chr(&HD) '控制器
Sleep 1000
Text12.Text = MSComm1.Input

End Sub

Private Sub Form_Load()
MSComm1.CommPort = 2
End Sub

Private Sub Timer1_Timer()
j = j + 1
Text6.Text = j
Sleep 1000
MSComm1.OutBufferCount = 0
Text2.Text = "@011R01000:" & Chr(&HD)        '控制器FP23

MSComm1.Output = Text2.Text
Sleep 1000
Text1.Text = MSComm1.Input

Text3.Text = Mid(Text1.Text, 9, 4)
Text4.Text = Val("&H" & Text3.Text) / 10
TChart1.Series(0).asFastLine.AddRealTime j, Val(Text4.Text), "", vbRed
Open "C:\a1.txt" For Append As 1#
Print #1, j, Text1.Text, Text3.Text, Text4.Text
Close #1

Sleep 1000

MSComm1.OutBufferCount = 0
Text7.Text = "@021R01000:" & Chr(&HD)        '控制器SR23-1
MSComm1.Output = Text7.Text
Sleep 1000
Text8.Text = MSComm1.Input



Text9.Text = Mid(Text8.Text, 9, 4)
Text10.Text = Val("&H" & Text9.Text) / 10

Open "C:\a2.txt" For Append As 1#
Print #1, j, Text8.Text, Text9.Text, Text10.Text
Close #1


Sleep 1000
MSComm1.OutBufferCount = 0
Text11.Text = "@031R01000:" & Chr(&HD)        '控制器SR23-2

MSComm1.Output = Text11.Text
Sleep 1000
Text12.Text = MSComm1.Input


Text13.Text = Mid(Text12.Text, 9, 4)
Text14.Text = Val("&H" & Text13.Text) / 10

Open "C:\a3.txt" For Append As 1#
Print #1, j, Text12.Text, Text13.Text, Text14.Text
Close #1


TChart2.Series(0).Clear
TChart2.Series(0).AddXY 0, Val(Text4.Text), "FP23", vbRed
TChart2.Series(0).AddXY -1, Val(Text10.Text), "SR23", vbRed
TChart2.Series(0).AddXY 1, Val(Text14.Text), "SR23", vbRed
End Sub

⌨️ 快捷键说明

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