Ejemplo n.º 1
0
        private void btnISOWriteWithID_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 hexID = txtTagID.Text;

            string[] hexIDSplit = hexID.Split(' ');
            try
            {
                foreach (String hex in hexIDSplit)
                {
                    // 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;
            }
            string hexValues = tIsoData.Text;

            string[] hexValuesSplit = hexValues.Split(' ');
            try
            {
                i = 0;
                foreach (String hex in hexValuesSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    if (hex != "")
                    {
                        int x = Convert.ToInt32(hex, 16);
                        value[i++] = (byte)x;
                    }
                }
            }
            catch (Exception)
            {
                lInfo.Items.Add("Please input data needed");
                return;
            }
            if (i != len)
            {
                lInfo.Items.Add("Please input data needed");
                return;
            }
            for (i = 0; i < len; i++)
            {
                status = Api.IsoWriteWithID(TagID, (byte)(addr + i), value[i]);
                if (status != 0)
                {
                    lInfo.Items.Add("Write failed!");
                    return;
                }
            }
            lInfo.Items.Add("Write success!");
        }