?? setnoadaddress.frm
字號:
VERSION 5.00
Begin VB.Form frmSetNodeAddress
Caption = "設置節點地址"
ClientHeight = 3915
ClientLeft = 60
ClientTop = 345
ClientWidth = 6315
LinkTopic = "Form1"
ScaleHeight = 3915
ScaleWidth = 6315
StartUpPosition = 3 'Windows Default
Begin VB.Timer Timer1
Left = 5520
Top = 2400
End
Begin VB.CommandButton butCancel
Caption = "退出"
Height = 495
Left = 3240
TabIndex = 3
Top = 2160
Width = 1215
End
Begin VB.CommandButton butSubmit
Caption = "確定"
Height = 495
Left = 1080
TabIndex = 2
Top = 2160
Width = 1215
End
Begin VB.TextBox txtNodeAddress
Height = 495
Left = 3960
TabIndex = 0
Top = 960
Width = 1335
End
Begin VB.Label Label2
Caption = "請檢查串口是否已經正確連接到節點上"
ForeColor = &H000000FF&
Height = 495
Left = 1440
TabIndex = 4
Top = 3000
Width = 3615
End
Begin VB.Label Label1
Caption = "請輸入節點的地址(16進制,不包括0x)"
Height = 375
Left = 360
TabIndex = 1
Top = 1080
Width = 3375
End
End
Attribute VB_Name = "frmSetNodeAddress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim timeout As Boolean
Dim isreceived As Boolean
Option Explicit
Private Sub butCancel_Click()
If (MsgBox("確定退出嗎?", vbOKCancel, "Confirm") = vbOK) Then
frmSetNodeAddress.Hide
MainForm.Show
End If
End Sub
Private Sub butSubmit_Click()
butSubmit.Enabled = False
Dim strNodeAddress As String
strNodeAddress = Trim(txtNodeAddress.Text)
If (strNodeAddress = "") Then
MsgBox "請輸入地址信息", vbOKOnly, "Error"
butSubmit.Enabled = True
Exit Sub
End If
If (Len(strNodeAddress) > 2) Then
MsgBox "請輸入正確的地址信息(長度大于2)", vbOKOnly, "Error"
butSubmit.Enabled = True
Exit Sub
End If
If Not isHex(Left(strNodeAddress, 1)) Then
MsgBox "請輸入正確的地址信息", vbOKOnly, "Error"
butSubmit.Enabled = True
Exit Sub
End If
If Not isHex(Right(strNodeAddress, 1)) Then
MsgBox "請輸入正確的地址信息", vbOKOnly, "Error"
butSubmit.Enabled = True
Exit Sub
End If
If MsgBox("確定寫入節點?", vbOKCancel, "confirm") = vbOK Then
If (isCommOpen = False) Then
MsgBox "串口沒有被正確打開,請檢查配置文件"
butSubmit.Enabled = True
Exit Sub
End If
Command(0) = COMMAND_SET_NODE_ADDRESS
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.MSComm1.Output = Command
'waitting for response
Dim txtBuff() As Byte
MainForm.MSComm1.InBufferCount = 0 ' clear inBuffer
Timer1.Enabled = True
Timer1.Interval = 2000
timeout = False
Dim i As Integer
Do
DoEvents
Loop Until ((MainForm.MSComm1.InBufferCount = COMMAND_RESPONSE_LENGTH) And (Not timeout))
isreceived = True
Timer1.Enabled = False
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_NODE_ADDRESS_RESPONSE)) And Hex(txtBuff(0)) = Hex(txtBuff(1)) And Hex(txtBuff(1)) = Hex(txtBuff(2))) Then
MsgBox "設置成功", , "success"
Else
MsgBox "錯誤的響應格式", , "Error"
End If
'frmSetNodeAddress.Hide
'MainForm.Show
butSubmit.Enabled = True
Else
butSubmit.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
If Not isreceived Then
MsgBox "定時器超時,請檢查網關節點和PC串口是否連接完好"
Timer1.Enabled = False
butSubmit.Enabled = True
timeout = True
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -