📄 regionutil.frm
字号:
' <STX><FLAGS><COMMAND><STARTING_BLOCK><NUMBER_OF_BLOCKS><DATA><CRC>, where
'
' <FLAGS>
' <COMMAND> = 0x42
' <STARTING_BLOCK> = paramBlock
' <NUMBER_OF_BLOCKS> = 0x01
' <DATA> = 4 bytes
' <CRC> = 2 bytes, calculated over <FLAGS> through <DATA>
If Form1.MSComm1.PortOpen = False Then
Exit Sub
End If
flags$ = "20" ' set the CRC_F
If option_Sys.Value = True Then
comand$ = "42" ' this is a Write_Sys command
label_Status.Caption = "Writing to System"
Else
comand$ = "41" ' Assume this is a Write_Mem command
label_Status.Caption = "Writing to Memory"
End If
nbBlks$ = "01"
'*********************************************************************
'
' Write Freq - Sys Param 0E - the 4 bytes are stored somewhere in M8 EEPROM
'*********************************************************************
' 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.1
If Form1.GetResponse() = False Then
label_Status.Caption = "Waiting for Command"
textbox_Freq.Text = "<Write Fail>"
Exit Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_Freq.Text = "<Write Fail>"
Exit Sub
End If
End If
' the write mem (write sys) command passed.
'*********************************************************************
'
' Write Max Freq - param 0F
'*********************************************************************
' 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 Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_MaxFreq.Text = "<Write Fail>"
Exit Sub
End If
End If
' the write mem (write sys) command passed.
'*********************************************************************
'
' Write Min Freq - param 10 - writes 4 bytes
'*********************************************************************
' 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 Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_MinFreq.Text = "<Write Fail>"
Exit Sub
End If
End If
' the write mem (write sys) command passed.
'*********************************************************************
'
' Write Freq Step - param 11 - writes 2 bytes
'*********************************************************************
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 Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_StepSize.Text = "<Write Fail>"
Exit Sub
End If
End If
' the write mem (write sys) command passed.
'*********************************************************************
'
' Write Pwr - param addr 16
'*********************************************************************
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>"
Exit Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_Pwr.Text = "<Write Fail>"
Exit Sub
End If
End If
' the write mem (write sys) command passed.
'*********************************************************************
'
' Write Mod Depth - param addr 17
'*********************************************************************
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$)
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_ModDepth.Text = "<Write Fail>"
Exit Sub
Else
If Mid(Form1.Response$, 2, 2) <> comand$ Then
label_Status.Caption = "Waiting for Command"
textbox_ModDepth.Text = "<Write Fail>"
Exit Sub
End If
End If
'' the write mem (write sys) command passed.
' '*********************************************************************
'
' Write Rise Time
'*********************************************************************
'flags$ = "20" ' set the CRC_F
'freqData$ = textbox_Freq.Text ' has the form 869.525
'' send the Write_Sys command "42" to write freqData$ into block "0D"
'Form1.MSComm1.Output = vbCr & flags$ & "42" & "0D" & "01" & freqData$ & vbCr
'If Form1.GetResponse() = True Then
' If Mid(Form1.Response$, 2, 2) <> "42" Then
' label_Status.Caption = "Waiting for Command"
' textbox_Freq.Text = "<Write Fail>"
' Exit Sub
' End If
' ' the write sys command passed.
'End If
'
'
label_Status.Caption = "Waiting for Command"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -