?? frmsetnodelocation.frm
字號:
Exit Sub
End If
If (strNodeLocationX = "") Then
MsgBox "請輸入X坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If (Len(strNodeLocationX) > 2) Then
MsgBox "請輸入正確的X坐標(biāo)信息(長度小于2)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Left(strNodeLocationX, 1)) Then
MsgBox "請輸入正確的X坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Right(strNodeLocationX, 1)) Then
MsgBox "請輸入正確的X坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If (strNodeLocationY = "") Then
MsgBox "請輸入Y坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If (Len(strNodeLocationY) > 2) Then
MsgBox "請輸入正確的Y坐標(biāo)信息(長度小于2)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Left(strNodeLocationY, 1)) Then
MsgBox "請輸入正確的Y坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Right(strNodeLocationY, 1)) Then
MsgBox "請輸入正確的Y坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If (strNodeLocationZ = "") Then
MsgBox "請輸入Z坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If (Len(strNodeLocationZ) > 2) Then
MsgBox "請輸入正確的Z坐標(biāo)信息(長度小于2)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Left(strNodeLocationZ, 1)) Then
MsgBox "請輸入正確的Z坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Right(strNodeLocationZ, 1)) Then
MsgBox "請輸入正確的Z坐標(biāo)", vbOKOnly, "Error"
Exit Sub
End If
'通過串口設(shè)置坐標(biāo)
If MsgBox("確定寫入節(jié)點(diǎn)?", vbOKCancel, "confirm") = vbOK Then
If (isCommOpen = False) Then
MsgBox "串口沒有被正確打開,請檢查配置文件"
Exit Sub
End If
Command(0) = COMMAND_SET_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" & strNodeLocationX
Command(8) = "&H" & strNodeLocationY
Command(9) = "&H" & strNodeLocationZ
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
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_SET_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"
Else
msgErrorMessage CInt(CStr(txtBuff(7)))
End If
Else
MsgBox "錯(cuò)誤的響應(yīng)格式", , "Error"
End If
Else
MsgBox "定時(shí)器超時(shí),請檢查網(wǎng)關(guān)節(jié)點(diǎn)和PC串口是否連接完好"
Timer1.Enabled = False
End If
End If
End Sub
Private Sub butQueryNodeLocation_Click()
Dim strNodeAddress As String
Dim i As Integer
strNodeAddress = Trim(textNodeAddress)
If (strNodeAddress = "") Then
MsgBox "請輸入節(jié)點(diǎn)地址", vbOKOnly, "Error"
Exit Sub
End If
If (Len(strNodeAddress) > 2) Then
MsgBox "請輸入正確的節(jié)點(diǎn)地址信息(長度小于2)", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Left(strNodeAddress, 1)) Then
MsgBox "請輸入正確的節(jié)點(diǎn)地址", vbOKOnly, "Error"
Exit Sub
End If
If Not isHex(Right(strNodeAddress, 1)) Then
MsgBox "請輸入正確的節(jié)點(diǎn)地址", vbOKOnly, "Error"
Exit Sub
End If
'通過串口查詢坐標(biāo)
'If MsgBox("確定寫入節(jié)點(diǎn)?", vbOKCancel, "confirm") = vbOK Then
If (isCommOpen = False) Then
MsgBox "串口沒有被正確打開,請檢查配置文件"
Exit Sub
End If
Command(0) = COMMAND_QUERY_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) = &H0
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
Do
DoEvents
If timeout Then
Exit Do
End If
'MsgBox MainForm.MSComm1.InBufferCount
Loop Until ((MainForm.MSComm1.InBufferCount = COMMAND_RESPONSE_LENGTH))
'MsgBox MainForm.MSComm1.InBufferCount
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_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 "查詢成功", , "success"
textX.Text = Hex(txtBuff(7))
textY.Text = Hex(txtBuff(8))
textZ.Text = Hex(txtBuff(9))
labrssi.Caption = txtBuff(10)
Else
msgErrorMessage CInt(CStr(txtBuff(7)))
End If
Else
MsgBox "錯(cuò)誤的響應(yīng)格式", , "Error"
End If
Else
MsgBox "定時(shí)器超時(shí),請檢查網(wǎng)關(guān)節(jié)點(diǎn)和PC串口是否連接完好"
Timer1.Enabled = False
End If
'End If
End Sub
Private Sub butConvert16to10_Click()
If Trim(textAfterConverted.Text) = "" Then
MsgBox "要轉(zhuǎn)換的16進(jìn)制坐標(biāo)不能為空", , "Error"
Exit Sub
End If
textBeforeConverted.Text = CStr(Val("&H" & textAfterConverted.Text) / 4)
End Sub
Private Sub Form_Load()
'MsgBox (45 - Val("&HFF" & "81"))
If (queryorsetlocation = 1) Then
'設(shè)置坐標(biāo)
butQueryNodeLocation.Enabled = False
butConvert16to10.Enabled = False
textAfterConverted.Enabled = False
Else
'查詢
butSetNodeLocation.Enabled = False
butConvert10to16.Enabled = False
textBeforeConverted.Enabled = False
textX.Enabled = False
textY.Enabled = False
textZ.Enabled = False
End If
End Sub
Private Sub Timer1_Timer()
'If Not isreceived Then
timeout = True
'End If
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -