//NfcTarget INfcInitiator.Poll(NfcModulation[] modulations, byte pollNr, byte period) //{ // this.SetProperty(NfcProperty.NP_ACTIVATE_FIELD, false); // this.SetProperty(NfcProperty.NP_HANDLE_CRC, true); // this.SetProperty(NfcProperty.NP_HANDLE_PARITY, true); // this.SetProperty(NfcProperty.NP_AUTO_ISO14443_4, true); // this.SetProperty(NfcProperty.NP_ACTIVATE_FIELD, true); // NfcTarget[] targets = new NfcTarget[10]; // GCHandle h = GCHandle.Alloc(targets, GCHandleType.Pinned); // try // { // int count = NativeMethods.initiator_list_passive_targets(this.m_ptr, modulations[0], h.AddrOfPinnedObject(), targets.Length); // if (count < 0) // NfcException.Raise((NfcError)count); // if (count == 0) // return null; // } // finally // { // h.Free(); // } //} NfcTarget INfcInitiator.Poll(NfcModulation[] modulations, byte pollNr, byte period) { IntPtr nfcTarget = IntPtr.Zero; int count; GCHandle gc = GCHandle.Alloc(modulations, GCHandleType.Pinned); try { int size = Marshal.SizeOf <Interop.nfc_target>(); nfcTarget = Marshal.AllocHGlobal(size); Console.WriteLine("Allocated nfcTarget memory. size={0} ptr={1}", size, nfcTarget); count = NativeMethods.initiator_poll_target(this.handle, modulations, (uint)modulations.Length, pollNr, period, nfcTarget); Console.WriteLine($"episage nfc returned {count}"); } finally { Marshal.FreeHGlobal(nfcTarget); gc.Free(); } if (count < 0) { Console.WriteLine("LastError={0}", this.LastError); NfcException.Raise((NfcError)count); } if (count == 0) { return(null); } NfcTarget target = new NfcTarget(this, nfcTarget); return(target); }
protected override void FreeHandle() { NfcError code = NativeMethods.initiator_deselect_target(this.m_device.DangerousGetHandle()); if (code != NfcError.Success) { NfcException.Raise(code); } Marshal.FreeHGlobal(this.handle); }
public INfcInitiator InitInitiator(bool secure) { NfcError ret; if (secure) { ret = NativeMethods.initiator_init_secure_element(this.handle); } else { ret = NativeMethods.initiator_init(this.handle); } NfcException.Raise(ret); return(this); }
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)); }
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)); }
public void SetProperty(NfcProperty property, bool value) { NfcError err = NativeMethods.device_set_property_bool(this.handle, property, value); NfcException.Raise(err); }