📄 form7.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form7
BorderStyle = 1 'Fixed Single
Caption = "SkyeTek Firmware Update Utility"
ClientHeight = 3165
ClientLeft = 150
ClientTop = 465
ClientWidth = 6450
LinkTopic = "Form7"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3165
ScaleWidth = 6450
StartUpPosition = 1 'CenterOwner
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 375
Left = 180
TabIndex = 2
Top = 960
Width = 5955
_ExtentX = 10504
_ExtentY = 661
_Version = 393216
Appearance = 1
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 3000
Top = 1320
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Button
Caption = "Update"
Height = 495
Left = 1920
TabIndex = 1
Top = 2280
Width = 2655
End
Begin VB.Label label_Status
Caption = "SkyeTek Firmware Update Utility"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 240
TabIndex = 0
Top = 360
Width = 5895
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFile_Exit
Caption = "E&xit"
End
End
Begin VB.Menu mnuHelp
Caption = "&Help"
Begin VB.Menu mnuHelp_About
Caption = "&About Firmware Update Utility"
End
End
End
Attribute VB_Name = "Form7"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Button_Click()
Dim Start As Single
Dim Linedata As String
Dim i As Integer
Dim DataLen As Integer
Dim RecordLen As Integer
' This is the current default for m1, but we need to make this an option that the user can select, incase they have a h3, or m3
DataLen = 12 ' Default value
RecordLen = 14 ' Default value
If Form1.bootModeF = False Then
temp = detectReader
Else
temp = True
End If
' now in bootloader mode
' now open the filename specified by the user of the dialog box
' Set filters.
CommonDialog1.Filter = "SkyeTek Hex Files (*.shf)|*.shf"
' Specify default filter.
CommonDialog1.FilterIndex = 2
' clear the filename line in the dialog box
CommonDialog1.FileName = ""
' Display the Open dialog box.
CommonDialog1.ShowOpen
' remember the filename of this skyetek hex file
demoFileName$ = CommonDialog1.FileName
If demoFileName$ = "" Then
' they hit cancel or selected nothing so go back to the
label_Status.Caption = "Step 1 - Connect the Reader" & vbCrLf & "Step 2 - Power the Reader" & vbCrLf & "Step 3 - Click the Update Button."
Button.Caption = "Update"
Exit Sub
End If
If temp = True Then
If Form1.bootModeF = True Then ' already in bootloader mode
SelectReader.Show vbModal, Me ' Activate the select reader form
If Form1.H3detected Then
DataLen = "74"
RecordLen = "76"
ElseIf Form1.M8detected Then
DataLen = "74"
RecordLen = "76"
Else
DataLen = "12"
RecordLen = "14"
End If
ElseIf Form1.fwverH$ = "FF" Then ' Don't know what kind of reader we have
SelectReader.Show vbModal, Me ' Activate the select reader form
If Form1.H3detected Then
DataLen = "74"
RecordLen = "76"
ElseIf Form1.M8detected Then
DataLen = "74"
RecordLen = "76"
Else
DataLen = "12"
RecordLen = "14"
End If
ElseIf Form1.fwverH$ = "10" Then ' for motherboard use 0x0C
Form1.MSComm1.Output = vbCr & "20410C0100D6E6" & vbCr ' put the reader into bootloader mode via SkyeTek Protocol
DataLen = "74"
RecordLen = "76"
Else ' for m-series module use 0x0B
Form1.MSComm1.Output = vbCr & "20410B01005AE3" & vbCr ' put the reader into bootloader mode via SkyeTek Protocol
If Form1.fwverH$ = "E0" Then ' for UHF Module need different data and record length
DataLen = "74"
RecordLen = "76"
Else
DataLen = "12"
RecordLen = "14"
End If
End If
Start = Timer
Do
Loop Until (Timer - Start) > 0.1
Response$ = ""
Do While Form1.MSComm1.InBufferCount > 0
Response$ = Response$ & Form1.MSComm1.Input
Loop
If Response$ = vbLf & "41538D" & vbCrLf Then
' you are now in bootloader mode
Form1.MSComm1.Settings = "9600,N,8,1" ' and bootloader mode will be at 9600 regardless of system baud rate
Form1.bootModeF = True
'else fail message restart and repower
End If
Else 'if no reader dected
' Error no reader detected
End If
' the .sfh file has been identified so now open that file and verify whether it is valid
Button.Enabled = False
label_Status.Caption = "Now Updating Firmware..." & vbCrLf & " Please wait."
Form1.updateF = True
Open demoFileName$ For Binary As #1
Dim fileData$
'Dim count As Integer
Dim count As Variant
'Const DataLen = DataLength 'aaaaddddddddddddddddcccccccc
'Const RecordLen = RecordLength 'DataLen+CR+Lf
fileData = Space(FileLen(demoFileName$))
Get #1, , fileData
Linenumber = 1
count = 0
intProgressBarMax = FileLen(demoFileName$) / RecordLen
ProgressBar1.Max = intProgressBarMax
ProgressBar1.Visible = True
' Send 1-12 bytes to the Reader
' This is required if any bytes were accidently sent before the actual shf data goes across
' then they can be flushed out by completing the 12 byte stream
For i = 1 To (RecordLen - 1)
' Send a Byte
Form1.MSComm1.Output = vbCr '"1" WHAT DOES THIS DO?
Start = Timer
Do
If (Timer - Start) > 0.1 Then Exit Do
resp$ = Form1.MSComm1.Input
DoEvents
Loop Until resp$ <> ""
If (resp$ <> "") Then Exit For
Next
' If after 12 bytes and still no response, then the reader is probably not connected
If (resp$ = "") Then
Close #1
ProgressBar1.Visible = False
result = MsgBox("Fail!" & vbCrLf & "Update Not Complete." & vbCrLf & "Reset All Connections.", vbOKOnly, "SkyeWare Message")
label_Status.Caption = "Step 1 - Connect the Reader" & vbCrLf & "Step 2 - Power the Reader" & vbCrLf & "Step 3 - Click the Update Button."
Button.Caption = "Update"
Button.Enabled = True
Form7.MousePointer = vbDefault
Exit Sub
End If
Form7.MousePointer = vbHourglass 'or 11
While count < FileLen(demoFileName$)
DoEvents 'yields to the operating system
'so that pending tasks can be executed
Linedata$ = Mid(fileData, 1 + count, DataLen)
count = count + RecordLen
' Set the Count value to Zero and increment it in case of a Failure
i = 0
TryAgain:
Form1.MSComm1.Output = Linedata$
' Form7.Refresh
Start = Timer
Do
If (Timer - Start) > 2 Then
Close #1
ProgressBar1.Visible = False
result = MsgBox("Fail!Reader Not Responding" & vbCrLf & "Update Not Complete." & vbCrLf & "Reset All Connections.", vbOKOnly, "SkyeWare Message")
label_Status.Caption = "Step 1 - Connect the Reader" & vbCrLf & "Step 2 - Power the Reader" & vbCrLf & "Step 3 - Click the Update Button."
Button.Caption = "Update"
Button.Enabled = True
Form7.MousePointer = vbDefault
Exit Sub
'error
End If
resp$ = Form1.MSComm1.Input
DoEvents
Loop Until resp$ <> ""
If Not resp$ = Chr$(6) Then
' In case of a Failure, increment the count value i.e. try upto 5 times and if still a
' Failure in programming, then quit
i = i + 1
If i < 5 Then
GoTo TryAgain
End If
If resp$ = Chr$(21) Then
d = t
End If
Close #1
ProgressBar1.Visible = False
result = MsgBox("Fail!" & vbCrLf & "Update Not Complete." & vbCrLf & "Reset All Connections.", vbOKOnly, "SkyeWare Message")
label_Status.Caption = "Step 1 - Connect the Reader" & vbCrLf & "Step 2 - Power the Reader" & vbCrLf & "Step 3 - Click the Update Button."
Button.Caption = "Update"
Button.Enabled = True
Form7.MousePointer = vbDefault
Exit Sub
End If
' got ACK, proceed and program the next line of the file
ProgressBar1.Value = Linenumber
Linenumber = Linenumber + 1
Wend
Close #1
' end of the file without any errors (NACKs)
ProgressBar1.Visible = False
result = MsgBox("Success! Update Complete.", vbOKOnly, "SkyeWare Message")
Form1.bootModeF = False
Form7.MousePointer = vbDefault 'or 0
'End
Unload Form7
End Sub
Private Sub Form_Load()
Form1.Hide
label_Status.Caption = "Step 1 - Connect the Reader" & vbCrLf & "Step 2 - Power the Reader" & vbCrLf & "Step 3 - Click the Update Button."
Button.Caption = "Update"
Dim intProgressBarMax As Integer
With ProgressBar1
.Visible = False
End With
End Sub
Private Function detectReader()
Dim Start As Single
Dim baudrate As Integer
Dim com As Integer
Dim X$ ' to clear unwanted responce characters
Do
For com = 1 To 16
If Form1.MSComm1.PortOpen = True Then
Form1.MSComm1.PortOpen = False
End If
Form1.MSComm1.CommPort = com
Form1.MSComm1.InputLen = 1
Form1.MSComm1.RThreshold = 0 ' disble OnComm
'Form1.MSComm1.RThreshold = 1 ' enable OnComm
Call setcom
If Form1.MSComm1.PortOpen = True Then
Form1.MSComm1.InputMode = comInputModeText
For baudrate = 0 To 3
Select Case baudrate
Case 0
'9600
Form1.MSComm1.Settings = "9600,N,8,1"
Case 1
' 19200
Form1.MSComm1.Settings = "19200,N,8,1"
Case 2
' 38400
Form1.MSComm1.Settings = "38400,N,8,1"
Case 3
' 57600
Form1.MSComm1.Settings = "57600,N,8,1"
End Select
If Form1.MSComm1.PortOpen = True Then
Form1.MSComm1.Output = vbCr & "0022010101" & vbCr ' give an illegal message to get a known error message
End If ' 12-bytes total, just like a bootloader command
Form1.MSComm1.InBufferCount = 0 ' clear the input buffer before the next response
' _exeHostCommand will respond with <LF><41><CRC><CR><LF>
' if already in boot mode then _bootload will respond with <NACK>
' wait .1 second to give the reader time to process the command before it responds
If Form1.GetResponse() = True Then
Select Case Form1.Response$
Case vbLf & "88" & vbCrLf
detectReader = True
Exit Function
Case Chr$(21)
'already in bootloader mode don't do anything
End Select
Else 'if no response to illegal command
'reset reader and try again
End If
Next ' baud rate loop
End If
If Form1.MSComm1.PortOpen = True Then
Form1.MSComm1.PortOpen = False
End If
Next ' try the next com port
result = MsgBox("No SkyeRead Device Detected ", vbAbortRetryIgnore, "SkyeRead Device")
Loop Until ((result = vbAbort) Or (result = vbIgnore))
If (result = vbAbort) Then
End
End If
End Function
Private Function setcom() As Boolean
On Error GoTo X:
Form1.MSComm1.PortOpen = True
'End Function
X:
End Function
Private Sub mnuFile_Exit_Click()
Unload Form7
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -