📄 c0330.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BackColor = &H00FFC0C0&
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
BackColor = &H00FF0000&
DrawStyle = 6 'Inside Solid
DrawWidth = 2
Height = 6000
Left = 480
ScaleHeight = 7841.587
ScaleMode = 0 'User
ScaleWidth = 10824.51
TabIndex = 3
Top = 840
Width = 10000
Begin VB.Label Label1
BackColor = &H00FFFFC0&
Caption = "Label1"
ForeColor = &H00FF8080&
Height = 255
Left = 120
TabIndex = 4
Top = 120
Width = 9187
End
End
Begin VB.TextBox Text1
Height = 375
Left = 480
TabIndex = 2
Text = "Text1"
Top = 240
Width = 10000
End
Begin VB.CommandButton Command2
BackColor = &H0080C0FF&
Caption = "Command2"
Height = 900
Left = 6360
Style = 1 'Graphical
TabIndex = 1
Top = 7080
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "Command1"
Height = 900
Left = 4200
Style = 1 'Graphical
TabIndex = 0
Top = 7080
Width = 975
End
Begin MSCommLib.MSComm MSComm1
Left = 1320
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
CommPort = 4
DTREnable = -1 'True
InputLen = 4
RTSEnable = -1 'True
InputMode = 1
End
Begin VB.Timer Timer1
Interval = 100
Left = 480
Top = 120
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'声明模块级变量.
Dim x1, i, j As Double
Dim p1, p2 As Integer
Dim aa() As Byte
'初始化,确定显示屏(Picture1)尺寸,分度,标题.
Private Sub Form_Load()
'请屏
Cls
'设计显示屏横坐标(时间分度),纵坐标(温度分度),以及显示屏背景颜色.
Label1.BackColor = &HFFFFC0
Label1.ForeColor = &HFF8080
Label1.Caption = "横坐标:每格10秒 纵坐标:每格摄氏10度"
Picture1.BackColor = &HFFFFC0 'vbBlue
'设计显示屏画曲线的风格.
Picture1.AutoSize = True
'设计按钮标题.
Command1.Caption = "启动"
Command2.Caption = "停止"
'设计定时器(Timer1)的定时中断时间(1秒),并设定其无效.
Timer1.Enabled = False
Timer1.Interval = 1000
'为显示屏设计横坐标和纵坐标的分度线.
Picture1.ScaleMode = 0
Picture1.ScaleHeight = 2000
Picture1.ScaleWidth = 6000
For i = 0 To 6000 Step 100
Picture1.Line (i, 0)-(i, 2000), RGB(255, 255, 255) 'vbWhite
Next i
For j = 0 To 2000 Step 100
Picture1.Line (0, j)-(6000, j), RGB(255, 255, 255) 'vbWhite
Next j
'设定通讯口(COM1),通讯参数(波特率9600,无奇偶校验,8位数据位,1个停止位),输入缓冲区为4个字符.
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 4
'设计运行窗体为最大化.
Form1.WindowState = 2
'关闭定通讯口.
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
'点击按钮1,启动定时接收和发送数据.
Private Sub Command1_Click()
x1 = 0
Timer1.Enabled = True
End Sub
'点击按钮2,停止定时接收和发送数据.并退出程序.
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
'定时中断,处理PC机向PLC发送数据,接收PLC的响应的返回数据并绘制各PLC的温控曲线.
Private Sub Timer1_Timer()
'声明过程级随机变量(aa).
ReDim aa(3)
'接收出错转到 eee:
On Error GoTo eee
'打开定通讯口.
MSComm1.PortOpen = True
'中断一次时间X1加1秒.
x1 = x1 + 1
eee:
'PC机接收PLC数据(其中P1是实测温度值,P2是设定温度值).
Do While MSComm1.InBufferCount < 4
Loop
aa = MSComm1.Input
p1 = Int(aa(0) * 255 + aa(1) * 1)
p2 = Int(aa(2) * 255 + aa(3) * 1)
'绘制PLC的温度曲线,并输出温度值.
Picture1.PSet (x1 * 10, 2000 - 10 * p1), vbRed
Picture1.PSet (x1 * 10, 2000 - 10 * p2), vbBlue
Text1.Text = "实测温度:" & Str(p1) & "设定温度:" & Str(p2) & "运行时间:" & Str(x1) & "秒钟"
If x1 >= 6000 Then
Cls
x1 = 0
Else
End If
'关闭定通讯口.
MSComm1.PortOpen = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -