⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.frm

📁 无线传感器网络节点的定位引擎程序
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "mscomm32.ocx"
Begin VB.Form MainForm 
   Caption         =   "Wireless sensor location"
   ClientHeight    =   8880
   ClientLeft      =   60
   ClientTop       =   300
   ClientWidth     =   9735
   LinkTopic       =   "Form1"
   ScaleHeight     =   8880
   ScaleWidth      =   9735
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton butStartLocation 
      Caption         =   "定位"
      Height          =   495
      Left            =   120
      TabIndex        =   11
      Top             =   2040
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "清空RSSI索引"
      Height          =   495
      Left            =   1680
      TabIndex        =   10
      Top             =   1200
      Width           =   1455
   End
   Begin VB.CommandButton butSetAnchorNodeAddress 
      Caption         =   "设置锚节点地址"
      Height          =   495
      Left            =   120
      TabIndex        =   9
      Top             =   1200
      Width           =   1455
   End
   Begin VB.CommandButton butQueryAN 
      Caption         =   "查询AN"
      Height          =   495
      Left            =   7920
      TabIndex        =   8
      Top             =   360
      Width           =   1455
   End
   Begin VB.CommandButton butSetAN 
      Caption         =   "设置AN"
      Height          =   495
      Left            =   6360
      TabIndex        =   7
      Top             =   360
      Width           =   1455
   End
   Begin VB.CommandButton butQueryNodeLocation 
      Caption         =   "查询节点坐标"
      Height          =   495
      Left            =   4800
      TabIndex        =   6
      Top             =   360
      Width           =   1455
   End
   Begin VB.CommandButton butSetNodeLocation 
      Caption         =   "设置节点坐标"
      Height          =   495
      Left            =   3240
      TabIndex        =   5
      Top             =   360
      Width           =   1455
   End
   Begin VB.Timer Timer1 
      Left            =   6480
      Top             =   3960
   End
   Begin VB.CommandButton butQueryNodeAddress 
      Caption         =   "查询节点地址"
      Height          =   495
      Left            =   1680
      TabIndex        =   4
      Top             =   360
      Width           =   1455
   End
   Begin VB.CommandButton butClear 
      Caption         =   "Clear"
      Height          =   495
      Left            =   1800
      TabIndex        =   3
      Top             =   3000
      Width           =   1335
   End
   Begin VB.CommandButton butSave2Log 
      Caption         =   "存到log中"
      Height          =   495
      Left            =   360
      TabIndex        =   2
      Top             =   3000
      Width           =   1095
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   8280
      Top             =   3840
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.TextBox Text1 
      Height          =   5295
      Left            =   0
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   1
      Top             =   3600
      Width           =   9735
   End
   Begin VB.CommandButton butSetNodeAddress 
      Caption         =   "设置节点地址"
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   360
      Width           =   1455
   End
   Begin VB.Line Line3 
      X1              =   0
      X2              =   9720
      Y1              =   1800
      Y2              =   1800
   End
   Begin VB.Line Line2 
      X1              =   0
      X2              =   9720
      Y1              =   2880
      Y2              =   2880
   End
   Begin VB.Line Line1 
      X1              =   120
      X2              =   9960
      Y1              =   960
      Y2              =   960
   End
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
 Dim strLogname As String
 Dim timeout As Boolean
 Dim isreceived As Boolean

Private Sub butClear_Click()
Text1.Text = ""
End Sub

Private Sub butQueryAN_Click()
    QueryorSetAN = 0
    frmSetAN.Show
End Sub

Private Sub butQueryNodeAddress_Click()
   
    Dim txtBuff() As Byte
    Dim i As Integer
    If (isCommOpen = False) Then
        MsgBox "串口没有被正确打开,请检查配置文件"
        Exit Sub
    End If
    Command(0) = COMMAND_QUERY_ADDRESS
    Command(1) = Command(0)
    Command(2) = Command(0)
    Command(3) = PC_ADDRESS
    Command(4) = &H0
    seqno = seqno + 1
    '向 INI 文件写信息
    '修改ini中seqno
    WritePrivateProfileString "SEQNO", "seqno", CStr(seqno), ConfigFilePath
    Int2BYTE seqno, Command(6), Command(5)
    Command(7) = &H0
    Command(8) = &H0
    Command(9) = &H0
    MainForm.Text1.Text = MainForm.Text1.Text & Now & " " & "发送" & " "
   For i = 0 To UBound(Command)
    MainForm.Text1.Text = MainForm.Text1.Text + " "
    If Len(CStr(Hex(Command(i)))) = 1 Then
        MainForm.Text1.Text = MainForm.Text1.Text + "0"
    
    End If
        MainForm.Text1.Text = MainForm.Text1.Text + CStr(Hex(Command(i)))
    Next
    MainForm.Text1.Text = MainForm.Text1.Text + vbCrLf
    MainForm.MSComm1.Output = Command
    
    
    'waitting for response
 
    



    MainForm.MSComm1.InBufferCount = 0 ' clear inBuffer
    Timer1.Enabled = True
    Timer1.Interval = 2000
    timeout = False
    

    Do
      DoEvents
      If (timeout) Then
        Exit Do
      End If
    Loop Until ((MainForm.MSComm1.InBufferCount = COMMAND_RESPONSE_LENGTH))
    Timer1.Enabled = False
    If Not timeout Then
         isreceived = True
         
         MainForm.Text1.Text = MainForm.Text1.Text & Now & " " & "接收" & " "
         txtBuff = MainForm.MSComm1.Input
         For i = 0 To COMMAND_RESPONSE_LENGTH - 1
            MainForm.Text1.Text = MainForm.Text1.Text + " "
            If Len(CStr(Hex(txtBuff(i)))) = 1 Then
                MainForm.Text1.Text = MainForm.Text1.Text + "0"
            
            End If
                MainForm.Text1.Text = MainForm.Text1.Text + CStr(Hex(txtBuff(i)))
         Next
         MainForm.Text1.Text = MainForm.Text1.Text + vbCrLf
         
         
         If (CStr(txtBuff(0) = CStr(COMMAND_QUERY_ADDRESS_RESPONSE)) And Hex(txtBuff(0)) = Hex(txtBuff(1)) And Hex(txtBuff(1)) = Hex(txtBuff(2))) Then
             MsgBox "查询成功,地址为" + CStr(Hex(txtBuff(3))), , "success"
         Else
             MsgBox "错误的响应格式", , "Error"
         End If
    Else
        MsgBox "定时器超时,请检查网关节点和PC串口是否连接完好"
        Timer1.Enabled = False
    End If
    
    
    
 
    
    
    
    
End Sub



Private Sub butQueryNodeLocation_Click()
queryorsetlocation = 0
frmSetNodeLocation.Show
End Sub

Private Sub butSave2Log_Click()
    If Trim(Text1.Text) = "" Then
        MsgBox "log为空"
        Exit Sub
    End If
    
    Open strLogname For Append As #1
        Print #1, Text1.Text
    Close #1
    MsgBox "成功存入log文件中", "Success"
End Sub

Private Sub butSetAN_Click()
    QueryorSetAN = 1
    frmSetAN.Show
End Sub

Private Sub butSetAnchorNodeAddress_Click()
frmSetAnchorAddress.Show
End Sub


Private Sub butSetNodeLocation_Click()
queryorsetlocation = 1
frmSetNodeLocation.Show
End Sub

Private Sub butStartLocation_Click()
frmStartLocation.Show
End Sub

Private Sub Command1_Click()
frmResetRssiIndex.Show
End Sub

Private Sub Form_Load()

    Dim strCommPortNo As String
    Dim CommPortNo As Integer
   
    
    
    ConfigFilePath = IIf(Right(App.Path, 1) = "\", App.Path & "config.ini", App.Path & "\" & "config.ini")
    
    strCommPortNo = Trim(ReadProFileString("MSCOMMCONFIG", "CommPortNo", ConfigFilePath))
    If (strCommPortNo = "") Then
        MsgBox "请在配置文件中设置串口号"
        Exit Sub
    End If
        
    CommPortNo = Val(strCommPortNo)
    
        
    If (openComm(MSComm1, CommPortNo)) Then
        isCommOpen = True
    Else
        isCommOpen = False
    End If
    
    '读取logfile 的路径
    strLogname = Trim(ReadProFileString("LOG", "LogfileName", ConfigFilePath))
    If strLogname = "" Then
        strLogname = "location.Log"
    End If
    
    

    '初始化变量
    'SEQNO
    Dim strSeqno As String
    
    
     strSeqno = (Trim(ReadProFileString("SEQNO", "seqno", ConfigFilePath)))
     If strSeqno = "" Then
        seqno = 0
     Else
        seqno = CInt(strSeqno)
     End If
    
    
    
   


    
End Sub



Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub butSetNodeAddress_Click()


    frmSetNodeAddress.Show

End Sub

Private Sub Timer1_Timer()

    
    timeout = True

    
End Sub

'Private Sub MSComm1_OnComm()
'    Select Case MSComm1.CommEvent
'
'    Case comEvReceive
'    'MsgBox "2"
'    'MsgBox MSComm1.InBufferCount
'     '   If MSComm1.InBufferCount = 20 Then
'     '       MsgBox "55"
'     '   End If
'
'    End Select
'End Sub
'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -