📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmmain
BorderStyle = 3 'Fixed Dialog
Caption = "串口通信系统"
ClientHeight = 10485
ClientLeft = 45
ClientTop = 435
ClientWidth = 9915
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 10485
ScaleWidth = 9915
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog comdialog
Left = 8520
Top = 6120
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSCommLib.MSComm MSComm3
Left = 8520
Top = 5280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin MSCommLib.MSComm MSComm2
Left = 8520
Top = 4560
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
RThreshold = 1
End
Begin VB.Timer drwtimer
Interval = 1000
Left = 8640
Top = 3240
End
Begin MSCommLib.MSComm ctrmscomm
Left = 8520
Top = 3840
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = 0 'False
End
Begin VB.Timer ctrtimer
Enabled = 0 'False
Interval = 1000
Left = 8640
Top = 2640
End
Begin VB.Frame Frame3
Caption = "发送内容"
Height = 1215
Left = 480
TabIndex = 8
Top = 9000
Width = 7575
Begin VB.TextBox txtmessage
Height = 375
Left = 5280
TabIndex = 13
Top = 600
Width = 1695
End
Begin VB.ComboBox cbohexascii
Height = 300
Left = 5280
TabIndex = 10
Text = "按ASCII码发送"
Top = 240
Width = 1695
End
Begin VB.TextBox txtsend
Height = 735
Left = 240
TabIndex = 9
Top = 240
Width = 4815
End
End
Begin VB.Frame Frame2
Caption = "接收显示"
Height = 6975
Left = 480
TabIndex = 6
Top = 1920
Width = 7800
Begin VB.PictureBox picshow
AutoRedraw = -1 'True
AutoSize = -1 'True
Height = 6135
Left = 0
ScaleHeight = 405
ScaleMode = 3 'Pixel
ScaleWidth = 509
TabIndex = 23
Top = 240
Width = 7695
End
Begin VB.TextBox txtreceivedec
Height = 1815
Left = 1680
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 12
Top = 240
Width = 5655
End
Begin VB.ComboBox cbotemper
Height = 315
Left = 5880
TabIndex = 20
Text = "30"
Top = 6480
Width = 615
End
Begin VB.HScrollBar hscroll1
Height = 495
Left = 0
Max = 12000
TabIndex = 17
Top = 6360
Width = 4095
End
Begin VB.TextBox txtreceivehex
Height = 1815
Left = 1680
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 11
Top = 2160
Width = 5655
End
Begin VB.TextBox txtreceiveascii
Height = 1935
Left = 1680
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 7
Top = 4080
Width = 5655
End
Begin VB.Label Label5
Caption = "摄氏度"
Height = 255
Left = 6600
TabIndex = 24
Top = 6480
Width = 735
End
Begin VB.Label Label4
Caption = "十进制显示:"
Height = 495
Left = 360
TabIndex = 22
Top = 1080
Width = 1095
End
Begin VB.Label Label3
Alignment = 1 'Right Justify
Caption = "阈值温度:"
Height = 375
Left = 4680
LinkTimeout = 0
TabIndex = 21
Top = 6480
Width = 1215
End
Begin VB.Label Label2
Caption = "十六进制显示:"
Height = 375
Left = 240
TabIndex = 16
Top = 3000
Width = 1455
End
Begin VB.Label Label1
Caption = "ASCII码显示:"
Height = 375
Left = 240
TabIndex = 15
Top = 4680
Width = 1335
End
End
Begin VB.Frame Frame1
Caption = "操作提示"
Height = 1455
Left = 480
TabIndex = 0
Top = 360
Width = 7815
Begin VB.CommandButton cmdsavepic
Caption = "保存图片"
Height = 375
Left = 3360
TabIndex = 25
Top = 960
Width = 975
End
Begin VB.CommandButton cmdquit
Caption = "关闭系统"
Height = 375
Left = 6000
TabIndex = 19
Top = 960
Width = 1455
End
Begin VB.CommandButton cmdsavetxt
Caption = "保存文本"
Height = 375
Left = 1800
TabIndex = 18
Top = 960
Width = 1335
End
Begin VB.CommandButton cmddraw
Caption = "曲线显示"
Height = 375
Left = 240
TabIndex = 14
Top = 960
Width = 1335
End
Begin VB.CommandButton cmdclear
Caption = "清除数据"
Height = 375
Left = 4560
TabIndex = 5
Top = 960
Width = 1335
End
Begin VB.CommandButton cmdsetting
Caption = "设置参数"
Height = 375
Left = 240
TabIndex = 4
Top = 360
Width = 1575
End
Begin VB.CommandButton cmdreceive
Caption = "开始接收"
Height = 375
Left = 5760
TabIndex = 3
Top = 360
Width = 1695
End
Begin VB.CommandButton cmdmanualsend
Caption = "手动发送"
Height = 375
Left = 3840
TabIndex = 2
Top = 360
Width = 1575
End
Begin VB.CommandButton cmdautosend
Caption = "自动发送"
Height = 375
Left = 2040
TabIndex = 1
Top = 360
Width = 1455
End
End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim x1 As Integer
Dim y1 As Double
Dim flagshow As Boolean '记录显示方式是曲线显示还是文本显示
Dim bytsendbyte() As Byte
Dim intoutmode As Integer
Dim alltemper() As Double
Const xstep = 20
Const ystep = 7
Const picwidth = 20 '一个屏幕所要画的点数
Private Sub cbohexascii_click()
If frmmain.cbohexascii.Text = "按ASCII码" Then
intoutmode = 0
Else
intoutmode = 1
End If
End Sub
'自动发送
'**************************************
Private Sub cmdautosend_Click()
If frmmain.cmdautosend.Caption = "自动发送" Then
If txtsend.Text = "" Then
MsgBox ("请输入要发送的数据!")
Else
If Not frmmain.ctrmscomm.PortOpen Then
frmmain.ctrmscomm.CommPort = intport '打开串行口,准备发送
frmmain.ctrmscomm.Settings = strset
frmmain.ctrmscomm.PortOpen = True
End If
frmmain.ctrtimer.Interval = inttime '激活时钟,进行发送
frmmain.ctrtimer.Enabled = True
frmmain.cmdautosend.Caption = "停止发送"
End If
Else
frmmain.ctrtimer.Enabled = False
frmmain.ctrmscomm.PortOpen = False
frmmain.cmdautosend.Caption = "自动发送"
txtmessage.Text = "停止发送"
End If
End Sub
'清除
'**************************************
Private Sub cmdclear_Click()
Dim byttemp(0) As Byte
ReDim bytreceivebyte(0) '清空已接收的数据
ReDim alltemper(0) ' 清空接收的画图数据
intreceivelen = 0
txtreceiveascii.Text = ""
txtreceivehex.Text = ""
txtreceivedec.Text = ""
txtmessage.Text = ""
txtsend.Text = ""
drwtimer.Enabled = False
picshow.Cls
Call paintXY(0)
End Sub
Private Sub cmddraw_Click()
If cmddraw.Caption = "曲线显示" Then
drwtimer.Interval = 1000
drwtimer.Enabled = True
frmmain.picshow.Enabled = True
frmmain.picshow.Visible = True
cmddraw.Caption = "文本显示"
MSComm2.PortOpen = False
If Not MSComm3.PortOpen Then '打开串行口
MSComm3.CommPort = intport
MSComm3.Settings = strset
MSComm3.PortOpen = True
End If
flagshow = Not flagshow
Else
frmmain.picshow.Visible = False
cmddraw.Caption = "曲线显示"
MSComm3.PortOpen = False
MSComm2.PortOpen = True
drwtimer.Enabled = False
flagshow = Not flagshow
End If
End Sub
'手动发送
'******************************
Private Sub cmdmanualsend_Click()
If cmdmanualsend.Caption = "手动发送" Then
If txtsend.Text = "" Then
MsgBox ("请输入要发送的数据!")
Else
If Not frmmain.ctrmscomm.PortOpen Then '打开串行口
frmmain.ctrmscomm.CommPort = intport
frmmain.ctrmscomm.Settings = strset
frmmain.ctrmscomm.PortOpen = True
End If
Call ctrtimer_Timer
cmdmanualsend.Caption = "停止发送"
End If
Else:
frmmain.ctrtimer.Enabled = False
frmmain.ctrmscomm.PortOpen = False
cmdmanualsend.Caption = "手动发送"
txtmessage.Text = "停止发送"
End If
End Sub
Private Sub cmdquit_Click()
Dim IntR As Integer
IntR = MsgBox("确认要退出系统吗?", vbYesNo, "退出确认")
If IntR = vbYes Then
End
End If
End Sub
'开始接收
'**************************************
Private Sub cmdreceive_Click()
If cmdreceive.Caption = "开始接收" Then
If Not frmmain.MSComm2.PortOpen Then
frmmain.MSComm2.CommPort = intport
frmmain.MSComm2.Settings = strset
frmmain.MSComm2.InputLen = 0
frmmain.MSComm2.InputMode = 1 '以文本方式接收数据
frmmain.MSComm2.InBufferCount = 0 '清空接受缓冲区
frmmain.MSComm2.RThreshold = 1 '接收到数据即触发OnComm
frmmain.MSComm2.PortOpen = True
End If
frmmain.cmdreceive.Caption = "停止接收"
Else
If flagshow = False Then
If frmmain.MSComm3.PortOpen = True Then
frmmain.MSComm3.PortOpen = False
Else
frmmain.MSComm2.PortOpen = False
End If
Else
frmmain.MSComm2.PortOpen = False
End If
cmdreceive.Caption = "开始接收"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -