📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5112
ClientLeft = 60
ClientTop = 348
ClientWidth = 7320
LinkTopic = "Form1"
ScaleHeight = 5112
ScaleWidth = 7320
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Pic
AutoRedraw = -1 'True
Height = 3852
Left = 600
ScaleHeight = 3804
ScaleWidth = 6324
TabIndex = 2
Top = 360
Width = 6372
End
Begin VB.CommandButton Command4
Caption = "Command4"
Height = 372
Left = 5160
TabIndex = 1
Top = 4440
Width = 1215
End
Begin MSCommLib.MSComm MSComm1
Left = 6600
Top = 4440
_ExtentX = 995
_ExtentY = 995
_Version = 393216
DTREnable = -1 'True
InBufferSize = 1536
BaudRate = 4800
InputMode = 1
End
Begin VB.Label Label1
Caption = "Label1"
Height = 252
Left = 720
TabIndex = 0
Top = 4560
Width = 1812
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Adrdata As Integer
Private Sub Command4_Click()
Dim Sdata(1 To 1) As Byte, Rdata() As Byte
Dim dStart As Integer, T3 As Long, An3 As Integer
Dim Dim1, Dim2 As Integer
'Dim DispData As Long
Pic.BackColor = &HFF00&
Pic.Width = 6000
Pic.Height = 4000
Pic.Scale (-10, CInt(Pic.Height - 20))-(Pic.Width, -20)
Pic.DrawWidth = 1
Pic.DrawStyle = 2
For i = 0 To 13
Pic.Line (0, i * 300)-(Pic.Width, i * 300)
Pic.Line (i * 420, 0)-(i * 420, Pic.Height - 20)
CurrentX = 180
CurrentY = 4240 - 300 * i
Print 20 * i
Next i
Pic.DrawStyle = 0
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
'---------------------------以下连接系统-----------------------------------
1:
Sdata(1) = 20 '20表示连接系统
MSComm1.Output = Sdata
Label1.Caption = "连接系统。。。。。"
MSComm1.InBufferCount = 0
Rdata = MSComm1.Input
T3 = GetTickCount
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1 Or GetTickCount - T3 >= 3000
If MSComm1.InBufferCount >= 1 Then
Rdata = MSComm1.Input
dStart = LBound(Rdata)
If Rdata(dStart) = 66 Then '22表示连接成功
Label1.Caption = "连接成功!"
Else
Label1.Caption = "连接失败!"
GoTo 7:
End If
Else
Label1.Caption = "连接chaoshi !"
GoTo 7:
End If
'----------------------------以上是连接系统-----------------------------------
'-------------------------以下是读取记录数据----------------------------------
For Dim1 = 1 To 1 '假设每次发送500个数
If Dim1 = 1 Then
Sdata(1) = 30 '30表示要求接收第一组数据
'+++++++++++++++--------
ElseIf Dim1 = 2 Then
Sdata(1) = 40 '40表示要求接收第二组数据
Else
Sdata(1) = 50 '50表示要求接收第三组数据
End If
MSComm1.Output = Sdata
Label1.Caption = "正在读数。。。。。"
MSComm1.InBufferCount = 0
Rdata = MSComm1.Input
T3 = GetTickCount
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1536 Or GetTickCount - T3 >= 5000
If MSComm1.InBufferCount >= 1536 Then
Rdata = MSComm1.Input
dStart = LBound(Rdata)
'For Dim2 = 0 To 1535
'DataDisp.Text = DataDisp.Text & Rdata(dStart + Dim2) & ","
'Next Dim2
j = 0
For Dim2 = 0 To 1534
Pic.Line (j, 15 * (Rdata(dStart + Dim2)))-(j + 2, 15 * Rdata(dStart + Dim2 + 1)), RGB(0, 0, 256)
j = j + 2
Next Dim2
Else
Label1.Caption = "通信故障!"
End If
Next Dim1
Label1.Caption = "读数完成!"
7:
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -