public Iso7816.ApduResponse SignalACR(string readerName, ACRReaderControl ctrl) { byte ledStateCtrl = 0; if (ctrl.finalRed) { ledStateCtrl |= 1 << 0; } if (ctrl.finalGreen) { ledStateCtrl |= 1 << 1; } if (ctrl.redMask) { ledStateCtrl |= 1 << 2; } if (ctrl.greenMask) { ledStateCtrl |= 1 << 3; } if (ctrl.initRedBlink) { ledStateCtrl |= 1 << 4; } if (ctrl.initGreenBlink) { ledStateCtrl |= 1 << 5; } if (ctrl.redBlinkMask) { ledStateCtrl |= 1 << 6; } if (ctrl.greenBlinkMask) { ledStateCtrl |= 1 << 7; } byte[] ctrlData = new byte[] { ctrl.t1Duration, ctrl.t2Duration, ctrl.reps, ctrl.buzzer }; blockCardEvents += 1; try { using (ISCardContext ctx = contextFactory.Establish(SCardScope.System)) using (ICardReader reader = ctx.ConnectReader(readerName, SCardShareMode.Direct, SCardProtocol.Unset)) { var apdu = new Iso7816.ApduCommand(0xFF, 0x00, 0x40, ledStateCtrl, ctrlData, null); return(reader.Control(apdu)); } } finally { new Thread(() => { Thread.Sleep(((ctrl.t1Duration * 100) + (ctrl.t2Duration * 100)) * ctrl.reps); blockCardEvents -= 1; }).Start(); } // For all I'm aware, this always returns a failure APDU, but the reader does perform the specified action. }
/// <summary> /// Extension method to SmartCardConnection class similar to Transmit asyc method, however it accepts PCSC SDK commands. /// </summary> /// <param name="apduCommand"> /// APDU command object to send to the ICC /// </param> /// <param name="reader"> /// SmartCardConnection object /// </param> /// <returns>APDU response object of type defined by the APDU command object</returns> public static Iso7816.ApduResponse Transceive(this ICardReader reader, Iso7816.ApduCommand apduCommand) { Iso7816.ApduResponse apduRes = Activator.CreateInstance(apduCommand.ApduResponseType) as Iso7816.ApduResponse; byte[] resp = new byte[256]; int bytesReceived = reader.Transmit(apduCommand.ToByteArray(), resp); Array.Resize(ref resp, bytesReceived); apduRes.ExtractResponse(resp); return(apduRes); }
private void TryTurnOffBeep(string readerName) { if (!readerName.Contains("ACR")) { return; } try { using (ISCardContext ctx = contextFactory.Establish(SCardScope.System)) using (ICardReader reader = ctx.ConnectReader(readerName, SCardShareMode.Direct, SCardProtocol.Unset)) { var apdu = new Iso7816.ApduCommand(0xFF, 0x00, 0x52, 0x00, null, 0x00); var res = reader.Control(apdu); if (res.Succeeded) { StatusMessage?.Invoke("Turned off buzzer on " + reader.Name); } } } catch (Exception) { } }