⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 用VB编写的接收卫星接收机的是数据
💻
字号:
Attribute VB_Name = "自定义函数"
Public Type EndpointLocate
   iInterface As Long
   iEndpoint As Long
End Type

Public Function procLocateEndpoint(str As String) As EndpointLocate
Dim part1
Dim part2
Dim retval As EndpointLocate

   part1 = Split(Trim(str), ".")

   part2 = Split(part1(0), "口")
   retval.iInterface = CLng(part2(1))

   part2 = Split(part1(1), "点")
   retval.iEndpoint = CLng(part2(1))

   procLocateEndpoint = retval
   
End Function

Public Function procInitMsInfo()
 With frmMain.msfInfo
     .MergeCells = flexMergeRestrictRows
     
     ' Flex Grid Title Cells
     ' Total Head
     .TextMatrix(0, 0) = "属性"
     .TextMatrix(0, 1) = "属性"
     .Row = 0
     .Col = 0
     .CellTextStyle = flexTextInsetLight
     .MergeRow(0) = True
     
     ' ioTransferCtrl
     ' tag head
     .TextMatrix(1, 0) = "传输控制参数"
     .TextMatrix(1, 1) = "传输控制参数"
     .Row = 1
     .Col = 0
     .CellBackColor = RGB(200, 200, 200)
      .MergeRow(1) = True
     .CellFontBold = True
     .CellFontSize = 10
     
     .TextMatrix(2, 0) = "管道号:": .Row = 2: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(3, 0) = "包大小:"
     .TextMatrix(4, 0) = "包数量:"
     .TextMatrix(5, 0) = "包每URB:"
     .TextMatrix(6, 0) = "使用URB(个):"
    
     ' Device Descirptor
     ' tag head
     .TextMatrix(7, 0) = "USB设备描述符"
     .TextMatrix(7, 1) = "USB设备描述符"
     .Row = 7
     .Col = 0
     .CellBackColor = RGB(200, 200, 200)
     .MergeRow(7) = True
     .CellFontBold = True
     .CellFontSize = 10
     
     .TextMatrix(8, 0) = "BCD码版本号:": .Row = 8: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(9, 0) = "设备类:": .Row = 9: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(10, 0) = "设备子类:": .Row = 10: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(11, 0) = "协议代码:": .Row = 11: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(12, 0) = "控制端点0数据包大小:": .Row = 12: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(13, 0) = "厂商代码:": .Row = 13: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(14, 0) = "产品代码:": .Row = 14: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(15, 0) = "序列号:": .Row = 15: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(16, 0) = "最大配置数:": .Row = 16: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     
     ' Configuration Descriptor
     ' tagHead
     .TextMatrix(17, 0) = "USB配置描述符"
     .TextMatrix(17, 1) = "USB配置描述符"
     .Row = 17
     .Col = 0
     .CellBackColor = RGB(200, 200, 200)
     .MergeRow(17) = True
     .CellFontBold = True
     .CellFontSize = 10
     
     .TextMatrix(18, 0) = "总长度:": .Row = 18: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(19, 0) = "该配置接口数:": .Row = 19: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(20, 0) = "配置索引:": .Row = 20: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(21, 0) = "串描述符索引:": .Row = 21: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     .TextMatrix(22, 0) = "特性掩码:": .Row = 22: .Col = 0: .CellBackColor = RGB(220, 220, 220): .Col = 1: .CellBackColor = RGB(240, 240, 240)
     
     ' MapX file Path
     ' tagHead
     .TextMatrix(23, 0) = "接收数据存储路径"
     .TextMatrix(23, 1) = "接收数据存储路径"
     .Row = 23
     .Col = 0
     .CellBackColor = RGB(200, 200, 200)
     .MergeRow(23) = True
     .CellFontBold = True
     .CellFontSize = 10
     
     .TextMatrix(24, 0) = " "
     .TextMatrix(24, 1) = " "
     .Row = 24
     .Col = 0
     .MergeRow(24) = True
     .CellFontSize = 10
 End With
End Function

Public Function procFillDeviceDescriptor(blFill As Boolean)
With frmMain.msfInfo
  If blFill = True Then

    .TextMatrix(8, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bcdUSB)
    .TextMatrix(9, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bDeviceClass)
    .TextMatrix(10, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bDeviceSubClass)
    .TextMatrix(11, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bDeviceProtocol)
    .TextMatrix(12, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bMaxPacketSize0)
    .TextMatrix(13, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.idVendor)
    .TextMatrix(14, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.idProduct)
    .TextMatrix(15, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.iSerialNumber)
    .TextMatrix(16, 1) = CStr(frmMain.ezlibObj.DeviceDescriptor.bNumConfigurations)
  Else
    .TextMatrix(8, 1) = ""
    .TextMatrix(9, 1) = ""
    .TextMatrix(10, 1) = ""
    .TextMatrix(11, 1) = ""
    .TextMatrix(12, 1) = ""
    .TextMatrix(13, 1) = ""
    .TextMatrix(14, 1) = ""
    .TextMatrix(15, 1) = ""
    .TextMatrix(16, 1) = ""
  End If
End With
End Function

Public Function procFillConfigurationDescriptor(blFill As Boolean)
 With frmMain.msfInfo
   If blFill = True Then
    .TextMatrix(18, 1) = CStr(frmMain.ezlibObj.ConfigurationDescriptor.wTotalLength)
    .TextMatrix(19, 1) = CStr(frmMain.ezlibObj.ConfigurationDescriptor.bNumInterfaces)
    .TextMatrix(20, 1) = CStr(frmMain.ezlibObj.ConfigurationDescriptor.bConfigurationValue)
    .TextMatrix(21, 1) = CStr(frmMain.ezlibObj.ConfigurationDescriptor.iConfiguration)
    .TextMatrix(22, 1) = CStr(frmMain.ezlibObj.ConfigurationDescriptor.bmAttributes)
   Else
    .TextMatrix(18, 1) = ""
    .TextMatrix(19, 1) = ""
    .TextMatrix(20, 1) = ""
    .TextMatrix(21, 1) = ""
    .TextMatrix(22, 1) = ""
   End If
 End With
End Function
' This function not only Fill TransferCtrl Fields in FlexGrid
' but also will Fill Data File Path
Public Function procFillTransferCtrl(blFill As Boolean)
With frmMain.msfInfo
   If blFill = True Then
    '.TextMatrix(2, 1) is Filled in frmParamSetup.cmdOk's Click Sub
     .TextMatrix(3, 1) = CStr(frmMain.ezTransCtrl.PacketSize)
     .TextMatrix(4, 1) = CStr(frmMain.ezTransCtrl.PacketCount)
     .TextMatrix(5, 1) = CStr(frmMain.ezTransCtrl.FramesPerBuffer)
     .TextMatrix(6, 1) = CStr(frmMain.ezTransCtrl.BufferCount)
    ' Fill Data File Path - frmMain.strDatafilePath
     .TextMatrix(24, 0) = Trim(frmMain.strDatafilePath)
     .TextMatrix(24, 1) = Trim(frmMain.strDatafilePath)
   Else
     .TextMatrix(2, 1) = ""
     .TextMatrix(3, 1) = ""
     .TextMatrix(4, 1) = ""
     .TextMatrix(5, 1) = ""
     .TextMatrix(6, 1) = ""
     
     .TextMatrix(24, 0) = " "
     .TextMatrix(24, 1) = " "
   End If
End With
End Function

' Load Codes to Chip if it was Specified
' weather the Codes was specified or not, it will Start Chip
' return 0, succeed
' return 1, Download Failed
' return 2, Start Chip Failed
Public Function procDownload(strFirmwarePath As String) As Long
Dim retval As Long

With frmMain.ezlibObj
 ' 1. if Chip is Running then Stop It
  If .IsChipRunning = ChipIsRunning Then .StopChip

  '2. if Firmware is specified the upload it to Chip
  If Len(Trim(strFirmwarePath)) <> 0 Then
      frmMain.statusBar.Panels(1).Text = "正在上传配置固件"
      retval = .DownloadHexCodeToChip(Trim(strFirmwarePath), vbNullString)
       
       If retval = 1 Then
          frmMain.statusBar.Panels(1).Text = "上传配置固件失败"
          'Download Failed,return 1
          procDownload = 1
          Exit Function
       End If
  
       frmMain.statusBar.Panels(1).Text = ""
  End If
  
  '3. Run Chip
  frmMain.statusBar.Panels(1).Text = "正在启动固件以配置设备"
  If .RunChip() = 1 Then
      frmMain.statusBar.Panels(1).Text = "启动配置固件失败"
      ' Start Chip Failed,Return 2
      procDownload = 2
      Exit Function
  End If

  frmMain.statusBar.Panels(1).Text = "固件代码已启动"
  
  ' 4. Fill Device Descriptor
  Call procFillDeviceDescriptor(True)
  ' 5. Fill Configuration Descriptor
  Call procFillConfigurationDescriptor(True)
  
  ' Succeed ,return 0
  procDownload = 0
End With

  
End Function

' Save Options to File (Write First Record of the File)
' Succeed, return 0
' Failed , return 1
Public Function procSaveOptions() As Long
Dim rec As OptionRecord
Dim intFileNum As Integer
Dim strFilePath As String

On Error GoTo ErrHandler
intFileNum = FreeFile

' 1. set file path
strFilePath = App.Path + "\Setup.opt"
Debug.Print strFilePath

' 2. Fill Record Fields
rec.recBlFlag = True
rec.recLngDevFrom = optLngDevFrom
rec.recLngDevTo = optLngDevTo

optLngDetachDelay = frmMain.ezlibObj.DeviceDetachTimeout
optLngPluginDelay = frmMain.ezlibObj.RunChipDelay
rec.recLngDetachDelay = optLngDetachDelay
rec.recLngPluginDelay = optLngPluginDelay

rec.recLngTransDelay = optLngTransDelay
rec.recLngDogDelay = optLngDogDelay
rec.recLngRetryTimes = optLngRetryTimes

'3. Write Record to File
Open strFilePath For Random As #intFileNum Len = Len(rec)
Put #intFileNum, 1, rec
Close #intFileNum

'// Succeed, return 0
procSaveOptions = 0

Exit Function
ErrHandler:
'// Failed, return 1
  Close #intFileNum
  procSaveOptions = 1
End Function

' Load Options From File (Read First Record of the File)
' Succeed, return 0
' Failed , return 1
Public Function procLoadOptions() As Long
Dim rec As OptionRecord
Dim intFileNum As Integer
Dim strFilePath As String

On Error GoTo ErrHandler
intFileNum = FreeFile

'1. set file path
strFilePath = App.Path + "\Setup.opt"
Debug.Print strFilePath

'2. Read From File
Open strFilePath For Random As #intFileNum Len = Len(rec)
Get #intFileNum, 1, rec
Close #intFileNum

'3. Fill Options with Record
If rec.recBlFlag = True Then
optLngDevFrom = rec.recLngDevFrom
optLngDevTo = rec.recLngDevTo

optLngDetachDelay = rec.recLngDetachDelay
optLngPluginDelay = rec.recLngPluginDelay
frmMain.ezlibObj.DeviceDetachTimeout = optLngDetachDelay
frmMain.ezlibObj.RunChipDelay = optLngPluginDelay

optLngTransDelay = rec.recLngTransDelay
optLngDogDelay = rec.recLngDogDelay
optLngRetryTimes = rec.recLngRetryTimes
Else
' If Read Record Failed
' Fill Options with Const Default values
optLngDevFrom = 0
optLngDevTo = MAX_USB_DEV_NUMBER

optLngDetachDelay = 2
optLngPluginDelay = 30
frmMain.ezlibObj.DeviceDetachTimeout = optLngDetachDelay
frmMain.ezlibObj.RunChipDelay = optLngPluginDelay


optLngTransDelay = 100
optLngDogDelay = 800
optLngRetryTimes = 5
End If

'// Succeed Return 0
   procLoadOptions = 0
Exit Function
ErrHandler:

optLngDevFrom = 0
optLngDevTo = MAX_USB_DEV_NUMBER

optLngDetachDelay = 2
optLngPluginDelay = 30
frmMain.ezlibObj.DeviceDetachTimeout = optLngDetachDelay
frmMain.ezlibObj.RunChipDelay = optLngPluginDelay


optLngTransDelay = 100
optLngDogDelay = 800
optLngRetryTimes = 5

'// Failed, return 1
procLoadOptions = 1
End Function
' Save Transfer Ctrl Reference to file (Write Second Record of the File)
' Succeed, return 0
' Failed , return 1
Public Function procSaveReferences() As Long
Dim rec As OptionRecord
Dim intFileNum As Integer
Dim strFilePath As String

On Error GoTo ErrHandler
intFileNum = FreeFile

' 1. set file path
strFilePath = App.Path + "\Setup.opt"
Debug.Print strFilePath

' 2. Fill Record Fields
rec.refBlFlag = True
rec.refLngPacketSize = refLngPacketSize
rec.refLngPacketCount = refLngPacketCount
rec.refLngBufferCount = refLngBufferCount
rec.refLngFramesPerBuffer = refLngFramesPerBuffer

'3. Write Record to File
Open strFilePath For Random As #intFileNum Len = Len(rec)
Put #intFileNum, 2, rec
Close #intFileNum

'// Succeed, return 0
procSaveReferences = 0

Exit Function
ErrHandler:
'// Failed, return 1
  Close #intFileNum
  procSaveReferences = 1
End Function
' Load Transfer Ctrl References From File (Read Second Record of the File)
' Succeed, return 0
' Failed , return 1
Public Function procLoadReferences() As Long
Dim rec As OptionRecord
Dim intFileNum As Integer
Dim strFilePath As String

On Error GoTo ErrHandler
intFileNum = FreeFile

'1. set file path
strFilePath = App.Path + "\Setup.opt"
Debug.Print strFilePath

'2. Read From File
Open strFilePath For Random As #intFileNum Len = Len(rec)
Get #intFileNum, 2, rec
Close #intFileNum

'3. Fill References Variables with Record
If rec.refBlFlag = True Then
refLngPacketSize = rec.refLngPacketSize
refLngPacketCount = rec.refLngPacketCount
refLngBufferCount = rec.refLngBufferCount
refLngFramesPerBuffer = rec.refLngFramesPerBuffer

Else
' If Read Record Failed
' Fill References Variables with Const Default values
refLngPacketSize = 85
refLngPacketCount = 1000
refLngBufferCount = 2
refLngFramesPerBuffer = 2
End If

'// Succeed Return 0
   procLoadReferences = 0
Exit Function
ErrHandler:
  refLngPacketSize = 85
  refLngPacketCount = 1000
  refLngBufferCount = 2
  refLngFramesPerBuffer = 2


'// Failed, return 1
procLoadReferences = 1
End Function
' Debug print the options
Public Sub procOptionsDebug()
  Debug.Print "devfrom:" + CStr(optLngDevFrom)
  Debug.Print "devto:" + CStr(optLngDevTo)
  Debug.Print "detachdelay:" + CStr(optLngDetachDelay)
  Debug.Print "plugindelay:" + CStr(optLngPluginDelay)
  Debug.Print "transdelay:" + CStr(optLngTransDelay)
  Debug.Print "dogdelay:" + CStr(optLngDogDelay)
  Debug.Print "retrytimes:" + CStr(optLngRetryTimes)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -