예제 #1
0
        internal NfcModulation ReadModulation()
        {
            IntPtr        ptrModulation = this.m_ptr + nfc_target_info.SIZE;
            NfcModulation modulation    = Marshal.PtrToStructure <NfcModulation>(ptrModulation);

            return(modulation);
        }
예제 #2
0
        NfcSelectedTarget INfcInitiator.Select(NfcModulation modulation)
        {
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf <nfc_target>());
            int    code = NativeMethods.initiator_select_passive_target(this.handle, modulation, IntPtr.Zero, 0, ptr);

            if (code < 0)
            {
                Marshal.FreeHGlobal(ptr);
                NfcException.Raise((NfcError)code);
            }
            if (code == 0)
            {
                Marshal.FreeHGlobal(ptr);
                return(null);
            }
            return(new NfcSelectedTarget(ptr, this));
        }
예제 #3
0
        public static MifareTag SelectMifareTag(this INfcInitiator initiator)
        {
            NfcDevice         device   = (NfcDevice)initiator;
            NfcModulation     ncMifare = new NfcModulation(NfcModulationType.ISO14443A, NfcBaudRate.BR106);
            NfcSelectedTarget target   = initiator.Select(ncMifare);

            if (target == null)
            {
                return(null);
            }

            if (target.Target.TasteMifareClassic1k())
            {
                return(new MifareClassic1kTag(target));
            }
            return(new GenericTag(target));
        }
예제 #4
0
        NfcTargetList INfcInitiator.ListPassiveTargets(NfcModulation modulation)
        {
            int    size    = Marshal.SizeOf <nfc_target>() * MAX_CANDIDATES;
            IntPtr ptrData = Marshal.AllocHGlobal(size);
            int    count   = NativeMethods.initiator_list_passive_targets(this.handle, modulation, ptrData, MAX_CANDIDATES);

            if (count < 0)
            {
                Marshal.FreeHGlobal(ptrData);
                NfcException.Raise((NfcError)count);
                return(null);
            }
            if (count == 0)
            {
                Marshal.FreeHGlobal(ptrData);
                return(new NfcTargetList(IntPtr.Zero, 0, this));
            }
            return(new NfcTargetList(ptrData, count, this));
        }