Esempio n. 1
0
        public static void EraseAllKeys(BaseDevice device)
        {
            if (device.TwiKfdtoolDevice.ComPort == string.Empty)
            {
                throw new ArgumentException("No device selected");
            }

            AdapterProtocol ap = null;

            try
            {
                ap = new AdapterProtocol(device.TwiKfdtoolDevice.ComPort);

                ap.Open();

                ap.Clear();

                ManualRekeyApplication mra = new ManualRekeyApplication(ap);

                mra.EraseAllKeys();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (ap != null)
                    {
                        ap.Close();
                    }
                }
                catch (System.IO.IOException ex)
                {
                    Logger.Warn("could not close serial port: {0}", ex.Message);
                }
            }
        }
Esempio n. 2
0
        public static void CheckTargetMrConnection(BaseDevice device)
        {
            if (device.TwiKfdtoolDevice.ComPort == string.Empty)
            {
                throw new ArgumentException("No device selected");
            }

            AdapterProtocol ap = null;

            try
            {
                ap = new AdapterProtocol(device.TwiKfdtoolDevice.ComPort);

                ap.Open();

                ap.Clear();

                ThreeWireProtocol twp = new ThreeWireProtocol(ap);

                twp.CheckTargetMrConnection();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (ap != null)
                    {
                        ap.Close();
                    }
                }
                catch (System.IO.IOException ex)
                {
                    Logger.Warn("could not close serial port: {0}", ex.Message);
                }
            }
        }
Esempio n. 3
0
        public static string SelfTest(BaseDevice device)
        {
            string result = string.Empty;

            if (device.TwiKfdtoolDevice.ComPort == string.Empty)
            {
                throw new ArgumentException("No device selected");
            }

            AdapterProtocol ap = null;

            try
            {
                ap = new AdapterProtocol(device.TwiKfdtoolDevice.ComPort);

                ap.Open();

                ap.Clear();

                byte res = ap.SelfTest();

                if (res == 0x01)
                {
                    result = string.Format("Data shorted to ground (0x{0:X2})", res);
                }
                else if (res == 0x02)
                {
                    result = string.Format("Sense shorted to ground (0x{0:X2})", res);
                }
                else if (res == 0x03)
                {
                    result = string.Format("Data shorted to power (0x{0:X2})", res);
                }
                else if (res == 0x04)
                {
                    result = string.Format("Sense shorted to power (0x{0:X2})", res);
                }
                else if (res == 0x05)
                {
                    result = string.Format("Data and Sense shorted (0x{0:X2})", res);
                }
                else if (res == 0x06)
                {
                    result = string.Format("Sense and Data shorted (0x{0:X2})", res);
                }
                else if (res != 0x00)
                {
                    result = string.Format("Unknown self test result (0x{0:X2})", res);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (ap != null)
                    {
                        ap.Close();
                    }
                }
                catch (System.IO.IOException ex)
                {
                    Logger.Warn("could not close serial port: {0}", ex.Message);
                }
            }

            return(result);
        }