Example #1
0
        public static async Task <byte[]> DoFastRead(
            this INFCMiFareTag tag,
            byte from,
            byte to,
            byte batchSize)
        {
            var results = new List <MifareCommandResult>();

            while (from < to)
            {
                var thisTo = (byte)Math.Min(from + batchSize, to);
                var data   = await tag.SendMifareCommand(0x3a, from, thisTo);

                results.Add(data);

                from = (byte)(from + (byte)(batchSize + 0x1));
            }

            if (results.Any(x => x.Error != null))
            {
                throw new Exception($"Failed to fast read; first error: {results.First(x => x.Error != null).Error}");
            }

            var all = MifareCommandResult.Combine(results);

            return(all.Data);
        }
Example #2
0
        public static async Task <byte[]> WritePage(
            this INFCMiFareTag tag,
            byte page,
            byte[] data)
        {
            var cmd = new byte[] { 0xa2, (byte)(page) }.Concat(data).ToArray();
            var result = await tag.SendMifareCommand(cmd);

            if (result.Error != null)
            {
                Debug.WriteLine(result.Error);
            }

            return(result.Data);
        }