Exemplo n.º 1
0
 internal NfcTag(IntPtr handle)
 {
     _tagHandle = handle;
     _nativeTransceiveCallback = TransceiveCompletedCallback;
     _nativeVoidCallback       = VoidCallback;
     _nativeTagReadCallback    = ReadNdefCallback;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Transceives the data of the raw format card.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="buffer">The binary data for a parameter or additional commands.</param>
        /// <privilege>http://tizen.org/privilege/nfc</privilege>
        /// <exception cref="NotSupportedException">Thrown when the NFC is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the the method fails due to an invalid operation.</exception>
        public Task <byte[]> TransceiveAsync(byte[] buffer)
        {
            var task = new TaskCompletionSource <byte[]>();

            byte[] resultBuffer = null;
            Interop.Nfc.TagTransceiveCompletedCallback callback = (int result, IntPtr resultData, int dataSize, IntPtr userData) =>
            {
                if (result == (int)NfcError.None)
                {
                    resultBuffer = new byte[dataSize];
                    Marshal.Copy(resultData, resultBuffer, 0, dataSize);
                    task.SetResult(resultBuffer);
                }
                return;
            };

            int ret = Interop.Nfc.Tag.Transceive(_tagHandle, buffer, buffer.Length, callback, IntPtr.Zero);

            if (ret != (int)NfcError.None)
            {
                Log.Error(Globals.LogTag, "Failed to transceive data, Error - " + (NfcError)ret);
                NfcErrorFactory.ThrowNfcException(ret);
            }

            return(task.Task);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor of NfcTag
 /// </summary>
 public NfcTag()
 {
     // A method is need to convert delegate to pass unmanaged layer through Interop call
     // If we do not convert explicitly it, implicitly convert was occurred
     // and temporal delegate was created. and it could be released by GC
     _nativeTransceiveCallback = TransceiveCompletedCallback;
     _nativeVoidCallback       = VoidCallback;
     _nativeTagReadCallback    = ReadNdefCallback;
 }