新人求助各位大神,帮忙看下程序,上位机软件编程
Dim FrmHabdle As Long \定义长整型变量Dim ComAdr As Byte \定义ComAdr为byte类型变量 \byte为8位整型变量(0-127)
Dim fCmdRet As Long
Dim fdminfre As Single \定义单精度型变量
Dim fdmaxfre As Single
Dim fIsInventoryScan As Boolean \定义一个返回类型为布尔型的变量
Dim fcloseApp As Boolean
Dim EPClist As String \定义字符型变量
Private Sub Check3_Click()
If Check3.Value = 1 Then
Combo7.ListIndex = Combo6.ListIndex
End If
End Sub
Private Sub Command1_Click()
Dim Port As Long
Dim Baud As Byte
Dim str As String
Dim TrType(2) As Byte
Dim VersionInfo(2) As Byte
Dim ReaderType, ScanTime, dmaxfre, dminfre, PowerDbm, FreBand, Accuracy As Byte
ComAdr = &HFF
Port = Combo1.ListIndex + 1
Baud = Combo2.ListIndex
If Baud > 2 Then
Baud = Baud + 2
End If
FrmHandle = -1
Label18.Caption = ""
Combo4.Clear
fCmdRet = OpenComPort(Port, ComAdr, Baud, FrmHabdle)
If (fCmdRet = 0) Then
fCmdRet = GetReaderInformation(ComAdr, VersionInfo(0), ReaderType, TrType(0), dmaxfre, dminfre, PowerDbm, ScanTime, FrmHabdle)
If (fCmdRet = 0) Then
Text3.Text = GetValue(VersionInfo(0)) + "." + GetValue(VersionInfo(1))
If (VersionInfo(1) >= 30) Then
For i = 0 To 30
str = Val(i)
Combo4.AddItem (str)
Next i
Combo4.ListIndex = 30
Else
For i = 0 To 18
str = Val(i)
Combo4.AddItem (str)
Next i
Combo4.ListIndex = 18
End If
Text4.Text = GetHexValue(ComAdr)
Text8.Text = GetHexValue(ComAdr)
str = GetValue(ScanTime)
Text9.Text = str + "*100ms"
index = ScanTime - 3
Combo5.ListIndex = index
str = Val(PowerDbm)
Text5.Text = str
Combo4.ListIndex = PowerDbm
FreBand = CByte(((dmaxfre And &HC0) \ 16) Or (dminfre \ 64))
Select Case FreBand
Case 0
Option1.Value = True
fdminfre = 902.6 + (dminfre And &H3F) * 0.4
fdmaxfre = 902.6 + (dmaxfre And &H3F) * 0.4
Case 1
Option2.Value = True
fdminfre = 920.125 + (dminfre And &H3F) * 0.25
fdmaxfre = 920.125 + (dmaxfre And &H3F) * 0.25
Case 2
Option3.Value = True
fdminfre = 902.75 + (dminfre And &H3F) * 0.5
fdmaxfre = 902.75 + (dmaxfre And &H3F) * 0.5
Case 3
Option4.Value = True
fdminfre = 917.1 + (dminfre And &H3F) * 0.2
fdmaxfre = 917.1 + (dmaxfre And &H3F) * 0.2
Case 4
Option5.Value = True
fdminfre = 865.1 + (dminfre And &H3F) * 0.2
fdmaxfre = 865.1 + (dmaxfre And &H3F) * 0.2
End Select
Text6.Text = CStr(fdminfre) + "MHz"
Text7.Text = CStr(fdmaxfre) + "MHz"
If fdmaxfre <> fdminfre Then
Check3.Value = 0
End If
Combo6.ListIndex = dminfre And &H3F
Combo7.ListIndex = dmaxfre And &H3F
Select Case ReaderType
Case 6
Text2.Text = ""
Case 3
Text2.Text = ""
Case 9
Text2.Text = "UHFReader18"
End Select
If (TrType(0) And &H2) = &H2 Then
Check1.Value = 1
Check2.Value = 1
Else
Check1.Value = 0
Check2.Value = 0
End If
Label18.Caption = "获取读写信息成功!"
End If
Command3.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command11.Enabled = True
Label18.Caption = "端口打开成功"
Else
Label18.Caption = "端口打开失败"
End If
End Sub
Function GetHexData(ByRef uBuff() As Byte, ByVal count As Long) As String
Dim GetData, GetBuff As String
Dim i As Long
GetData = ""
For i = 0 To count - 1
If uBuff(i) < 16 Then
GetBuff = "0" & Hex(uBuff(i))
Else
GetBuff = Hex(uBuff(i))
End If
GetData = GetData + GetBuff
Next i
GetHexData = GetData
End Function
Function GetHexValue(ByVal uBuff As Byte) As String
Dim GetData As String
Dim i As Long
If uBuff < 16 Then
GetData = "0" & Hex(uBuff)
Else
GetData = Hex(uBuff)
End If
GetHexValue = GetData
End Function
Function GetValue(ByVal uBuff As Byte) As String
Dim GetData As String
Dim i As Long
If uBuff < 10 Then
GetData = "0" & Val(uBuff)
Else
GetData = Val(uBuff)
End If
GetValue = GetData
End Function
Private Sub Command10_Click()
Dim Mem, Num, WordPtr As Byte
Dim EPClength, maskFlag, maskadr, maskLen As Byte
Dim i As Integer
Dim s2 As String
Dim CardData(320) As Byte
Dim fOperEPC(320) As Byte
Dim fPassword(4) As Byte
Dim temp As String
If (Text10.Text = "") Or (Text11.Text = "") Then
Exit Sub
End If
Text14.Text = ""
If (Len(Text12.Text) < 8) Then
MsgBox "密码长度小于8!"
Exit Sub
End If
maskFlag = 0
maskadr = 0
maskLen = 0
For i = 0 To Len(Combo9.Text) / 2 - 1
fOperEPC(i) = Val("&H" + Mid(Combo9.Text, i * 2 + 1, 2))
Next i
For i = 0 To 3
fPassword(i) = Val("&H" + Mid(Text12.Text, i * 2 + 1, 2))
Next i
WordPtr = Val("&H" + Text10.Text)
Num = Val("&H" + Text11.Text)
Mem = Combo10.ListIndex
EPClength = Len(Combo9.Text) / 2
fCmdRet = ReadCard_G2(ComAdr, fOperEPC(0), Mem, WordPtr, Num, fPassword(0), maskadr, maskLen, maskFlag, CardData(0), EPClength, ferrorcode, FrmHabdle)
If (fCmdRet = 0) Then
temp = GetHexData(CardData(), Num * 2)
temp = UCase(temp)
Text14.Text = temp
Label18.Caption = "读数据成功!"
Else
Label18.Caption = "读数据失败!"
End If
End Sub
Private Sub Command11_Click()
Dim Mem, Writedatalen, WordPtr As Byte
Dim EPClength, maskFlag, maskadr, maskLen As Byte
Dim i As Integer
Dim s2 As String
Dim CardData(320) As Byte
Dim fOperEPC(320) As Byte
Dim fPassword(4) As Byte
Dim temp As String
Dim WritedataNum As Long
If (Text10.Text = "") Or (Text11.Text = "") Then
Exit Sub
End If
Text14.Text = ""
If (Len(Text12.Text) < 8) Then
MsgBox "密码长度小于8!"
Exit Sub
End If
If (Len(Text13.Text) Mod 4 <> 0) Then
MsgBox "以字数输入数据,如1234,12345678!"
Exit Sub
End If
maskFlag = 0
maskadr = 0
maskLen = 0
For i = 0 To Len(Combo9.Text) / 2 - 1
fOperEPC(i) = Val("&H" + Mid(Combo9.Text, i * 2 + 1, 2))
Next i
For i = 0 To Len(Text13.Text) / 2 - 1
CardData(i) = Val("&H" + Mid(Text13.Text, i * 2 + 1, 2))
Next i
Writedatalen = Len(Text13.Text) / 2
For i = 0 To 3
fPassword(i) = Val("&H" + Mid(Text12.Text, i * 2 + 1, 2))
Next i
WordPtr = Val("&H" + Text10.Text)
Mem = Combo10.ListIndex
EPClength = Len(Combo9.Text) / 2
fCmdRet = WriteCard_G2(ComAdr, fOperEPC(0), Mem, WordPtr, Writedatalen, CardData(0), fPassword(0), maskadr, maskLen, maskFlag, WritedataNum, EPClength, ferrorcode, FrmHabdle)
If (fCmdRet = 0) Then
Label18.Caption = "写数据成功!"
Else
Label18.Caption = "写数据失败!"
End If
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
fCmdRet = CloseComPort()
If fCmdRet = 0 Then
Label18.Caption = "端口关闭成功!"
Label18.Caption = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text9.Text = ""
Check1.Value = 0
Check2.Value = 0
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command11.Enabled = False
Else
Label18.Caption = "端口关闭失败!"
End If
End Sub
Private Sub Command3_Click()
Dim TrType(2) As Byte
Dim VersionInfo(2) As Byte
Dim ReaderType, ScanTime, dmaxfre, dminfre, PowerDbm, FreBand, Accuracy As Byte
Dim str As String
Dim index As Long
Label18.Caption = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text9.Text = ""
Check1.Value = 0
Check2.Value = 0
Combo4.Clear
fCmdRet = GetReaderInformation(ComAdr, VersionInfo(0), ReaderType, TrType(0), dmaxfre, dminfre, PowerDbm, ScanTime, FrmHabdle)
If (fCmdRet = 0) Then
Text3.Text = GetValue(VersionInfo(0)) + "." + GetValue(VersionInfo(1))
If (VersionInfo(1) >= 30) Then
For i = 0 To 30
str = Val(i)
Combo4.AddItem (str)
Next i
Combo4.ListIndex = 30
Else
For i = 0 To 18
str = Val(i)
Combo4.AddItem (str)
Next i
Combo4.ListIndex = 18
End If
Text4.Text = GetHexValue(ComAdr)
Text8.Text = GetHexValue(ComAdr)
str = GetValue(ScanTime)
Text9.Text = str + "*100ms"
index = ScanTime - 3
Combo5.ListIndex = index
str = Val(PowerDbm)
Text5.Text = str
Combo4.ListIndex = PowerDbm
FreBand = CByte(((dmaxfre And &HC0) \ 16) Or (dminfre \ 64))
Select Case FreBand
Case 0
Option1.Value = True
fdminfre = 902.6 + (dminfre And &H3F) * 0.4
fdmaxfre = 902.6 + (dmaxfre And &H3F) * 0.4
Case 1
Option2.Value = True
fdminfre = 920.125 + (dminfre And &H3F) * 0.25
fdmaxfre = 920.125 + (dmaxfre And &H3F) * 0.25
Case 2
Option3.Value = True
fdminfre = 902.75 + (dminfre And &H3F) * 0.5
fdmaxfre = 902.75 + (dmaxfre And &H3F) * 0.5
Case 3
Option4.Value = True
fdminfre = 917.1 + (dminfre And &H3F) * 0.2
fdmaxfre = 917.1 + (dmaxfre And &H3F) * 0.2
Case 4
Option5.Value = True
fdminfre = 865.1 + (dminfre And &H3F) * 0.2
fdmaxfre = 865.1 + (dmaxfre And &H3F) * 0.2
End Select
Text6.Text = CStr(fdminfre) + "MHz"
Text7.Text = CStr(fdmaxfre) + "MHz"
If fdmaxfre <> fdminfre Then
Check3.Value = 0
End If
Combo6.ListIndex = CByte(dminfre And &H3F)
Combo7.ListIndex = CByte(dmaxfre And &H3F)
Select Case ReaderType
Case 6
Text2.Text = ""
Case 3
Text2.Text = ""
Case 9
Text2.Text = "UHFReader18"
End Select
软件 --------------------编程问答-------------------- 提问的智慧 --------------------编程问答-------------------- 啊??我没学过Vb但是这个用的是VB 看不懂 --------------------编程问答-------------------- 请问你的问题是神马 我怎么不懂 --------------------编程问答--------------------
补充:VB , 网络编程