From d97003b98ac1e1c06fddccde3cb13f2cd5f9dd51 Mon Sep 17 00:00:00 2001 From: tithanayut <30551284+tithanayut@users.noreply.github.com> Date: Wed, 13 Mar 2019 21:18:43 +0700 Subject: [PATCH] Add new function (Support 7 Byte UID Card) --- UIDtoKeyboard/frmMain.Designer.vb | 7 ++-- UIDtoKeyboard/frmMain.vb | 56 ++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/UIDtoKeyboard/frmMain.Designer.vb b/UIDtoKeyboard/frmMain.Designer.vb index ad1534b..be15e87 100644 --- a/UIDtoKeyboard/frmMain.Designer.vb +++ b/UIDtoKeyboard/frmMain.Designer.vb @@ -97,9 +97,10 @@ Partial Class frmMain Me.lblInst2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(222, Byte)) Me.lblInst2.Location = New System.Drawing.Point(567, 59) Me.lblInst2.Name = "lblInst2" - Me.lblInst2.Size = New System.Drawing.Size(155, 36) + Me.lblInst2.Size = New System.Drawing.Size(217, 72) Me.lblInst2.TabIndex = 7 - Me.lblInst2.Text = "1- Card UID" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "2- Card UID (Reverse)" + Me.lblInst2.Text = "1- Card UID (4 Byte)" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "2- Card UID (4 Byte + Reverse)" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "3- Card UID (7 Byte)" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "4- Ca" & + "rd UID (7 Byte + Reverse) " ' 'txtReadingMode ' @@ -123,7 +124,7 @@ Partial Class frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(758, 551) + Me.ClientSize = New System.Drawing.Size(810, 551) Me.Controls.Add(Me.lblReadingMode) Me.Controls.Add(Me.txtReadingMode) Me.Controls.Add(Me.lblInst2) diff --git a/UIDtoKeyboard/frmMain.vb b/UIDtoKeyboard/frmMain.vb index f8d5dd3..d6b8ba8 100644 --- a/UIDtoKeyboard/frmMain.vb +++ b/UIDtoKeyboard/frmMain.vb @@ -49,7 +49,11 @@ Public Class frmMain End Sub Sub cardInit(eventName As SCardMonitor, unknown As CardStatusEventArgs) - SendUID() + If readingMode = 1 OrElse readingMode = 2 Then + SendUID4Byte() + ElseIf readingMode = 3 OrElse readingMode = 4 Then + sendUID7Byte() + End If End Sub Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load @@ -61,7 +65,7 @@ Public Class frmMain End Sub Private Sub btnStartMonitor_Click(sender As Object, e As EventArgs) Handles btnStartMonitor.Click - If txtReadingMode.Text <> 1 AndAlso txtReadingMode.Text <> 2 Then + If txtReadingMode.Text <> 1 AndAlso txtReadingMode.Text <> 2 AndAlso txtReadingMode.Text <> 3 AndAlso txtReadingMode.Text <> 4 Then MessageBox.Show("Error: Reading mode not macth the preset.") Else If isstart = True Then @@ -78,7 +82,7 @@ Public Class frmMain End If End Sub - Function SendUID() + Function SendUID4Byte() Try Using context = _contextFactory.Establish(SCardScope.System) Using rfidReader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any) @@ -93,7 +97,12 @@ Public Class frmMain Dim bytesReceived = rfidReader.Transmit(sendPci, command, command.Length, receivePci, receiveBuffer, receiveBuffer.Length) Dim responseApdu = New ResponseApdu(receiveBuffer, bytesReceived, IsoCase.Case2Short, rfidReader.Protocol) - If readingMode = 2 Then + If readingMode = 1 Then + Dim uid As String = BitConverter.ToString(responseApdu.GetData()) + uid = uid.Replace("-", "") + + SendKeys.SendWait(uid + "{ENTER}") + ElseIf readingMode = 2 Then Dim uid As Byte() = New Byte(3) {} Dim revuid As Byte() = New Byte(3) {} Array.Copy(responseApdu.GetData(), uid, 4) @@ -104,11 +113,48 @@ Public Class frmMain uid2 = uid2.Replace("-", "") SendKeys.SendWait(uid2 + "{ENTER}") - Else + End If + End Using + End Using + End Using + Catch + 'Error Handling should be developed + End Try + + Return True + End Function + + Function SendUID7Byte() + Try + Using context = _contextFactory.Establish(SCardScope.System) + Using rfidReader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any) + Using rfidReader.Transaction(SCardReaderDisposition.Leave) + + Dim apdu As Byte() = {&HFF, &HCA, &H0, &H0, &H7} + Dim sendPci = SCardPCI.GetPci(rfidReader.Protocol) + Dim receivePci = New SCardPCI() + + Dim receiveBuffer = New Byte(255) {} + Dim command = apdu.ToArray() + Dim bytesReceived = rfidReader.Transmit(sendPci, command, command.Length, receivePci, receiveBuffer, receiveBuffer.Length) + Dim responseApdu = New ResponseApdu(receiveBuffer, bytesReceived, IsoCase.Case2Short, rfidReader.Protocol) + + If readingMode = 3 Then Dim uid As String = BitConverter.ToString(responseApdu.GetData()) uid = uid.Replace("-", "") SendKeys.SendWait(uid + "{ENTER}") + ElseIf readingMode = 4 Then + Dim uid As Byte() = New Byte(6) {} + Dim revuid As Byte() = New Byte(6) {} + Array.Copy(responseApdu.GetData(), uid, 7) + Array.Copy(uid, revuid, 7) + Array.Reverse(revuid, 0, 7) + + Dim uid2 As String = BitConverter.ToString(revuid) + uid2 = uid2.Replace("-", "") + + SendKeys.SendWait(uid2 + "{ENTER}") End If End Using End Using