Ejemplo n.º 1
0
 private void _dcmd(byte[] _name)
 {
     try
     {
         // initialize the reader.
         SCardReader _reader = new SCardReader(_context);
         _context.Establish(SCardScope.System);
         // connect to the reader, protocol not limited.
         SCardError _error = _reader.Connect(_port,
                                             SCardShareMode.Direct,
                                             SCardProtocol.Unset);
         if (CheckError(_error))
         {
             throw new PCSCException(_error);
         }
         byte[] _pbRecvBuffer = new byte[256];
         // use the hexadecimal code to control the LED.
         _error = _reader.Control(IOCTL_SCL2000_CTL, _name, ref _pbRecvBuffer);
         if (CheckError(_error))
         {
             throw new PCSCException(_error);
         }
         string _result = ToHexString(_pbRecvBuffer);
         // disconnect the reader.
         _reader.Disconnect(SCardReaderDisposition.Leave);
     }
     catch (PCSCException ex)
     {
         Console.WriteLine(ex.Message + " (" + ex.SCardError.ToString() + ") ");
     }
     catch (InvalidOperationException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 2
0
        public bool ReadVersionInformation()
        {
            bool Result = false;

            Version = "";

            byte[] capdu = new byte[] { 0xE0, 0x00, 0x00, 0x18, 0x00 };
            byte[] rapdu = new byte[128];

            try
            {
                SCardError ret = reader.Connect(readers[indexReader], SCardShareMode.Direct, SCardProtocol.Unset);

                Result = (ret == SCardError.Success);

                if (Result)
                {
                    ret = reader.Control(SCARD_CTL_CODE(3500), capdu, ref rapdu);

                    Result = (ret == SCardError.Success) &&
                             (rapdu.Length >= 6) && (rapdu[0] == 0xE1) && (rapdu[1] == 0x00) && (rapdu[2] == 0x00) && (rapdu[3] == 0x00);

                    if (Result)
                    {
                        Version = System.Text.ASCIIEncoding.ASCII.GetString(rapdu, 5, rapdu[4]);
                    }

                    reader.Disconnect(SCardReaderDisposition.Leave);
                }
            }
            catch (Exception E)
            {
                Result = false;
            }

            return(Result);
        }