VERSION 5.00
Begin VB.Form frmSearching 
   Caption         =   "搜索模块...."
   ClientHeight    =   2775
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3345
   Icon            =   "frmSearching.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   2775
   ScaleWidth      =   3345
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "停止"
      Default         =   -1  'True
      Height          =   375
      Left            =   1080
      TabIndex        =   3
      Top             =   2160
      Width           =   735
   End
   Begin VB.Timer Timer1 
      Interval        =   440
      Left            =   120
      Top             =   2040
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      ForeColor       =   &H000000FF&
      Height          =   180
      Left            =   2040
      TabIndex        =   2
      Top             =   1680
      Width           =   210
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "扫描地址："
      Height          =   180
      Left            =   960
      TabIndex        =   1
      Top             =   1680
      Width           =   900
   End
   Begin VB.Label Label1 
      BorderStyle     =   1  'Fixed Single
      Height          =   975
      Left            =   360
      TabIndex        =   0
      Top             =   360
      Width           =   2535
   End
End
Attribute VB_Name = "frmSearching"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim i As Integer
Dim sea As Boolean
Dim str As String
Dim strS As String

Private Sub Command1_Click()
   Unload Me
   If sea = False Then
      MsgBox "没有搜索到模块!", vbOKOnly + vbExclamation, "停止搜索!"
   End If
End Sub

Private Sub Form_Load()
   Dim settings As String, Offset As Integer
   Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
   frmComm.Enabled = False
   settings = frmComm.MSComm1.settings
   If InStr(settings, ".") > 0 Then
      Offset = 2
   Else
      Offset = 0
   End If
   Label1 = Chr(10) + Chr(13) + Space(8) + _
            "串  口： " + Format(frmComm.MSComm1.CommPort) + _
            Chr(10) + Chr(13) + Chr(10) + Chr(13) + _
            Space(8) + "波特率：" + _
            Left$(settings, Len(settings) - 6 - Offset)
   If frmComm.MSComm1.PortOpen = False Then
      frmComm.MSComm1.PortOpen = True
   End If
   i = 0
   sea = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
   frmComm.Enabled = True
End Sub

Private Sub Timer1_Timer()
   Dim ys As Single
   Dim NAME As String
   Label3 = i
   str = "$" + Right("0" + Hex(i), 2) + "M" + Chr(13)
   ys = Timer + 0.2
   frmComm.MSComm1.Output = str
   Do
      DoEvents
      If frmComm.MSComm1.InBufferCount >= 8 Then
         Exit Do
      End If
   Loop Until Timer > ys
   strS = frmComm.MSComm1.Input
   If Left(strS, 1) = "!" And Right(strS, 1) = Chr(13) Then
      NAME = Mid(strS, 4, 4)
      str = "$" + Right("0" + Hex(i), 2) + "2" + Chr(13)
      frmComm.MSComm1.Output = str
      ys = Timer + 0.2
      Do
        DoEvents
        If frmComm.MSComm1.InBufferCount >= 10 Then
           Exit Do
        End If
      Loop Until Timer > ys
      strS = frmComm.MSComm1.Input
      If Left(strS, 1) = "!" And Right(strS, 1) = Chr(13) Then
         Set lvitem = frmComm.LV.ListItems.Add(, , Format(i, "000") + "(" + Right("0" + Hex(i), 2) + "H)")
         lvitem.SubItems(1) = NAME
         lvitem.SubItems(4) = "Analog Input"
         lvitem.SubItems(6) = "% of Full"
         sea = True
      End If
   End If
   i = i + 1
   If i = sum + 1 Then
      Unload Me
      If sea = False Then
         MsgBox "没有找到模块,请查明原因!", vbOKOnly + vbExclamation, "搜索模块失败!"
      End If
   End If
End Sub
