?? frmstartlocation.frm
字號:
VERSION 5.00
Begin VB.Form frmStartLocation
Caption = "Form1"
ClientHeight = 5775
ClientLeft = 60
ClientTop = 345
ClientWidth = 7470
LinkTopic = "Form1"
ScaleHeight = 5775
ScaleWidth = 7470
StartUpPosition = 3 'Windows Default
Begin VB.TextBox TextZ
Height = 615
Left = 4800
TabIndex = 8
Top = 4080
Width = 1215
End
Begin VB.TextBox TextY
Height = 615
Left = 2760
TabIndex = 7
Top = 4080
Width = 1335
End
Begin VB.TextBox textX
Height = 615
Left = 840
TabIndex = 6
Top = 4080
Width = 1215
End
Begin VB.TextBox textAnchorNodeNo
Height = 495
Left = 1800
TabIndex = 4
Top = 1920
Width = 1935
End
Begin VB.Timer Timer1
Left = 5400
Top = 1200
End
Begin VB.CommandButton Command2
Caption = "退出"
Height = 495
Left = 3240
TabIndex = 2
Top = 3000
Width = 1455
End
Begin VB.CommandButton butSubmit
Caption = "確定"
Height = 495
Left = 1200
TabIndex = 1
Top = 3000
Width = 1455
End
Begin VB.TextBox textNodeAddress
Height = 495
Left = 1800
TabIndex = 0
Top = 1200
Width = 1935
End
Begin VB.Label Label6
Caption = "節(jié)點地址"
Height = 495
Left = 600
TabIndex = 12
Top = 1200
Width = 975
End
Begin VB.Label Label5
Caption = "Z"
Height = 375
Left = 4440
TabIndex = 11
Top = 4200
Width = 255
End
Begin VB.Label Label4
Caption = "Y"
Height = 375
Left = 2400
TabIndex = 10
Top = 4200
Width = 255
End
Begin VB.Label Label2
Caption = "X"
Height = 375
Left = 480
TabIndex = 9
Top = 4200
Width = 255
End
Begin VB.Label Label1
Caption = "錨節(jié)點個數(shù)"
Height = 495
Left = 480
TabIndex = 5
Top = 1920
Width = 1095
End
Begin VB.Label Label3
Caption = "地址,16進(jìn)制,不包括0X"
ForeColor = &H000000FF&
Height = 375
Left = 840
TabIndex = 3
Top = 600
Width = 3015
End
End
Attribute VB_Name = "frmStartLocation"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim timeout As Boolean
Dim strNodeAddress As String
Dim i As Integer
Private Sub butSubmit_Click()
strNodeAddress = Trim(textNodeAddress.Text)
If (strNodeAddress = "") Then
MsgBox "請輸入地址信息", vbOKOnly, "Error"
Exit Sub
End If
If (Len(strNodeAddress) > 2) Then
MsgBox "請輸入正確的地址信息(長度小于2)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Left(strNodeAddress, 1)) Then
MsgBox "請輸入正確的地址信息", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Right(strNodeAddress, 1)) Then
MsgBox "請輸入正確的地址信息", vbOKOnly, "Error"
Exit Sub
End If
If (Trim(textAnchorNodeNo.Text) = "") Then
MsgBox "請輸入錨節(jié)點個數(shù)", vbOKOnly, "Error"
Exit Sub
End If
If Not IsNumeric(Trim(textAnchorNodeNo.Text)) Then
MsgBox "錨節(jié)點個數(shù)只能為數(shù)字", vbOKOnly, "Error"
Exit Sub
End If
If CInt(Trim(textAnchorNodeNo.Text)) > 8 Then
MsgBox "錨節(jié)點個數(shù)小于8", vbOKOnly, "Error"
Exit Sub
End If
Dim j As Integer
If MsgBox("開始定位?", vbOKCancel, "confirm") = vbOK Then
If (isCommOpen = False) Then
MsgBox "串口沒有被正確打開,請檢查配置文件"
butSubmit.Enabled = True
Exit Sub
End If
start_location
End If
End Sub
Private Sub Command2_Click()
If (MsgBox("確定退出嗎?", vbOKCancel, "Confirm") = vbOK) Then
Unload Me
MainForm.Show
End If
End Sub
Private Sub Form_Load()
Open "dangqiandian.txt" For Output As #1
End Sub
Private Sub Timer1_Timer()
timeout = True
'MsgBox "超時"
Timer1.Enabled = True
End Sub
Private Sub start_location()
While (1)
Command(0) = COMMAND_START_LOCATION
Command(1) = Command(0)
Command(2) = Command(0)
Command(3) = PC_ADDRESS
Command(4) = "&H" & strNodeAddress
seqno = seqno + 1
'修改ini中seqno
WritePrivateProfileString "SEQNO", "seqno", CStr(seqno), ConfigFilePath
Int2BYTE seqno, Command(6), Command(5)
Command(7) = "&H" & Trim(textAnchorNodeNo.Text)
Command(8) = &H0
Command(9) = &H0
MainForm.Text1.Text = MainForm.Text1.Text & Now & " " & "發(fā)送" & " "
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
Dim txtBuff() As Byte
MainForm.MSComm1.InBufferCount = 0 ' clear inBuffer
Timer1.Enabled = True
Timer1.Interval = UART_RADIO_RETRY_COUNT * UART_RADIO_HAL_TIME + 2000
timeout = False
DoEvents
Do
DoEvents
If timeout Then
Exit Do
End If
Loop Until ((MainForm.MSComm1.InBufferCount >= COMMAND_RESPONSE_LENGTH))
'MsgBox MainForm.MSComm1.InBufferCount
'Timer1.Enabled = False
If (Not timeout) Then
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_START_LOCATION_RESPONSE)) And Hex(txtBuff(0)) = Hex(txtBuff(1)) And Hex(txtBuff(1)) = Hex(txtBuff(2))) Then
'檢查設(shè)置是否成功
If txtBuff(6) = SUCCESS_RESPONSE Then
'MsgBox "設(shè)置成功", , "success"
'MsgBox txtBuff(7)
'MsgBox txtBuff(8)
'顯示XYZ坐標(biāo)
'If (txtBuff(7) / 2) > 40 Then
'Else
textX.Text = txtBuff(7) / 2
TextY.Text = txtBuff(8) / 2
TextZ.Text = 0
'Print #1, textX.Text; TextY.Text
'End If
Close #1
'Timer1.Enabled = False
Else
msgErrorMessage CInt(CStr(txtBuff(7)))
End If
Else
MsgBox "錯誤的響應(yīng)格式", , "Error"
End If
Timer1.Enabled = True
Timer1.Interval = UART_RADIO_RETRY_COUNT * UART_RADIO_HAL_TIME + 7000
timeout = False
Else
Timer1.Enabled = True
Timer1.Interval = 2 * (UART_RADIO_RETRY_COUNT * UART_RADIO_HAL_TIME) + 7000
timeout = False
End If
Wend
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -