Ejemplo n.º 1
0
        private void readBlockTest()
        {
            byte byteLen = 0;

            byte[] ary_data = new byte[128];    //the first byte is DSFID, and the other 8 byte containers the UID data
            try
            {
                byte[] a = new byte[8];
                st = ISO15693Commands.rf_readblock(icdev, 0x22, 0x00, 0x0A, uid, out byteLen, ary_data);
                if (st != 0)
                {
                    MessageBox.Show("未发现单个标签");
                    return;
                }
                else
                {
                    string blockData = CCommondMethod.ByteArrayToString(ary_data, 0, 128);

                    textBox2.Text = blockData;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private ErrorCode ReadData()
        {
            // the application note says, max block number per read is 10 blocks.
            try
            {
                byte[] rtnData = new byte[4];    //read first block, get the data length
                byte   rtnLen  = 0;
                st = ISO15693Commands.rf_readblock(ReaderInfo.icdev, 0x22, 0x00, (byte)1, m_btTagUID, out rtnLen, rtnData);
                if (st != 0)
                {
                    //MessageBox.Show("error");
                    return(ErrorCode.ReadFail);
                }
                else
                {
                    //bool b_readLengthData = true;

                    byte[] lenthData = new byte[2];
                    //the first two bytes stored data length
                    Array.Copy(rtnData, 2, lenthData, 0, 2);

                    Int32 i_totalBytes = BitConverter.ToInt16(lenthData, 0) + 4;

                    if (i_totalBytes == 4)
                    {
                        return(ErrorCode.TagHasNoData);
                    }

                    readBuffer = new byte[i_totalBytes - 4];



                    st = 0;
                    byte blockIndex = 1;
                    int  byteIndex  = 0;

                    while (i_totalBytes > 0 && st == 0)
                    {
                        byte blockLen = 0;
                        //if (i_totalBytes % 4 == 0)
                        //{
                        //    blockLen = (byte)(i_totalBytes / 4);
                        //}
                        //else
                        //{
                        //    blockLen = (byte)(i_totalBytes / 4 + 1);
                        //}

                        blockLen = (byte)((i_totalBytes + 3) / 4);

                        //calculate block number required, max number is 10
                        byte blockNumber = blockLen > (byte)10 ? (byte)10 : blockLen;

                        //byte byteNumber = 0;

                        byte[] readData = new byte[blockNumber * 4];

                        st = ISO15693Commands.rf_readblock(ReaderInfo.icdev, 0x22, blockIndex, blockNumber, m_btTagUID, out rtnLen, readData);

                        if (st == 0)
                        {
                            int leftDataLength = readBuffer.Length - byteIndex;
                            int copyDataLength = leftDataLength > readData.Length ? readData.Length : leftDataLength;

                            //if (b_readLengthData)
                            //{
                            //    Array.Copy(readData, 2, readBuffer, byteIndex, copyDataLength == readData.Length ? copyDataLength - 2 : copyDataLength);

                            //    //b_readLengthData = true;
                            //}
                            //else
                            //{
                            Array.Copy(readData, 0, readBuffer, byteIndex, copyDataLength);
                            //}
                        }
                        else
                        {
                            return(ErrorCode.ReadFail);
                        }

                        byteIndex += rtnLen;
                        //if (b_readLengthData)
                        //{
                        //    byteIndex -= 2;

                        //    b_readLengthData = false;
                        //}
                        blockIndex   += blockNumber;
                        i_totalBytes -= rtnLen;

                        System.Threading.Thread.Sleep(20);
                    }

                    return(ErrorCode.ReadSuccessful);
                }
            }
            catch (Exception)
            {
                return(ErrorCode.OtherException);
            }
        }