Ejemplo n.º 1
0
        /// <summary>
        /// Write an NDEF message to a NFC tag
        /// </summary>
        ///
        /// <example>
        /// <para>
        ///     Example of how to write a Ndef message with a single text record
        /// </para>
        ///
        ///
        /// <code language="cs">
        ///      using System;
        ///      using TapTrack.Classic.Ndef;
        ///
        ///      namespace TapTrack.Classic.Example
        ///      {
        ///          class WriteNdefExample
        ///          {
        ///              static void Main(string[] args)
        ///              {
        ///                  Driver tappyDriver = new Driver();
        ///                  TextRecordPayload payload = new TextRecordPayload("en", "Hello world!");   // Ndef message with one text record
        ///
        ///                  tappyDriver.AutoDetect();                                                  // Automatically connect to the first TappyUSB the driver finds
        ///
        ///                  tappyDriver.WriteNdef(0, false, new NdefMessage(payload), null);           // Send the WriteNdef command with no timeout and no callbacks
        ///
        ///                  Console.WriteLine("Please tap tag");
        ///                  Console.ReadKey();                                                         // Stop the program from exiting
        ///              }
        ///          }
        ///      }
        /// </code>
        /// <para>
        ///     How to write a multi-Ndef record to a tag
        /// </para>
        /// <code language="cs">
        ///    using System;
        ///    using System.Collections.Generic;
        ///    using TapTrack.Classic.Ndef;
        ///
        ///    namespace TapTrack.Classic.Example
        ///    {
        ///        class WriteNdefExample
        ///        {
        ///            static void Main(string[] args)
        ///            {
        ///                Driver tappyDriver = new Driver();
        ///
        ///                List&lt;RecordPayload&gt; payload = new List&lt;RecordPayload&gt;();
        ///
        ///                TextRecordPayload textRecord = new TextRecordPayload("en", "Hello world!");
        ///                UriRecordPayload uriRecord = new UriRecordPayload("http://www.taptrack.com");
        ///
        ///                payload.Add(textRecord);
        ///                payload.Add(uriRecord);
        ///
        ///                tappyDriver.AutoDetect();
        ///
        ///                tappyDriver.WriteNdef(0, false, new NdefMessage(payload.ToArray()), null);
        ///
        ///                Console.WriteLine("Please tap tag");
        ///                Console.ReadKey();
        ///            }
        ///        }
        ///    }
        /// </code>
        ///
        /// </example>
        ///
        /// <param name="timeout">The max time the TappyUSB will wait for a tag. 0 = infinite timeout</param>
        /// <param name="willLock">Determine whether to lock to tag after writing, locking prevents further writing to the tag</param>
        /// <param name="message">Ndef message to be sent</param>
        /// <param name="successHandler">Method to be called when a success occurs</param>
        /// <param name="ackHandler">Method to be called when an ACK is received</param>
        /// <param name="errorHandler">Method to be called when an application, NACK, DCS, or LCS error occurs</param>
        public void WriteNdef(byte timeout, bool willLock, NdefMessage message, Callback successHandler, Callback ackHandler = null, CallbackError errorHandler = null)
        {
            Debug.WriteLine("Starting Command: Write Ndef");
            List <byte> data = new List <byte>();

            data.Add(timeout);
            data.Add(Convert.ToByte(willLock));
            data.AddRange(message.GetByteArray());
            Send(Frame.ConstructCommand(Driver.CMD.WRITE_NDEF, data.ToArray()), new CallbackSet(successHandler, ackHandler, errorHandler));
        }