VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "DL810_5510 Series HF Reader Demonstration Software(VB) V1.0"
   ClientHeight    =   6165
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   9015
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   6165
   ScaleWidth      =   9015
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Alarm2 
      Caption         =   "Stop EAS Alarm"
      Height          =   375
      Left            =   5640
      TabIndex        =   39
      Top             =   4680
      Width           =   1935
   End
   Begin VB.CommandButton Alarm 
      Caption         =   "Start EAS Alarm"
      Height          =   375
      Left            =   3480
      TabIndex        =   37
      Top             =   4680
      Width           =   1935
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   8520
      Top             =   5160
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Reset EAS"
      Height          =   375
      Left            =   4680
      TabIndex        =   36
      Top             =   4080
      Width           =   1455
   End
   Begin VB.CommandButton SetEAS 
      Caption         =   "Set EAS"
      Height          =   375
      Left            =   4680
      TabIndex        =   35
      Top             =   3480
      Width           =   1455
   End
   Begin VB.ListBox List1 
      Height          =   2040
      Left            =   120
      TabIndex        =   33
      Top             =   3480
      Width           =   2055
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   2400
      TabIndex        =   32
      Top             =   2280
      Width           =   1935
   End
   Begin VB.CommandButton Command2 
      Caption         =   "ReadMultipleBlock"
      Height          =   375
      Left            =   4440
      TabIndex        =   31
      Top             =   2760
      Width           =   1935
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   3240
      TabIndex        =   30
      Top             =   2760
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1080
      TabIndex        =   28
      Top             =   2760
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "ReadSingleBlock"
      Height          =   375
      Left            =   4440
      TabIndex        =   26
      Top             =   2280
      Width           =   1935
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   960
      TabIndex        =   24
      Top             =   2280
      Width           =   1335
   End
   Begin VB.ListBox UIDList 
      Height          =   1680
      Left            =   6840
      TabIndex        =   21
      Top             =   2520
      Width           =   2055
   End
   Begin VB.Frame 通讯 
      Caption         =   "Communication"
      Height          =   1575
      Left            =   120
      TabIndex        =   18
      Top             =   120
      Width           =   2295
      Begin VB.CommandButton OpenPort 
         Caption         =   "Open COM Port"
         Height          =   375
         Left            =   240
         TabIndex        =   20
         Top             =   240
         Width           =   1815
      End
      Begin VB.CommandButton ClosePort 
         Caption         =   "Close COM Port"
         Height          =   375
         Left            =   240
         TabIndex        =   19
         Top             =   960
         Width           =   1815
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Operation Mode"
      Height          =   735
      Left            =   2520
      TabIndex        =   13
      Top             =   1440
      Width           =   6375
      Begin VB.OptionButton Option3 
         Caption         =   "Non-AddressMode"
         Height          =   375
         Left            =   4560
         TabIndex        =   17
         Top             =   240
         Width           =   1695
      End
      Begin VB.OptionButton Option2 
         Caption         =   "SelectMode"
         Height          =   375
         Left            =   3360
         TabIndex        =   16
         Top             =   240
         Width           =   1215
      End
      Begin VB.OptionButton Option1 
         Caption         =   "AddressMode"
         Height          =   375
         Left            =   2040
         TabIndex        =   15
         Top             =   240
         Width           =   1455
      End
      Begin VB.ComboBox CUID 
         Height          =   300
         Left            =   120
         TabIndex        =   14
         Top             =   240
         Width           =   1935
      End
   End
   Begin VB.CommandButton ntInventory 
      Caption         =   "Inventory"
      Height          =   375
      Left            =   360
      TabIndex        =   12
      Top             =   1800
      Width           =   1935
   End
   Begin VB.Frame Frame1 
      Caption         =   "Reader Information"
      Height          =   1335
      Left            =   2520
      TabIndex        =   0
      Top             =   120
      Width           =   6375
      Begin VB.CommandButton GetReadInfo 
         Caption         =   "GetReaderInfo"
         Height          =   375
         Left            =   4800
         TabIndex        =   11
         Top             =   840
         Width           =   1455
      End
      Begin VB.TextBox ntTime 
         BackColor       =   &H8000000F&
         Height          =   375
         Left            =   3480
         Locked          =   -1  'True
         TabIndex        =   10
         Top             =   840
         Width           =   615
      End
      Begin VB.TextBox ntAddress 
         BackColor       =   &H8000000F&
         Height          =   375
         Left            =   720
         Locked          =   -1  'True
         TabIndex        =   8
         Top             =   840
         Width           =   855
      End
      Begin VB.TextBox ReaderInfoProtocol 
         BackColor       =   &H8000000F&
         Height          =   375
         Left            =   4440
         Locked          =   -1  'True
         TabIndex        =   6
         Top             =   240
         Width           =   1815
      End
      Begin VB.TextBox Version 
         BackColor       =   &H8000000F&
         Height          =   375
         Left            =   2520
         Locked          =   -1  'True
         TabIndex        =   4
         Top             =   240
         Width           =   975
      End
      Begin VB.TextBox ntType 
         BackColor       =   &H8000000F&
         Height          =   375
         Left            =   600
         Locked          =   -1  'True
         TabIndex        =   2
         Top             =   240
         Width           =   1095
      End
      Begin VB.Label Label7 
         Caption         =   "*100ms"
         Height          =   255
         Left            =   4200
         TabIndex        =   23
         Top             =   960
         Width           =   615
      End
      Begin VB.Label Label5 
         Caption         =   "MaxInventoryScanTime:"
         Height          =   255
         Left            =   1680
         TabIndex        =   9
         Top             =   960
         Width           =   2175
      End
      Begin VB.Label Label4 
         Caption         =   "Addr:"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   960
         Width           =   615
      End
      Begin VB.Label Label3 
         Caption         =   "Protocol:"
         Height          =   255
         Left            =   3600
         TabIndex        =   5
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "Version:"
         Height          =   255
         Left            =   1800
         TabIndex        =   3
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "Type:"
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   360
         Width           =   615
      End
   End
   Begin VB.Label Arm 
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   24
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   4680
      TabIndex        =   38
      Top             =   5280
      Width           =   3615
   End
   Begin VB.Label Label11 
      Caption         =   "BlockData:"
      Height          =   255
      Left            =   120
      TabIndex        =   34
      Top             =   3240
      Width           =   1695
   End
   Begin VB.Label Label10 
      Caption         =   "BlockCount："
      Height          =   375
      Left            =   2160
      TabIndex        =   29
      Top             =   2760
      Width           =   1095
   End
   Begin VB.Label Label9 
      Caption         =   "StartBlock："
      Height          =   375
      Left            =   120
      TabIndex        =   27
      Top             =   2880
      Width           =   975
   End
   Begin VB.Label Label8 
      Caption         =   "BlockBum："
      Height          =   255
      Left            =   120
      TabIndex        =   25
      Top             =   2400
      Width           =   735
   End
   Begin VB.Label Label6 
      Caption         =   "DSFID-UID List"
      Height          =   255
      Left            =   6840
      TabIndex        =   22
      Top             =   2280
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i As Integer
Dim j As Integer
Dim Port As Long
Dim FrmHandle As Long
Dim ComAdr As Byte
Dim CardNum As Byte
Dim DSFIDAndUID(4096) As Byte
Dim verInfo(1) As Byte                  '读写器版本信息
Dim TrType(1) As Byte                   '支持协议
Dim InventoryScanTime As Byte           '最大询查时间
Dim ReaderType As Byte
Dim str1 As String
Dim State As Byte
Dim ErrorCode As Byte
Dim menorySize(1) As Byte
Dim blockSecStatus(30) As Byte
Dim fclose As Boolean
Dim fbusy As Boolean


Function CheckAlarm()
Dim RspLength As Byte
Dim CustomDatalength As Byte
Dim CustomData(10) As Byte
Dim FeedbackDataLength As Byte
Dim FeedbackData(20) As Byte
Dim temp, temp1, temp2, temp3 As String
temp = CUID.List(CUID.ListIndex)
If temp = "" Then
MsgBox "NO Tag!"
Exit Function
End If
RspLength = Val("&H" & "23")
temp = "23a504" + temp
CustomDatalength = Len(temp) / 2
For i = 0 To 10
CustomData(i) = Val("&H" & Mid(temp, i * 2 + 1, 2))
Next i
i = TransparentRead(ComAdr, RspLength, CustomDatalength, CustomData(0), FeedbackDataLength, FeedbackData(0), ErrorCode, FrmHandle)
If i = &HE Then
Arm.Caption = "No  Alarm!"
End If
If i = 0 Then
Arm.Caption = "ALARM!"
End If
End Function

Private Sub Alarm_Click()
Timer1.Enabled = True
Alarm.Enabled = False
Alarm2.Enabled = True
ClosePort.Enabled = False
GetReadInfo.Enabled = False
ntInventory.Enabled = False
OpenPort.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
SetEAS.Enabled = False
GetReadInfo.Enabled = False
ntInventory.Enabled = False

End Sub

Private Sub Alarm2_Click()
Timer1.Enabled = False
Alarm.Enabled = True
Alarm2.Enabled = False
Arm.Caption = ""
ClosePort.Enabled = True
GetReadInfo.Enabled = True
ntInventory.Enabled = True
OpenPort.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
SetEAS.Enabled = True
GetReadInfo.Enabled = True
ntInventory.Enabled = True
End Sub

Private Sub ClosePort_Click()
i = -1
i = CloseComPort()
If i <> 0 Then
MsgBox "CloseComPort failed! ", , "Communication"
End If
ntType.Text = ""
Version.Text = ""
ReaderInfoProtocol.Text = ""
ntAddress.Text = ""
ntTime.Text = ""
UIDList.Clear
CUID.Clear
List1.Clear
Text1.Text = ""
Text2.Text = ""
Combo1.Clear
Text3.Text = ""

ClosePort.Enabled = False
'Timer1.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
SetEAS.Enabled = False
Alarm.Enabled = False
Alarm2.Enabled = False
GetReadInfo.Enabled = False
ntInventory.Enabled = False
OpenPort.Enabled = True

End Sub

Private Sub Command1_Click()
Dim state1, state2 As Byte
Dim UIDI(8) As Byte
Dim UIDO(8) As Byte
Dim informationFlag As Byte
Dim DSFID As Byte
Dim blockSize As Byte
Dim BlockNum As Byte
Dim menorySize(1) As Byte
Dim ICReference As Byte
Dim AFI As Byte
Dim temp, temp1, temp2, temp3 As String
Dim m, n, k As Integer
'Dim i As Integer
temp = ""
temp1 = ""
temp = CUID.List(CUID.ListIndex)
For i = 0 To 7
UIDI(i) = Val("&H" & Mid(temp, i * 2 + 1, 2))
Next i
'state1 = 0
i = GetSystemInformation(ComAdr, state1, UIDI(0), informationFlag, UIDO(0), DSFID, AFI, menorySize(0), ICReference, ErrorCode, FrmHandle)
If i <> 0 Then
MsgBox "GetSystemInformation Filed"
Exit Sub
End If
If menorySize(1) = 3 Then
state2 = 0
Else
state2 = 4
End If
Dim data(7) As Byte
BlockNum = CByte(Combo1.List(Combo1.ListIndex))
k = ReadSingleBlock(ComAdr, state2, UIDI(0), BlockNum, blockSecStatus(0), data(0), ErrorCode, FrmHandle)
If k <> 0 Then
MsgBox "ReadSingleBlock Failed!"
Exit Sub
End If
temp = Hex(blockSecStatus(0))
If CInt(blockSecStatus(0)) < 16 Then
temp3 = "0" & Hex(blockSecStatus(0))
Else
temp3 = Hex(blockSecStatus(0))
End If
If menorySize(1) = 3 Then
For n = 0 To 3
If data(n) < 16 Then
temp2 = "0" & Hex(data(n))
Else
temp2 = Hex(data(n))
End If
temp1 = temp1 + temp2
Next n
Text3.Text = temp3 & " " & temp1
End If
If menorySize(1) = 7 Then
For n = 0 To 7
If data(n) < 16 Then
temp2 = "0" & Hex(data(n))
Else
temp2 = Hex(data(n))
End If
temp1 = temp1 + temp2
Next n
Text3.Text = temp3 & " " & temp1
End If
End Sub

Private Sub Command2_Click()
Dim state1, state2 As Byte
Dim UIDI(8) As Byte
Dim UIDO(8) As Byte
Dim data(1024) As Byte
Dim informationFlag As Byte
Dim DSFID As Byte
Dim blockSize As Byte
Dim BlockNum As Byte
Dim blockCount As Byte
Dim menorySize(1) As Byte
Dim ICReference As Byte
Dim AFI As Byte
Dim temp, temp1, temp2, temp3, temp4 As String
Dim m, n, k As Integer
temp = ""
temp1 = ""
List1.Clear
temp = CUID.List(CUID.ListIndex)
For i = 0 To 7
UIDI(i) = Val("&H" & Mid(temp, i * 2 + 1, 2))
Next i
i = GetSystemInformation(ComAdr, state1, UIDI(0), informationFlag, UIDO(0), DSFID, AFI, menorySize(0), ICReference, ErrorCode, FrmHandle)
If i <> 0 Then
MsgBox "GetSystemInformation Filed"
Exit Sub
End If

If Text1.Text = "" Or Text2.Text = "" Then
Exit Sub
End If
BlockNum = CByte(Text1.Text)
blockCount = CByte(Text2.Text)
If blockCount = 0 Then
MsgBox "blockCount can't order to '0'"
Exit Sub
End If
If menorySize(1) = 3 Then
If blockCount > 28 Or BlockNum > 28 Then
MsgBox "Number can't over 28 "
Exit Sub
End If
state2 = 0
Else
If blockCount > 15 Or BlockNum > 15 Then
MsgBox "Number can't over 15 "
Exit Sub
End If
state2 = 4
End If
If fclose Then Close
i = ReadMultipleBlock(ComAdr, state2, UIDI(0), BlockNum, blockCount, blockSecStatus(0), data(0), ErrorCode, FrmHandle)
If i <> 0 Then
MsgBox "ReadMultipleBlock Failed"
Exit Sub
End If



If i = 0 Then
temp2 = ""
temp3 = ""
If menorySize(1) = 3 Then
For m = 0 To (blockCount - 1) * 4 + 3
If data(m) < 16 Then
temp2 = "0" & Hex(data(m))
Else
temp2 = Hex(data(m))
End If
temp3 = temp3 + temp2
Next m
For n = 0 To (blockCount - 1)
If blockSecStatus(n) < 16 Then
temp4 = "0" & Hex(blockSecStatus(n))
Else
temp4 = Hex(blockSecStatus(n))
End If
temp = Mid(temp3, n * 8 + 1, 8)
temp = temp4 & " " & temp
List1.AddItem temp
Next n
End If
If menorySize(1) = 7 Then
For m = 0 To (blockCount - 1) * 8 + 7
If data(m) < 16 Then
temp2 = "0" & Hex(data(m))
Else
temp2 = Hex(data(m))
End If
temp3 = temp3 + temp2
Next m
For n = 0 To (blockCount - 1)
If blockSecStatus(n) < 16 Then
temp4 = "0" & Hex(blockSecStatus(n))
Else
temp4 = Hex(blockSecStatus(n))
End If
temp = Mid(temp3, n * 16 + 1, 16)
temp = temp4 & " " & temp
List1.AddItem temp
Next n
End If
End If

End Sub

Private Sub Command3_Click()
Dim Option1(3) As Byte
Dim RspLength As Byte
Dim CustomDatalength As Byte
Dim CustomData(10) As Byte
Dim FeedbackDataLength As Byte
Dim FeedbackData(20) As Byte
Dim temp, temp1, temp2, temp3 As String
temp = CUID.List(CUID.ListIndex)
If temp = "" Then
MsgBox "NO Tag!"
Exit Sub
End If
Option1(0) = Val("&H" & "00")
Option1(1) = Val("&H" & "44")
Option1(2) = Val("&H" & "00")
Option1(3) = Val("&H" & "00")
RspLength = CByte("03")
temp = "23a304" + temp
CustomDatalength = Len(temp) / 2
For i = 0 To 10
CustomData(i) = Val("&H" & Mid(temp, i * 2 + 1, 2))
Next i
i = TransparentWrite(ComAdr, Option1(0), RspLength, CustomDatalength, CustomData(0), FeedbackDataLength, FeedbackData(0), ErrorCode, FrmHandle)
If i <> 0 Then
MsgBox "Reset EAS Failed"
Exit Sub
End If
End Sub

Private Sub Command4_Click()

End Sub

Private Sub Form_Load()
ntType.Text = ""
Version.Text = ""
ReaderInfoProtocol.Text = ""
ntAddress.Text = ""
ntTime.Text = ""
Text1.Text = "0"
Text2.Text = "1"
ClosePort.Enabled = False
GetReadInfo.Enabled = False
ntInventory.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
SetEAS.Enabled = False
Alarm.Enabled = False
Alarm2.Enabled = False
Option1.Value = False
For i = 0 To 27
Combo1.AddItem CStr(i)
Next i
Combo1.ListIndex = 0
fclose = False
Timer1.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
i = -1
i = CloseComPort()
fclose = ture
End Sub

Private Sub GetReadInfo_Click()
Dim str5 As String
ntType.Text = ""
Version.Text = ""
ReaderInfoProtocol.Text = ""
ntAddress.Text = ""
ntTime.Text = ""
i = -1
i = GetReaderInformation(ComAdr, verInfo(0), ReaderType, TrType(0), InventoryScanTime, FrmHandle)
If i = 0 Then
ntTime.Text = CByte(InventoryScanTime)
If ComAdr < 16 Then
ntAddress.Text = "0" & Hex(ComAdr)
Else
ntAddress.Text = Hex(ComAdr)
End If
ReaderInfoProtocol.Text = "ISO/IEC 15693"
str5 = "0" & Val(verInfo(0)) & "." & Val(verInfo(1))
Version.Text = str5
ntType.Text = "DL810_5510"
Else
MsgBox "GetReaderInformation Failed!"
End If

End Sub

Private Sub ntInventory_Click()
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim AFI As Byte
State = 6
AFI = 0
CardNum = 0
i = Inventory(ComAdr, State, AFI, DSFIDAndUID(0), CardNum, FrmHandle) 'inventory
If i = &HA Or i = &HB Or i = &HE Then
If CardNum = 0 Then
UIDList.Clear
CUID.Clear
MsgBox "no Tag!", , "Inventory"
Exit Sub
End If
str1 = ""
str2 = ""
For i = 1 To 9 * CardNum
If DSFIDAndUID(i - 1) < 16 Then
str1 = "0" & Hex(DSFIDAndUID(i - 1))
Else
str1 = Hex(DSFIDAndUID(i - 1))
End If
str2 = str2 + str1
Next i
UIDList.Clear
CUID.Clear
While str2 <> ""
str3 = Left(str2, 18)
str4 = Right(str3, 16)
UIDList.AddItem str3
CUID.AddItem str4
str2 = Right(str2, Len(str2) - 18)
Wend
CUID.ListIndex = 0
End If
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
SetEAS.Enabled = True
Alarm.Enabled = True
Alarm2.Enabled = True
End Sub

Private Sub OpenPort_Click()
Dim str2 As String
Dim str3 As String
Dim str4 As String
ComAdr = &HFF
Port = -1
i = -1
fbusy = False
i = AutoOpenComPort(Port, ComAdr, FrmHandle)
If i = 0 Then
'MsgBox "OpenComPort Succuessfully", , "Communication"
ClosePort.Enabled = True
GetReadInfo.Enabled = True
ntInventory.Enabled = True
OpenPort.Enabled = False
Option1.Enabled = True
Option1.Value = True
Option2.Enabled = False
Option3.Enabled = False
Text1.Text = "0"
Text2.Text = "1"
For i = 0 To 27
Combo1.AddItem CStr(i)
Next i
Combo1.ListIndex = 0
ntType.Text = ""
Version.Text = ""
ReaderInfoProtocol.Text = ""
ntAddress.Text = ""
ntTime.Text = ""
i = -1
i = GetReaderInformation(ComAdr, verInfo(0), ReaderType, TrType(0), InventoryScanTime, FrmHandle)
If i = 0 Then
ntTime.Text = CByte(InventoryScanTime)
If ComAdr < 16 Then
ntAddress.Text = "0" & Hex(ComAdr)
Else
ntAddress.Text = Hex(ComAdr)
End If
ReaderInfoProtocol.Text = "ISO/IEC 15693"
str5 = "0" & Val(verInfo(0)) & "." & Val(verInfo(1))
Version.Text = str5
ntType.Text = "DL810_5510"
Else
MsgBox "GetReaderInformation Failed!"
End If
Else
MsgBox "OpenComPort failed", , "Communication"
ntType.Text = ""
Version.Text = ""
ReaderInfoProtocol.Text = ""
ntAddress.Text = ""
ntTime.Text = ""
UIDList.Clear
CUID.Clear
End If
End Sub

Private Sub SetEAS_Click()
Dim Option1(3) As Byte
Dim RspLength As Byte
Dim CustomDatalength As Byte
Dim CustomData(10) As Byte
Dim FeedbackDataLength As Byte
Dim FeedbackData(20) As Byte
Dim temp, temp1, temp2, temp3 As String
temp = CUID.List(CUID.ListIndex)
If temp = "" Then
MsgBox "NO Tag!"
Exit Sub
End If
Option1(0) = Val("&H" & "00")
Option1(1) = Val("&H" & "44")
Option1(2) = Val("&H" & "00")
Option1(3) = Val("&H" & "00")
RspLength = CByte("03")
temp = "23a204" + temp
CustomDatalength = Len(temp) / 2
For i = 0 To 10
CustomData(i) = Val("&H" & Mid(temp, i * 2 + 1, 2))
Next i
i = TransparentWrite(ComAdr, Option1(0), RspLength, CustomDatalength, CustomData(0), FeedbackDataLength, FeedbackData(0), ErrorCode, FrmHandle)
If i <> 0 Then
MsgBox "SetEAS Failed"
Exit Sub
End If
End Sub

Private Sub Timer1_Timer()
If fbusy = True Then
Exit Sub
End If
fbusy = True
i = CheckAlarm()
fbusy = False
If Alarm2.Enabled = False Then
Arm.Caption = ""
End If
End Sub
