Esempio n. 1
0
        private byte[] ReadPassiveTargetId(byte baudrate, int timeout)
        {
            byte[] packet =
            {
                CommandInlistpassivetarget,
                1, // Activate only one target (max 2)
                baudrate
            };

            if (!SendCommandCheckAck(packet, timeout))
            {
                return(null);
            }

            var response = ReadData(20);

            if (response[7] != 1)
            {
                return(null);
            }

            DebugOnly.Print("Tag found!");

            var uid = new byte[response[12]];

            for (uint i = 0; i < response[12]; i++)
            {
                uid[i] = response[13 + i];
            }

            DebugOnly.Print("UID:");
            DebugOnly.PrintByteArray(uid);

            return(uid);
        }
Esempio n. 2
0
        private void WriteCommand(byte[] cmd)
        {
            var cmdlen = (uint)cmd.Length + 1;

            // Compute checksum
            var checksum = Preamble + Preamble + Startcode + HostToPn532;

            for (uint i = 0; i < cmdlen - 1; i++)
            {
                checksum += cmd[i];
            }

            byte[] writeHeader =
            {
                SpiDatawrite,
                Preamble,
                Preamble,
                Startcode,
                (byte)cmdlen,
                (byte)(~cmdlen + 1),
                HostToPn532
            };

            byte[] writeFooter =
            {
                (byte)~checksum,
                Postamble
            };

            // Create write array
            var write = Utility.CombineArrays(writeHeader, cmd);

            write = Utility.CombineArrays(write, writeFooter);

            write = Common.ReverseBit(write);

            spi.Write(write);

            // Debug informations
            DebugOnly.Print("\nSending command: ");
            DebugOnly.PrintByteArray(write);
        }
Esempio n. 3
0
        // LOW LEVEL COMM
        private byte[] ReadData(int n)
        {
            var read = new byte[n + 1];

            byte[] write = { SpiDataread };
            write = Utility.CombineArrays(write, Common.CreateNullPayload(n));

            write = Common.ReverseBit(write);

            spi.WriteRead(write, read);

            read = Utility.ExtractRangeFromArray(read, 1, n);
            read = Common.ReverseBit(read);

            // Debug informations
            DebugOnly.Print("\nReading response: ");
            DebugOnly.PrintByteArray(read);

            return(read);
        }