📄 form2.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form2
Caption = "call"
ClientHeight = 4770
ClientLeft = 165
ClientTop = 735
ClientWidth = 7035
Icon = "Form2.frx":0000
LinkTopic = "Form2"
LockControls = -1 'True
Picture = "Form2.frx":0E42
ScaleHeight = 4770
ScaleWidth = 7035
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "退出系统"
Height = 495
Left = 4560
TabIndex = 4
Top = 3120
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "进入发卡"
Height = 495
Left = 2760
MaskColor = &H000000FF&
TabIndex = 3
Top = 3120
Width = 1215
End
Begin VB.TextBox Text1
Height = 975
Left = 600
TabIndex = 1
Top = 1440
Width = 5895
End
Begin VB.CommandButton Command1
Caption = "呼叫下位机"
Height = 495
Left = 1080
TabIndex = 0
Top = 3120
Width = 1095
End
Begin MSCommLib.MSComm MSComm1
Left = 360
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
CommPort = 2
DTREnable = -1 'True
RThreshold = 1
End
Begin VB.Timer Timer1
Interval = 5
Left = 1320
Top = 120
End
Begin VB.Label Label1
Alignment = 2 'Center
BackStyle = 0 'Transparent
Caption = "发 送 进 度 显 示 区"
BeginProperty Font
Name = "楷体_GB2312"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 375
Index = 0
Left = 1560
TabIndex = 2
Top = 720
Width = 3255
End
Begin VB.Menu setting
Caption = "波特率设定"
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim s1$, s2$, n%, ss$
MSComm1.Settings = "600,m,8,1"
s1 = InputBox("请输入握手信息(十六进制格式,字母大写)", "握手信息输入")
s2 = Trim(s1)
n = Len(s2)
If (n >= 1) Then
If s2 <= "0F" Then
ss = Mid$(s2, 2, 1)
Else
ss = s2
End If
Text1.Text = s2
Command1.Enabled = True
Timer1.Enabled = True
Else
MsgBox "没有输入任何有效地址!"
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Form2.Hide
Form3.Show
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form2_Load()
MSComm1.PortOpen = True
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Form2.Command1.Enabled = True
Timer1.Enabled = False
MSComm1.RThreshold = 2
Form2.Hide
End Sub
Private Sub MSComm1_OnComm()
Dim din As Variant, buf1$, buf2$, str1$, str2$, str3$, str4$, K%, L%
Select Case MSComm1.CommEvent
Case comEvReceive
din = Trim(MSComm1.Input)
buf1 = Hex(Asc(Mid$(din, 1, 1)))
If buf1 = "0" Then
buf2 = Hex(Asc(Mid$(din, 2, 1)))
MSComm1.Settings = "600,s,8,1"
If buf2 = ss Then
Text1.Text = "11"
Timer1.Enabled = True
End If
ElseIf buf1 = "1" Then
buf2 = Hex(Asc(Mid$(din, 2, 1)))
MSComm1.Settings = "600,s,8,1"
If buf2 = "22" Then
Form2.Command1.Enabled = False
Form2.Command2.Enabled = True
Form2.Command3.Enabled = True
Form2.Command4.Enabled = True
Form2.Command5.Enabled = True
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
ElseIf buf2 = "77" Then
MsgBox "非法命令!"
Form2.Command1.Enabled = True
Form2.Command2.Enabled = False
Form2.Command3.Enabled = False
Form2 Command4.Enabled = False
Form2.Command1.Enabled = True
MSComm1.InBufferCount = 0
ElseIf buf2 = "10" Then
Text1.Text = ""
MsgBox "请输入地址、六位密码、楼层号和房间号", , "提示"
Form3.Show
Form3.Command1.Enabled = True
Form3.Command2.Enabled = False
Form3.Text1.Enabled = True
Form3.Text2.Enabled = True
Form3.Text3.Enabled = True
Form3.Text4.Enabled = True
Form3.Text5.Enabled = False
Form3.Text6.Enabled = False
Form3.Text7.Enabled = False
Form3.Text8.Enabled = False
Form3.Text9.Enabled = False
Form3.Text10.Enabled = False
Form3.Text1.SetFocus
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Form2.Command1.Enabled = False
ElseIf buf2 = "12" Then
Text1.Text = ""
MsgBox "请输入初始化时间", , "提示"
Form3.Show
Form3.Command1.Enabled = False
Form3.Command2.Enabled = True
Form3.Text1.Enabled = False
Form3.Text2.Enabled = False
Form3.Text3.Enabled = False
Form3.Text4.Enabled = False
Form3.Text5.Enabled = True
Form3.Text6.Enabled = True
Form3.Text7.Enabled = True
Form3.Text8.Enabled = True
Form3.Text9.Enabled = True
Form3.Text10.Enabled = True
Form3.Text5.SetFocus
ElseIf buf2 = "13" Then
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
ElseIf buf2 = "23" Then
MsgBox "硬件故障!"
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
ElseIf buf2 = "21" Then
MsgBox "自检完毕,一切正常!"
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
ElseIf buf2 = "55" Then
MsgBox "无新信息!"
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
ElseIf buf2 = "3F" Then
Form2.Command1.Enabled = False
Form2.Command2.Enabled = False
Form2.Command3.Enabled = False
Form2.Command4.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
MSComm1.RThreshold = 9
MSComm1.InBufferCount = 0
ElseIf buf2 = "43" Then
MsgBox "数据处理错误,请重新连接!"
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Form2.Command1.Enabled = False
Form2.Hide
Form1.Show
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 2
ElseIf buf2 = "44" Then
MsgBox "数据接收完毕!"
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Form2.Command1.Enabled = False
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 2
Text1.Text = "34"
Timer1.Enabled = True
ElseIf buf2 = "35" Then
MsgBox "数据已更新!"
Command1.Enabled = True
Command5.Enabled = True
Form2.Command1.Enabled = False
Form2.Command2.Enabled = True
Form2.Command3.Enabled = True
Form2.Command4.Enabled = True
Form2.Hide
Form1.Show
MSComm1.InBufferCount = 0
End If
ElseIf buf1 = "2" Then
Form2.Data1.Recordset.AddNew
buf2 = Hex(Asc(Mid$(din, 2, 1)))
MSComm1.Settings = "600,s,8,1"
If buf2 = "18" Then
Form2.Text1.Text = "总控卡"
End If
If buf2 = "28" Then
Form2.Text1.Text = "楼层卡"
End If
If buf2 = "38" Then
Form2.Text1.Text = "客户卡"
End If
buf2 = Hex(Asc(Mid$(din, 3, 1)))
Form2.Text2.Text = buf2
buf2 = Hex(Asc(Mid$(din, 4, 1)))
If buf2 = "0" Then
Form2.Text5.Text = "日"
ElseIf buf2 = "1" Then
Form2.Text5.Text = "一"
ElseIf buf2 = "2" Then
Form2.Text5.Text = "二"
ElseIf buf2 = "3" Then
Form2.Text5.Text = "三"
ElseIf buf2 = "4" Then
Form2.Text5.Text = "四"
ElseIf buf2 = "5" Then
Form2.Text5.Text = "五"
ElseIf buf2 = "6" Then
Form2.Text5.Text = "六"
End If
buf2 = Hex(Asc(Mid$(din, 5, 1)))
str1 = buf2 '分钟
buf2 = Hex(Asc(Mid$(din, 6, 1)))
str2 = buf2 '时钟
str1 = str2 + ":" + str1
Form2.Text4.Text = str1
buf2 = Hex(Asc(Mid$(din, 7, 1)))
str1 = buf2 '日期
buf2 = Hex(Asc(Mid$(din, 8, 1)))
str2 = buf2 '月份
buf2 = Hex(Asc(Mid$(din, 9, 1)))
If buf2 < "F" Then
buf2 = "200" + buf2
Else: buf2 = "20" + buf2
End If
str3 = buf2
str1 = str3 + "/" + str2 + "/" + str1
Form2.Text3.Text = str1
Form2.Data2.RecordSource = "select * from 地址与房间号对应信息 where 地址='" & ss & " '"
Form2.Data2.Refresh
Form2.Text6.Text = Form2.Data2.Recordset.Fields("房间号")
Form2.Data1.Recordset.Fields("IC卡类型") = Form2.Text1.Text
Form2.Data1.Recordset.Fields("卡号") = Form2.Text2.Text
Form2.Data1.Recordset.Fields("日期") = Form2.Text3.Text
Form2.Data1.Recordset.Fields("房间号") = Form2.Text6.Text
Form2.Data1.Recordset.Fields("时间") = Form2.Text4.Text
Form2.Data1.Recordset.Fields("星期") = Form2.Text5.Text
Form2.Data1.Recordset.Update
Form2.Data1.Recordset.MoveLast
Text1.Text = "33"
Timer1.Enabled = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 2
End If
Case comEventRxOver
MSComm1.InBufferCount = 0
MsgBox "ERROR"
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -