📄 form2.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form2
Caption = "Form2"
ClientHeight = 5550
ClientLeft = 60
ClientTop = 345
ClientWidth = 7065
LinkTopic = "Form2"
ScaleHeight = 5550
ScaleWidth = 7065
StartUpPosition = 3 '窗口缺省
Begin MSCommLib.MSComm MSComm1
Left = 2880
Top = 1080
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Frame Frame1
Caption = "Frame1"
Height = 5055
Left = 120
TabIndex = 0
Top = 240
Width = 6855
Begin VB.Label Label1
Caption = "Label1"
BeginProperty Font
Name = "宋体"
Size = 26.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 2055
Left = 2400
TabIndex = 1
Top = 2160
Width = 3495
End
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rebytes() As Byte
Private Sub Form_Load()
Label1.Caption = "集中器"
MSComm1.RThreshold = 1
MSComm1.InputMode = comInputModeText
MSComm1.CommPort = 2
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim a As String
Dim l As Integer
Dim ln As Integer
Dim s As Integer
Dim c(16) As String * 1
Dim nian As Date
Dim yue As Date
Dim ri As Date
Dim shi As Date
Dim fen As Date
Dim miao As Date
Dim endtime As Long
If (MSComm1.CommEvent = comEvReceive) Then
jiaoyanhe = 0
endtime = 10 + Timer
If flag = 2 Then
Timer2.Interval = 0
'加沿时
End If
Do
b = b + MSComm1.Input
begin = InStr(1, b, "*~1")
begin2 = InStr(1, b, "*~2")
bend = InStr(1, b, "#")
If begin <> 0 And bend <> 0 And bend - begin > 0 Then '1
a = Mid(b, begin, bend - begin + 1)
l = Len(a)
Exit Do
ElseIf begin2 <> 0 And bend <> 0 And bend - begin2 > 0 Then
a = Mid(b, begin2, bend - begin2 + 1)
l = Len(a)
Exit Do
End If
If Time > endtime Then
Exit Do
End If
Loop
'拆包
ReDim bytes(l)
For i = 0 To l - 1
bytes(i) = 0
Next i
Text1 = a
For i = 0 To l - 1
bytes(i) = Asc(Mid(a, i + 1, 1))
Next i
'校验
For i = 0 To l - 3
jiaoyanhe = jiaoyanhe Xor bytes(i)
Next i
If Asc(jiaoyanhe) = bytes(l - 2) Then '2
'****************************************************
If bytes(2) = Asc("1") And bytes(4) = Asc("q") And bytes(6) = Asc("#") Then '3
' For i = 0 To 1000
' Next i
ReDim rebytes(7)
rebytes(0) = Asc("*")
rebytes(1) = Asc("~")
rebytes(2) = Asc("1")
rebytes(3) = Asc("a")
rebytes(4) = Asc("f")
jiaoyanhe = 0
For i = 0 To 4
jiaoyanhe = jiaoyanhe Xor rebytes(i)
Next i
rebytes(5) = Asc(jiaoyanhe)
rebytes(6) = Asc("#")
' MsgBox ("yyyyyyyy")
MSComm1.Output = rebytes
MSComm1.InBufferCount = 0
MSComm1.PortOpen = False
Call Module1.delay
Form1.Show
Load Form1
Form2.Hide
ElseIf bytes(2) = Asc("2") And bytes(4) = Asc("q") And bytes(6) = Asc("#") Then '3
' For i = 0 To 1000
' Next i
ReDim rebytes(7)
rebytes(0) = Asc("*")
rebytes(1) = Asc("~")
rebytes(2) = Asc("2")
rebytes(3) = Asc("a")
rebytes(4) = Asc("f")
jiaoyanhe = 0
For i = 0 To 4
jiaoyanhe = jiaoyanhe Xor rebytes(i)
Next i
rebytes(5) = Asc(jiaoyanhe)
rebytes(6) = Asc("#")
'MsgBox ("yyyyyyyy")
MSComm1.Output = rebytes
MSComm1.InBufferCount = 0
MSComm1.PortOpen = False
Call Module1.delay
Form3.Show
Load Form3
Form2.Hide
End If
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -