Exemplo n.º 1
0
        /// <summary>
        /// Read Nfc Tag from µFR Reader and transfer data to database
        /// </summary>
        static void ReadCycle_uFR(ref bool card_in_field)
        {
            //signaling
            const byte FRES_OK_LIGHT = 0x01,    // long green
                       FERR_LIGHT    = 0x02,    // long red
                       FRES_OK_SOUND = 0x01,    // short
                       FERR_SOUND    = 0x00;    // none

            uFR.DL_STATUS dl_status;
            string        nfcDataContent = string.Empty;

            (dl_status, nfcDataContent) = Functions_uFR.ReadLinear();

            switch (dl_status)
            {
            case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_2:
            case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_5:
                Functions_uFR.reader_automaticOpen();
                break;

            case uFR.DL_STATUS.UFR_OK:
                if (!card_in_field)
                {
                    card_in_field = true;
                    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");
                            uFCoder.ReaderUISignal(FERR_LIGHT, FERR_SOUND);
                            WriteExceptions(ex);
                        }
                        Console.WriteLine(nfcDataContent);
                        if (dbSaveOk)
                        {
                            uFCoder.ReaderUISignal(FRES_OK_LIGHT, FRES_OK_SOUND);
                        }
                    }
                    else
                    {
                        uFCoder.ReaderUISignal(FERR_LIGHT, FERR_SOUND);
                    }
                }
                break;

            case uFR.DL_STATUS.UFR_NO_CARD:
                card_in_field = false;
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Write data into Nfc Tag
        /// </summary>
        static void WriteCycle_uFR(string nfcNewDataContent)
        {
            //signaling
            const byte FRES_OK_LIGHT = 0x01,    // long green
                       FERR_LIGHT    = 0x02,    // long red
                       ALT_LIGHT     = 0x03,    // alternation
                       FLASH_LIGHT   = 0x04,    // flash
                       FRES_OK_SOUND = 0x01,    // short
                       FERR_SOUND    = 0x00;    // none

            uFR.DL_STATUS dl_status;

            bool signalingOn = false;

            if (!string.IsNullOrEmpty(nfcNewDataContent))
            {
                (dl_status) = Functions_uFR.WriteLinear(nfcNewDataContent);
                signalingOn = true;
            }
            else
            {
                (dl_status, _) = Functions_uFR.ReadLinear();
            }

            switch (dl_status)
            {
            case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_2:
            case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_5:
                Functions_uFR.reader_automaticOpen();
                break;

            case uFR.DL_STATUS.UFR_OK:
                if (signalingOn)
                {
                    uFCoder.ReaderUISignal(FRES_OK_LIGHT, FRES_OK_SOUND);
                }
                break;

            default:
                if (signalingOn)
                {
                    uFCoder.ReaderUISignal(FERR_LIGHT, FERR_SOUND);
                }
                else
                {
                    uFCoder.ReaderUISignal(ALT_LIGHT, FERR_SOUND);
                }
                break;
            }
        }