📄 searchform.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Searchform
BorderStyle = 3 'Fixed Dialog
Caption = "Searching..."
ClientHeight = 2265
ClientLeft = 4440
ClientTop = 3795
ClientWidth = 5325
Icon = "Searchform.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2265
ScaleWidth = 5325
ShowInTaskbar = 0 'False
StartUpPosition = 1 'CenterOwner
Begin MSComctlLib.ProgressBar ProBar
Height = 495
Left = 120
TabIndex = 6
Top = 1320
Width = 3855
_ExtentX = 6800
_ExtentY = 873
_Version = 393216
Appearance = 1
Scrolling = 1
End
Begin VB.CommandButton CloseForm
Caption = "Stop"
Height = 375
Left = 4200
TabIndex = 5
Top = 1440
Width = 975
End
Begin MSCommLib.MSComm MSComm
Left = 480
Top = 480
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Timer Find_time
Enabled = 0 'False
Interval = 500
Left = 360
Top = 1920
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "(DEC)"
Height = 195
Left = 2520
TabIndex = 4
Top = 780
Width = 420
End
Begin VB.Label lab_dec
Alignment = 1 'Right Justify
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1440
TabIndex = 3
Top = 720
Width = 855
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "(HEX)"
Height = 195
Left = 2520
TabIndex = 2
Top = 240
Width = 420
End
Begin VB.Label lab_hex
Alignment = 1 'Right Justify
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1440
TabIndex = 1
Top = 120
Width = 855
End
Begin VB.Label Label1
Caption = "Address:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 0
Top = 210
Width = 855
End
End
Attribute VB_Name = "Searchform"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SendCount As Byte
Private Sub CloseForm_Click()
Unload Me
End Sub
Private Sub Find_time_Timer()
Dim a As String
Find_time.Enabled = False
SendCount = SendCount + 1
If SendCount > 3 Then
SeachMTID = SeachMTID + 1
ProBar.Value = ProBar.Value + 1
SendCount = 0
End If
With MSComm
.InBufferCount = 0
.OutBufferCount = 0
.RThreshold = 1
End With
If SeachMTID <= 255 Then
Find_time.Enabled = True
Else
ClosePort
' MsgBox LoadResString(147), , LoadResString(124)
Exit Sub
End If
lab_hex.Caption = Hex(SeachMTID)
lab_dec.Caption = SeachMTID
SendDataReady
End Sub
Private Sub Form_Load()
Searchform.Caption = LoadResString(116)
Searchform.Label1.Caption = LoadResString(117)
Searchform.CloseForm.Caption = LoadResString(118)
Searchform.Left = 3000
Searchform.Top = 3000
InitMscomm
lab_hex.Caption = Hex(SeachMTID)
lab_dec.Caption = SeachMTID
ProBar.Max = 256 - SeachMTID
ProBar.Min = 0
ProBar.Value = 0
Find_time.Interval = COMtime + 30
SendCount = 0
With MSComm
.InBufferCount = 0
.OutBufferCount = 0
.RThreshold = 1
End With
SendDataReady
Find_time.Enabled = True
End Sub
Private Sub InitMscomm()
On Error GoTo ErrorHandler
With MSComm
.CommPort = COMport
If .PortOpen = True Then
.PortOpen = False
End If
.Settings = COMbaud + ",n,8,1"
.InputMode = comInputModeBinary '设置或返回 Input 属性取回的数据的类型,文本形式或二进制形式
.NullDiscard = False '确定 null 字符是否从端口传送到接收缓冲区
.InBufferSize = 1000 '设置并返回接收缓冲区的字节数。
.OutBufferSize = 1000 '设置并返回发送缓冲区的字节数。
.InBufferCount = 0 '返回接收缓冲区中等待的字符数。属性设置为 0 来清除接收缓冲区。
.OutBufferCount = 0 '返回在传输缓冲区中等待的字符数。 设置 OutBufferCount 属性为 0 可以清除传输缓冲区。
.InputLen = 0 '设置并返回 Input 属性从接收缓冲区读取的字符数
'设置 InputLen 为 0 时,使用 Input 将使 MSComm 控件读取接收缓冲区中全部的内容。
.SThreshold = 0
.RThreshold = 0 '设置并返回的要接收的字符数。 并将产生 OnComm的omEvReceive事件
.PortOpen = True
End With
Exit Sub
ErrorHandler:
If isEnglish = False Then
MsgBox "串口" + Str(COMport) + " 打开失败", vbCritical '+ vbCrLf + "无此串口或串口已打开"
Else
MsgBox "Opens serial port" + Str(COMport) + "unsuccessful", vbCritical '+ vbCrLf + "无此串口或串口已打开"
End If
End Sub
Private Sub SendDataReady()
Dim i As Byte
Dim temp As Long
DataArr(0) = SeachMTID
DataArr(1) = &H99
DataArr(2) = &H0
DataArr(3) = &H2
DataArr(4) = &H0
DataArr(5) = &H2
For i = 0 To 5
SendBuf(i) = DataArr(i)
Next i
temp = CRC16(6)
SendBuf(6) = CrcDataHI
SendBuf(7) = CrcDataLO
SendLen = 8
ModbusTrans
MSComm.RThreshold = 11 '在 MSComm 控件设置 CommEvent 属性为 comEvReceive
'并产生 OnComm 之前,设置并返回的要接收的字符数。
End Sub
Private Sub ModbusTrans()
Dim i As Byte
Dim Buf As String
On Error GoTo sendfailed
Buf = String(SendLen, Chr(0))
outbyte = StrConv(Buf, vbFromUnicode)
For i = 0 To SendLen - 1
outbyte(i) = SendBuf(i)
Next i
MSComm.Output = outbyte
Exit Sub
sendfailed:
Err.Clear
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm.PortOpen Then
ClosePort
End If
End Sub
Private Sub MSComm_OnComm()
Dim i As Byte
On Error GoTo ErrHandler1
With MSComm
Select Case .CommEvent
Case comEvReceive
.RThreshold = 0
inputbyte = .Input
Reclen = 0
For i = LBound(inputbyte) To UBound(inputbyte)
RecBuf(Reclen) = inputbyte(i)
DataArr(Reclen) = RecBuf(Reclen)
Reclen = Reclen + 1
Next i
CRC16 (Reclen - 2)
If (RecBuf(Reclen - 2) = CrcDataHI) And (RecBuf(Reclen - 1) = CrcDataLO) Then
If RecBuf(0) = SeachMTID Then
AddNewNode RecBuf(8)
SendCount = 5
End If
End If
Find_time.Enabled = True
End Select
End With
Exit Sub
ErrHandler1:
Find_time.Enabled = True
End Sub
Private Sub AddNewNode(ByVal InType As Byte)
Dim nodx As Node
Dim address As String
Dim COMNUM As String
COMNUM = Form1.Label13.Caption
address = Format(SeachMTID, "000")
Select Case InType
Case 0 'U31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "U31_" + Format(SeachMTID, "000"), "U31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_U31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_U31 = "V" + Str(RecBuf(4) / 10)
Case 1 'I31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "I31_" + Format(SeachMTID, "000"), "I31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_I31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_I31 = "V" + Str(RecBuf(4) / 10)
Case 2 'DU31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "DU31_" + Format(SeachMTID, "000"), "DU31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_DU31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_DU31 = "V" + Str(RecBuf(4) / 10)
Case 3 'DI31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "DI31_" + Format(SeachMTID, "000"), "DI31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_DI31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_DI31 = "V" + Str(RecBuf(4) / 10)
Case 4 'p31s
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "P31S_" + Format(SeachMTID, "000"), "P31S " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_P31S = "V" + Str(RecBuf(6) / 100)
HardwareEdit_P31S = "V" + Str(RecBuf(4) / 10)
Case 5 'L31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "L31_" + Format(SeachMTID, "000"), "L31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_L31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_L31 = "V" + Str(RecBuf(4) / 10)
Case 6 'F31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "F31_" + Format(SeachMTID, "000"), "F31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_F31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_F31 = "V" + Str(RecBuf(4) / 10)
Case 7 'T31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "T31_" + Format(SeachMTID, "000"), "T31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_T31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_T31 = "V" + Str(RecBuf(4) / 10)
Case 8 'U33
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "U33_" + Format(SeachMTID, "000"), "U33 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_U33 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_U33 = "V" + Str(RecBuf(4) / 10)
Case 9 'I33
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "I33_" + Format(SeachMTID, "000"), "I33 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_I33 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_I33 = "V" + Str(RecBuf(4) / 10)
Case &HA 'P31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "P31_" + Format(SeachMTID, "000"), "P31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_P31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_P31 = "V" + Str(RecBuf(4) / 10)
Case &HB 'Q31
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "Q31_" + Format(SeachMTID, "000"), "Q31 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_Q31 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_Q31 = "V" + Str(RecBuf(4) / 10)
Case &HC 'S32
Set nodx = MyTree.Nodes.Add(COMNUM, tvwChild, "S32_" + Format(SeachMTID, "000"), "S32 " + Format(SeachMTID, "000"), 3)
nodx.Parent.Expanded = True
SoftEdit_S32 = "V" + Str(RecBuf(6) / 100)
HardwareEdit_S32 = "V" + Str(RecBuf(4) / 10)
End Select
End Sub
Private Sub ClosePort()
Find_time.Enabled = False
MSComm.PortOpen = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -