Esempio n. 1
0
 public NfcContext()
 {
     Libnfc.Init(out contextPointer);
     if (contextPointer == IntPtr.Zero)
     {
         throw new Exception("Unable to init libnfc (malloc)");
     }
 }
Esempio n. 2
0
        public void DeviceSetPropertyBool(NfcProperty property, bool enable)
        {
            var result = Libnfc.DeviceSetPropertyBool(devicePointer, property, enable);

            if (result < 0)
            {
                Perror("nfc_device_set_property_bool");
                throw new Exception("nfc_device_set_property_bool");
            }
        }
Esempio n. 3
0
        public void InitiatorInit()
        {
            var result = Libnfc.InitiatorInit(devicePointer);

            if (result < 0)
            {
                Perror("nfc_initiator_init");
                throw new Exception("nfc_initiator_init");
            }
        }
Esempio n. 4
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             // Dispose managed resources.
             // component.Dispose();
         }
         Libnfc.Exit(contextPointer);
         contextPointer = IntPtr.Zero;
         disposed       = true;
     }
 }
Esempio n. 5
0
        public List <string> ListDevices(int count = Libnfc.MaxUserDefinedDevices + 6)
        {
            IntPtr connectionStringsPointer = Marshal.AllocHGlobal(Libnfc.ConnectStringBufferSize * count);
            var    devicesCount             = Libnfc.ListDevices(contextPointer, connectionStringsPointer, (uint)count);

            var devices = new List <string>((int)devicesCount);

            for (int i = 0; i < devicesCount; i++)
            {
                devices.Add(Marshal.PtrToStringAnsi(connectionStringsPointer + i * count));
            }

            Marshal.FreeHGlobal(connectionStringsPointer);
            return(devices);
        }
Esempio n. 6
0
        public virtual NfcDevice OpenDevice(string name = null)
        {
            IntPtr devicePointer;

            try
            {
                devicePointer = Libnfc.Open(contextPointer, name);
                if (devicePointer == IntPtr.Zero)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Error opening NFC reader");
            }

            return(new NfcDevice(devicePointer));
        }
Esempio n. 7
0
 public string Version() => Libnfc.Version();
Esempio n. 8
0
 public void Perror(string s) =>
 Libnfc.Perror(devicePointer, s);
Esempio n. 9
0
 public int InitiatorTransceiveBytes(byte[] pbtTx, uint szTx, byte[] pbtRx, uint szRx, int timeout) =>
 Libnfc.InitiatorTransceiveBytes(devicePointer, pbtTx, szTx, pbtRx, szRx, timeout);
Esempio n. 10
0
 public int InitiatorTransceiveBytesTimed(byte[] pbtTx, uint szTx, byte[] pbtRx, uint szRx, ref uint cycles) =>
 Libnfc.InitiatorTransceiveBytesTimed(devicePointer, pbtTx, szTx, pbtRx, szRx, ref cycles);
Esempio n. 11
0
 public int InitiatorTransceiveBits(byte[] pbtTx, uint szTxBits, byte[] pbtTxPar, byte[] pbtRx, uint szRx, byte[] pbtRxPar) =>
 Libnfc.InitiatorTransceiveBits(devicePointer, pbtTx, szTxBits, pbtTxPar, pbtRx, szRx, pbtRxPar);