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

📄 uhf_analysis.frm

📁 M8演示程序
💻 FRM
📖 第 1 页 / 共 5 页
字号:
        ' Reset loop parameters
        If CDbl(UHF_Analysis.textbox_MaxFreq.Text) = CDbl(UHF_Analysis.textbox_MinFreq.Text) Then
           textbox_Freq.Text = UHF_Analysis.textbox_MaxFreq.Text
        Else
           textbox_Freq.Text = "902.000"
        End If
        

    End If
    Close #1 'Close output file
    MsgBox "Test Done!"
    Btn_Start.Enabled = True
    

End Sub

Private Sub Btn_Stop_Click()

StopTest = True
Btn_Start.Enabled = True

End Sub

Private Sub Form_Load()
   
    If Form1.MSComm1.PortOpen = False Then
        ' detect a reader and set the baud rate
        Call Form1.mnuOptions_Reader_Click
    End If
        
    Form1.MSComm1.InBufferCount = 0
    Form1.MSComm1.RThreshold = 0     ' disable OnComm - polling used at first
    
    textbox_Freq.Text = "902.000"
    textbox_MaxFreq.Text = "928.000"
    textbox_MinFreq.Text = "902.000"
    textbox_StepFreq.Text = "200"
    
    textbox_Pwr.Text = "12.0"
    textbox_MaxPwr.Text = "27.0"
    textbox_MinPwr.Text = "12.0"
    textbox_StepPwr.Text = "0.1"
    
    textbox_ModDepth.Text = "100"
    textbox_RiseTime.Text = "300"
    
End Sub


Private Function setcom() As Boolean
    
    On Error GoTo X:
    Form1.MSComm1.PortOpen = True
    'End Function
X:
End Function
Private Function Write_Frequency()
    WriteFreq = True

    '*********************************************************************
    '
    ' Write Freq - Sys Param 0E - the 4 bytes are stored somewhere in M8 EEPROM
    '*********************************************************************
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    ' eliminate the decimal from the string
    freqData$ = Mid(textbox_Freq.Text, 1, 3) & Mid(textbox_Freq.Text, 5, 3) & "000"
    
    strtBlk$ = "0E"
    
    longFreq = CLng(Val(freqData$))
    ' byte 0
    byteFreq = longFreq And &HFF
    byte0 = CByte(byteFreq)
    hexByte0$ = Hex$(byte0)
    If Len(hexByte0$) = 1 Then
        hexByte0$ = "0" & hexByte0$
    End If
    ' byte 1
    byteFreq = (longFreq / 256) And &HFF
    byte1 = CByte(byteFreq)
    hexByte1$ = Hex$(byte1)
    If Len(hexByte1$) = 1 Then
        hexByte1$ = "0" & hexByte1$
    End If
    ' byte 2
    byteFreq = (longFreq And &HFF0000) / 65536
    byte2 = CByte(byteFreq)
    hexByte2$ = Hex$(byte2)
    If Len(hexByte2$) = 1 Then
        hexByte2$ = "0" & hexByte2$
    End If
    ' byte 3
    byteFreq = (longFreq And &HFF000000) / 65536 / 256
    byte3 = CByte(byteFreq)
    hexByte3$ = Hex$(byte3)
    If Len(hexByte3$) = 1 Then
        hexByte3$ = "0" & hexByte3$
    End If
    ' combine the hex bytes
    hexLong$ = hexByte0$ & hexByte1$ & hexByte2$ & hexByte3$
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$)
    Form1.Response$ = ""
    Form1.MSComm1.Output = vbCr & flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$ & crc$ & vbCr
    
    Dim Start As Single
    ' wait .1 second to give the reader time to process the command before it responds
    Start = Timer
    Do
    Loop Until (Timer - Start) > 0.2

    If Form1.GetResponse() = False Then
        'label_Status.Caption = "Waiting for Command"
        'textbox_Freq.Text = "<Write Fail>"
        WriteFreq = False
        Exit Function
    Else
        If Mid(Form1.Response$, 2, 2) <> comand$ Then
            'label_Status.Caption = "Waiting for Command"
            'textbox_Freq.Text = "<Write Fail>"
            WriteFreq = False
            Exit Function
        End If
    End If
    ' the write mem (write sys) command passed.
End Function
Private Function Write_Max_Frequency()
    '*********************************************************************
    '
    ' Write Max Freq - param 0F
    '*********************************************************************
    
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    ' eliminate the decimal from the string
    freqData$ = Mid(textbox_MaxFreq.Text, 1, 3) & Mid(textbox_MaxFreq.Text, 5, 3) & "000"
    
    strtBlk$ = "0F"
    
    longFreq = CLng(Val(freqData$))
    ' byte 0
    byteFreq = longFreq And &HFF
    byte0 = CByte(byteFreq)
    hexByte0$ = Hex$(byte0)
    If Len(hexByte0$) = 1 Then
        hexByte0$ = "0" & hexByte0$
    End If
    ' byte 1
    byteFreq = (longFreq / 256) And &HFF
    byte1 = CByte(byteFreq)
    hexByte1$ = Hex$(byte1)
    If Len(hexByte1$) = 1 Then
        hexByte1$ = "0" & hexByte1$
    End If
    ' byte 2
    byteFreq = (longFreq And &HFF0000) / 65536
    byte2 = CByte(byteFreq)
    hexByte2$ = Hex$(byte2)
    If Len(hexByte2$) = 1 Then
        hexByte2$ = "0" & hexByte2$
    End If
    ' byte 3
    byteFreq = (longFreq And &HFF000000) / 65536 / 256
    byte3 = CByte(byteFreq)
    hexByte3$ = Hex$(byte3)
    If Len(hexByte3$) = 1 Then
        hexByte3$ = "0" & hexByte3$
    End If
    ' combine the hex bytes
    hexLong$ = hexByte0$ & hexByte1$ & hexByte2$ & hexByte3$
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$)
    Form1.Response$ = ""
    Form1.MSComm1.Output = vbCr & flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$ & crc$ & vbCr
    ' wait .1 second to give the reader time to process the command before it responds
    Start = Timer
    Do
    Loop Until (Timer - Start) > 0.1
       
    If Form1.GetResponse() = False Then
        'label_Status.Caption = "Waiting for Command"
        'textbox_MaxFreq.Text = "<Write Fail>"
        Exit Function
    Else
        If Mid(Form1.Response$, 2, 2) <> comand$ Then
            'label_Status.Caption = "Waiting for Command"
            'textbox_MaxFreq.Text = "<Write Fail>"
            Exit Function
        End If
    End If
    ' the write mem (write sys) command passed.
End Function
Private Function Write_Min_Frequency()
    '*********************************************************************
    '
    ' Write Min Freq - param 10 - writes 4 bytes
    '*********************************************************************
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    ' eliminate the decimal from the string
    freqData$ = Mid(textbox_MinFreq.Text, 1, 3) & Mid(textbox_MinFreq.Text, 5, 3) & "000"
    
    strtBlk$ = "10"
    
    longFreq = CLng(Val(freqData$))
    ' byte 0
    byteFreq = longFreq And &HFF
    byte0 = CByte(byteFreq)
    hexByte0$ = Hex$(byte0)
    If Len(hexByte0$) = 1 Then
        hexByte0$ = "0" & hexByte0$
    End If
    ' byte 1
    byteFreq = (longFreq / 256) And &HFF
    byte1 = CByte(byteFreq)
    hexByte1$ = Hex$(byte1)
    If Len(hexByte1$) = 1 Then
        hexByte1$ = "0" & hexByte1$
    End If
    ' byte 2
    byteFreq = (longFreq And &HFF0000) / 65536
    byte2 = CByte(byteFreq)
    hexByte2$ = Hex$(byte2)
    If Len(hexByte2$) = 1 Then
        hexByte2$ = "0" & hexByte2$
    End If
    ' byte 3
    byteFreq = (longFreq And &HFF000000) / 65536 / 256
    byte3 = CByte(byteFreq)
    hexByte3$ = Hex$(byte3)
    If Len(hexByte3$) = 1 Then
        hexByte3$ = "0" & hexByte3$
    End If
    ' combine the hex bytes
    hexLong$ = hexByte0$ & hexByte1$ & hexByte2$ & hexByte3$
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$)
    Form1.Response$ = ""
    Form1.MSComm1.Output = vbCr & flags$ & comand$ & strtBlk$ & nbBlks$ & hexLong$ & crc$ & vbCr
    ' wait .1 second to give the reader time to process the command before it responds
    Start = Timer
    Do
    Loop Until (Timer - Start) > 0.1
    If Form1.GetResponse() = False Then
        'label_Status.Caption = "Waiting for Command"
        'textbox_MinFreq.Text = "<Write Fail>"
        Exit Function
    Else
        If Mid(Form1.Response$, 2, 2) <> comand$ Then
            'label_Status.Caption = "Waiting for Command"
            'textbox_MinFreq.Text = "<Write Fail>"
            Exit Function
        End If
    End If
    ' the write mem (write sys) command passed.
End Function

Private Function Write_Step_Frequency()
    '*********************************************************************
    '
    ' Write Freq Step - param 11 - writes 2 bytes
    '*********************************************************************
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    strtBlk$ = "11"
    
    If textbox_StepSize.Text = "10" Then
        stepSize$ = "00"
    ElseIf textbox_StepSize.Text = "25" Then
        stepSize$ = "01"
    ElseIf textbox_StepSize.Text = "50" Then
        stepSize$ = "02" ' 50kHz step size
    ElseIf textbox_StepSize.Text = "100" Then
        stepSize$ = "03" ' 100kHz step size
    Else
        stepSize$ = "04" ' 200kHz step size (any value 04-FF)
    End If
    
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & stepSize$)
    Form1.Response$ = ""
    Form1.MSComm1.Output = vbCr & flags$ & comand$ & strtBlk$ & nbBlks$ & stepSize$ & crc$ & vbCr
    ' wait .1 second to give the reader time to process the command before it responds
    Start = Timer
    Do
    Loop Until (Timer - Start) > 0.1
    If Form1.GetResponse() = False Then
        'label_Status.Caption = "Waiting for Command"
        'textbox_StepSize.Text = "<Write Fail>"
        Exit Function
    Else
        If Mid(Form1.Response$, 2, 2) <> comand$ Then
            'label_Status.Caption = "Waiting for Command"
            'textbox_StepSize.Text = "<Write Fail>"
            Exit Function
        End If
    End If
    ' the write mem (write sys) command passed.
End Function
Private Function Write_Power()
    WritePwr = True

    '*********************************************************************
    '
    ' Write Pwr - param addr 16
    '*********************************************************************
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    strtBlk$ = "16"
    pwrData$ = textbox_Pwr.Text
       
    ' Need to convert from 12-27dBm to decimal values 0-150
    newPwrData = ((pwrData$ - 12) * 10)
    
    ' Need to convert from 0-150 value to Hex
    dacVal$ = Hex(newPwrData)
       
    ' Check for only one char in the string (need format "00" or 00 hex, two hex bytes)
    ' If string length is one, add leading 0 (case: "A" -> "0A")
    If Len(dacVal$) = 1 Then
        dacVal$ = "0" & dacVal$
    End If
        

    ' send the Write_Sys comand$ (41 or 42) to write pwrData$ into startBlk$
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & dacVal$)
    Form1.Response$ = ""
    Form1.MSComm1.Output = vbCr & flags$ & comand$ & strtBlk$ & nbBlks$ & dacVal$ & crc$ & vbCr
    ' wait .1 second to give the reader time to process the command before it responds
    Start = Timer
    Do
    Loop Until (Timer - Start) > 0.2
    If Form1.GetResponse() = False Then
        'label_Status.Caption = "Waiting for Command"
        'textbox_Pwr.Text = "<Write Fail>"
        WritePwr = False
    
        Exit Function
    Else
        If Mid(Form1.Response$, 2, 2) <> comand$ Then
            'label_Status.Caption = "Waiting for Command"
            'textbox_Pwr.Text = "<Write Fail>"
            WritePwr = False
            
            Exit Function
        End If
    End If
    ' the write mem (write sys) command passed.
End Function
Private Function Write_Mod_Depth()
    WriteMod = True

    '*********************************************************************
    '
    ' Write Mod Depth - param addr 17
    '*********************************************************************
    flags$ = "20"   ' set the CRC_F
    comand$ = "42" ' Assume this is a Write_Sys command
    
    nbBlks$ = "01"
    
    strtBlk$ = "17"
    pwrData$ = textbox_ModDepth.Text
       
    dacVal$ = Hex(pwrData)
       
    ' Check for only one char in the string (need format "00" or 00 hex, two hex bytes)
    ' If string length is one, add leading 0 (case: "A" -> "0A")
    If Len(dacVal$) = 1 Then
        dacVal$ = "0" & dacVal$
    End If
    
    ''send the Write_Sys comand$ (41 or 42) to write pwrData$ into startBlk$
    crc$ = Form1.calculateCRC(flags$ & comand$ & strtBlk$ & nbBlks$ & dacVal$)

⌨️ 快捷键说明

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