コード例 #1
0
        static void ReadCycle_RC522(string actEnvironment, ref int card_in_field)
        {
            if (actEnvironment == null || actEnvironment.StartsWith("RPI") == false)
            {
                return;
            }

            Functions_RC522.InvertLedSignal();

            (bool cardDetected, bool readDone, string nfcDataContent) = Functions_RC522.ReadTagFromRC522();

            // data from reader received ?
            if (string.IsNullOrEmpty(nfcDataContent) == false && readDone && card_in_field == 0)
            {
                card_in_field = 3;
                Person person = FunctionsCCT.ParseNfcDataToPerson(nfcDataContent);

                if (person != null)
                {
                    bool dbSaveOk = false;
                    try
                    {
                        dbSaveOk = FunctionsCCT.AddPersonToDb(person);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Could not write to database");
                        // Signal not ok ??;
                        WriteExceptions(ex);
                    }
                    Console.WriteLine(nfcDataContent);
                    if (dbSaveOk)
                    {
                        Functions_RC522.BeepSignal();
                    }
                }
            }
            else if (card_in_field > 0)
            {
                if (cardDetected)
                {
                    card_in_field = 3;
                }
                else
                {
                    card_in_field--;
                }
            }
            else
            {
                card_in_field = 0;
            }
        }
コード例 #2
0
        private static void WriteCycle_RC522(string actEnvironment, string nfcNewDataContent)
        {
            if (actEnvironment == null || actEnvironment.StartsWith("RPI") == false)
            {
                return;
            }

            Functions_RC522.InvertLedSignal(2);

            if (!string.IsNullOrEmpty(nfcNewDataContent))
            {
                (_, bool done) = Functions_RC522.WriteTagRC522(nfcNewDataContent);

                if (done)
                {
                    Functions_RC522.BeepSignal();
                }
            }
        }