private void Button_Click(object sender, RoutedEventArgs e)
 {
     RFIDReader._spiDevice.Dispose();
     RFIDReader._resetPin.Dispose();
     RFIDReader = null;
     Window.Current.Close();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StartPageLogic"/> class.
 /// </summary>
 public StartPageLogic()
 {
     _mfrc522        = new MFRC522(BoardConfig.MFRC522CmdPin, BoardConfig.MFRC522ResetPin);
     _distanceSensor = new UltrasonicDistanceSensor(BoardConfig.UltrasonicSensorTriggerPin, BoardConfig.UltrasonicSensorEchoPin);
     _camera         = new PhotoCam();
     _motor          = new ServoMotor(BoardConfig.ServoMotorPin);
     _httpClient     = new HttpClient();
 }
 public TeacherPage()
 {
     this.InitializeComponent();
     httpController = new HttpController();
     RFIDReader     = new MFRC522();
     InitRFIDReader();
     runTask();
 }
Ejemplo n.º 4
0
        static void Main()
        {
            // Set pins
            //Configuration.SetPinFunction(GpioPin, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);

            Debug.WriteLine("###############################################");
            Debug.WriteLine("# SPI1");
            Debug.WriteLine("###############################################");
            Debug.WriteLine($"SPI1_CLOCK:" + Configuration.GetFunctionPin(DeviceFunction.SPI1_CLOCK));
            Debug.WriteLine($"SPI1_MISO :" + Configuration.GetFunctionPin(DeviceFunction.SPI1_MISO));
            Debug.WriteLine($"SPI1_MOSI :" + Configuration.GetFunctionPin(DeviceFunction.SPI1_MOSI));
            Debug.WriteLine("###############################################");

            _mfRc522 = new MFRC522("SPI1", 4, 5);

            Debug.WriteLine("");
            Debug.WriteLine($"Version: 0x{_mfRc522.GetVersion():X}");
            Debug.WriteLine("");
            Debug.WriteLine("###############################################");

            byte[] bufferAtqa = new byte[2];
            byte[] defaultKey = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

            while (true)
            {
                //test
                //bufferAtqa[0] = 0x0;
                //bufferAtqa[1] = 0x0;

                if (_mfRc522.IsNewCardPresent(bufferAtqa))
                {
                    // Debug.WriteLine("Card detected...");
                    // Debug.WriteLine($"ATQA: 0x{bufferAtqa[1]:X2},0x{bufferAtqa[0]:X2}");

                    var uid = _mfRc522.PiccReadCardSerial();
                    if (uid != null)
                    {
                        DisplayUid(uid);

                        //try
                        //{
                        //    byte pageOrSector = (byte)(uid.GetPiccType() == PiccType.Mifare1K ? 16 : 4);
                        //    for (byte i = 0; i < pageOrSector; i++)
                        //    {
                        //        Debug.WriteLine($"{i}:");
                        //        var buffer = _mfRc522.GetSector(uid, i, defaultKey /*, PiccCommand.AuthenticateKeyA*/);
                        //        if (uid.GetPiccType() == PiccType.Mifare1K)
                        //        {
                        //            var c = _mfRc522.GetAccessRights(buffer);
                        //            Display1kBuffer(buffer, c);
                        //        }
                        //        else if (uid.GetPiccType() == PiccType.MifareUltralight)
                        //        {
                        //            DisplayUltralightBuffer(buffer);
                        //        }
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    Debug.WriteLine(ex.Message);
                        //}

                        _mfRc522.Halt();

                        _mfRc522.StopCrypto();
                    }
                    else
                    {
                        _mfRc522.ResetItAndShoot();
                    }
                }

                Thread.Sleep(500);
            }
        }