Ejemplo n.º 1
0
        private void btnISOReadWithID_Click(object sender, EventArgs e)
        {
            int  addr;
            int  len;
            int  i         = 0;
            int  status    = 0;
            byte byAntenna = 0;

            byte[] TagID = new byte[16];
            byte[] value = new byte[32];
            string s     = "The data is:";
            string s1    = "";

            try
            {
                addr = int.Parse(tIsoAddr.Text);
                len  = int.Parse(tIsoCnt.Text);
            }
            catch (Exception)
            {
                lInfo.Items.Add("Please input ByteAddr and ByteCnt");
                return;
            }
            string hexValues = txtTagID.Text;

            string[] hexValuesSplit = hexValues.Split(' ');
            try
            {
                foreach (String hex in hexValuesSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    int x = Convert.ToInt32(hex, 16);
                    TagID[i++] = (byte)x;
                }
            }
            catch (Exception)
            {
                lInfo.Items.Add("Please input Tag ID needed");
                return;
            }
            if (i != 8)
            {
                lInfo.Items.Add("Please input Tag ID needed");
                return;
            }

            for (i = 0; i < len;)
            {
                status = Api.IsoReadWithID(TagID, (byte)(addr + i), ref value, ref byAntenna);
                if (status != 0)
                {
                    lInfo.Items.Add("Read failed!");
                    return;
                }

                for (int j = 0; j < 8; j++)
                {
                    s1 = string.Format("{0:X2}", value[j]);
                    s += s1;
                    if (i + j >= len - 1)
                    {
                        break;
                    }
                }
                i += 8;
            }
            if (status == 0)
            {
                lInfo.Items.Add("Read success!");
                lInfo.Items.Add(s);
            }
        }