public NfcContext() { Libnfc.Init(out contextPointer); if (contextPointer == IntPtr.Zero) { throw new Exception("Unable to init libnfc (malloc)"); } }
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"); } }
public void InitiatorInit() { var result = Libnfc.InitiatorInit(devicePointer); if (result < 0) { Perror("nfc_initiator_init"); throw new Exception("nfc_initiator_init"); } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { // Dispose managed resources. // component.Dispose(); } Libnfc.Exit(contextPointer); contextPointer = IntPtr.Zero; disposed = true; } }
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); }
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)); }
public string Version() => Libnfc.Version();
public void Perror(string s) => Libnfc.Perror(devicePointer, s);
public int InitiatorTransceiveBytes(byte[] pbtTx, uint szTx, byte[] pbtRx, uint szRx, int timeout) => Libnfc.InitiatorTransceiveBytes(devicePointer, pbtTx, szTx, pbtRx, szRx, timeout);
public int InitiatorTransceiveBytesTimed(byte[] pbtTx, uint szTx, byte[] pbtRx, uint szRx, ref uint cycles) => Libnfc.InitiatorTransceiveBytesTimed(devicePointer, pbtTx, szTx, pbtRx, szRx, ref cycles);
public int InitiatorTransceiveBits(byte[] pbtTx, uint szTxBits, byte[] pbtTxPar, byte[] pbtRx, uint szRx, byte[] pbtRxPar) => Libnfc.InitiatorTransceiveBits(devicePointer, pbtTx, szTxBits, pbtTxPar, pbtRx, szRx, pbtRxPar);