Ejemplo n.º 1
0
        public byte[] ReadScratchpad()
        {
            byte[] result_block;

            // select the device
            if (Adapter.SelectDevice(Address, 0))
            {
                // create a block to send that reads the scratchpad
                byte[] send_block = new byte[10];

                // read scratchpad command
                send_block[0] = (byte)0xBE;

                // now add the read bytes for data bytes and crc8
                for (int i = 1; i < 10; i++)
                {
                    send_block[i] = (byte)0xFF;
                }

                // send the block
                //Adapter.DataBlock(send_block, 0, send_block.Length);
                Adapter.DataBlock(send_block);

                // now, send_block contains the 9-byte Scratchpad plus READ_SCRATCHPAD_COMMAND byte
                // convert the block to a 9-byte array representing Scratchpad (get rid of first byte)
                result_block = new byte[9];

                for (int i = 0; i < 9; i++)
                {
                    result_block[i] = send_block[i + 1];
                }

                // see if CRC8 is correct
                if (CRC8.Compute(send_block, 1, 9) == 0)
                {
                    return(result_block);
                }
            }

            return(null);
        }