?? mainform.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 + -