예제 #1
0
        void  CreateMonitorThreads()
        {
            int i, unFinished = 0;

            if (MachLst.Count == 0)
            {
                return;
            }

            for (i = 0, unFinished = 0; i < MachLst.Count; i++)
            {
                if (MachLst[i].rd == null)
                {
                    unFinished = 1;
                    MyManager.AddInfoToDB("错误", MachLst[i].MachName + "未建立连接!");
                    lst1.Items.Add(MachLst[i].MachName + "未建立连接!");
                    break;
                }
                //只显示EPC以FFFF FFFF开头的标签
                Gen2TagFilter filter = new Gen2TagFilter(ByteFormat.FromHex("FFFFFFFF"), MemBank.EPC, 32, false);
                MachLst[i].rd.ParamSet("Singulation", filter);
                SimpleReadPlan searchPlan = new SimpleReadPlan(MachLst[i].ConnectedAnts);
                MachLst[i].rd.ParamSet("ReadPlan", searchPlan);
                MachLst[i].Mthread = new Thread(new ParameterizedThreadStart(TagMonitorThread));
            }

            if (unFinished == 1)
            {
                return;
            }

            for (i = 0; i < MachLst.Count; i++)
            {
                MachLst[i].Mthread.Start(MachLst[i]);
                lst1.Items.Add("启动" + MachLst[i].Mthread);
            }

            lst1.Items.Add("创建线程完毕!");
        }
예제 #2
0
 public void Kill()
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             uint           killPassword = ByteConv.ToU32(ByteFormat.FromHex(textBox3.Text), 0);
             TagOp          tagOp        = new Gen2.Kill(killPassword);
             SimpleReadPlan plan         = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #3
0
 public void WritePassword(uint byteIndex, string password)
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         ushort[] data           = ByteConv.ToU16s(ByteFormat.FromHex(password));
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             TagOp          tagOp = new Gen2.WriteData(Gen2.Bank.RESERVED, byteIndex, data);
             SimpleReadPlan plan  = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #4
0
        private void btnbrl_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("请选择操作天线");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            byte[] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("访问密码不能为空");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("访问密码必须是8个16进制数");
                    break;

                case -1:
                    MessageBox.Show("访问密码只能是16进制数字");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }

            byte bitmap = 0;

            if (cb1.Checked)
            {
                bitmap |= 1 << 7;
            }
            if (cb2.Checked)
            {
                bitmap |= 1 << 6;
            }
            if (cb3.Checked)
            {
                bitmap |= 1 << 5;
            }
            if (cb4.Checked)
            {
                bitmap |= 1 << 4;
            }
            if (cb5.Checked)
            {
                bitmap |= 1 << 3;
            }
            if (cb6.Checked)
            {
                bitmap |= 1 << 2;
            }
            if (cb7.Checked)
            {
                bitmap |= 1 << 1;
            }
            if (cb8.Checked)
            {
                bitmap |= 1 << 0;
            }

            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }

            try
            {
                ALIEN_Higgs3_BlockReadLockPara para = new ALIEN_Higgs3_BlockReadLockPara(bitmap, pwd);
                mrdr.CustomCmd(filter, CustomCmdType.ALIEN_Higgs3_BlockReadLock, para);
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("没法发现标签");
                }
                else
                {
                    MessageBox.Show("操作失败:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("操作失败" + ex.ToString());
                return;
            }
        }
예제 #5
0
        private void btnwrite_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }
            if (selants.Count != 1)
            {
                MessageBox.Show("必须且只能选择个一个天线");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("请选中要操作的卡号");
                return;
            }
            string sltag = listBox2.SelectedItem.ToString();


            if (IsValidHexstr(this.rtbdata.Text.Trim(), 432) != 0)
            {
                MessageBox.Show("将要写入的数据必须是16进制的字符,且长度为2字符的整数倍,最大长度不超过432个字符");
                return;
            }

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入起始地址");
                return;
            }

            int bytecnt = this.rtbdata.Text.Trim().Length / 2;

            try
            {
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                int    addrst = int.Parse(this.tbStartAddr.Text.Trim());
                int    st     = Environment.TickCount;
                byte[] wdata  = ByteFormat.FromHex(this.rtbdata.Text.Trim());
                Modrdr.ParamSet("OpTimeout", (ushort)6500);
                Modrdr.WriteTagMemBytes(new ISO180006bTagData(ByteFormat.FromHex(sltag)), MemBank.ISO180006BMEM, addrst, wdata);
                this.label3.Text  = (Environment.TickCount - st).ToString();
                this.rtbdata.Text = "写成功";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Modrdr.ParamSet("OpTimeout", (ushort)1000);
            }
        }
예제 #6
0
        private void btnsetimpinjqt_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("please select antenna");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            byte[] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("please input access password");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("access password must be 8 of hexadecimal numbers");
                    break;

                case -1:
                    MessageBox.Show("access password must be 8 of hexadecimal numbers");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }

            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }

            if ((!this.rbimpinjqtread.Checked) && (!this.rbimpinjwrite.Checked))
            {
                MessageBox.Show("please select command type");
                return;
            }

            try
            {
                if (this.rbimpinjqtread.Checked)
                {
                    IMPINJ_M4_QtPara para = new IMPINJ_M4_QtPara(pwd);

                    IMPINJ_M4_QtResult qtret = (IMPINJ_M4_QtResult)mrdr.CustomCmd(filter, CustomCmdType.IMPINJ_M4_Qt, para);
                    if (qtret.MemType == IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Private)
                    {
                        this.rbimpinjqtmemprivate.Checked = true;
                    }
                    else
                    {
                        this.rbimpinjqtmempublic.Checked = true;
                    }
                    if (qtret.RangeType == IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_FarField)
                    {
                        this.rbimpinjqtfarfield.Checked = true;
                    }
                    else
                    {
                        this.rbimpinjqtnearfiled.Checked = true;
                    }
                }
                else
                {
                    if ((!rbimpinjqtnearfiled.Checked) && (!rbimpinjqtfarfield.Checked))
                    {
                        MessageBox.Show("please select reading distance");
                        return;
                    }
                    if ((!rbimpinjqtmemprivate.Checked) && (!rbimpinjqtmempublic.Checked))
                    {
                        MessageBox.Show("please select memory profile");
                        return;
                    }
                    if ((!rbimpinjqtperm.Checked) && (!rbimpinjqttemp.Checked))
                    {
                        MessageBox.Show("please select persistence type");
                        return;
                    }

                    IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type   trange   = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_Invalid;
                    IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Invalid;
                    IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type     tmem     = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Invalid;

                    if (rbimpinjqtnearfiled.Checked)
                    {
                        trange = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_NearField;
                    }
                    else
                    {
                        trange = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_FarField;
                    }
                    if (rbimpinjqtmemprivate.Checked)
                    {
                        tmem = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Private;
                    }
                    else
                    {
                        tmem = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Public;
                    }
                    if (rbimpinjqtperm.Checked)
                    {
                        tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Perm;
                    }
                    else
                    {
                        tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Temp;
                    }

                    IMPINJ_M4_QtPara para = new IMPINJ_M4_QtPara(pwd, tpersist, trange, tmem);
                    mrdr.CustomCmd(filter, CustomCmdType.IMPINJ_M4_Qt, para);
                }
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("no tag");
                }
                else
                {
                    MessageBox.Show("operation failed:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("operation failed:" + ex.ToString());
                return;
            }
        }
예제 #7
0
        private void btnlock_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }
            if (selants.Count != 1)
            {
                MessageBox.Show("must and only select one antenna");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("please select the id of tag to operate");
                return;
            }
            string sltag = listBox2.SelectedItem.ToString();

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input the starting address");
                return;
            }
            try
            {
                int addrst = int.Parse(this.tbStartAddr.Text.Trim());
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                Modrdr.LockTag(new ISO180006bTagData(ByteFormat.FromHex(sltag)), new ISO180006bLockAction(addrst));
                this.rtbdata.Text = "lock success";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #8
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }

            if (selants.Count != 1)
            {
                MessageBox.Show("must and only select one antenna");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("please select the id of tag to operate");
                return;
            }

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input the starting address");
                return;
            }
            if (this.tbBlkCnt.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input the block count to read");
                return;
            }

            string sltag = listBox2.SelectedItem.ToString();

            try
            {
                int addrst = int.Parse(this.tbStartAddr.Text.Trim());
                int blkcnt = int.Parse(this.tbBlkCnt.Text.Trim());
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                int    t1   = Environment.TickCount;
                byte[] data = Modrdr.ReadTagMemBytes(new ISO180006bTagData(ByteFormat.FromHex(sltag)), MemBank.ISO180006BMEM, addrst, blkcnt);
                Debug.WriteLine((Environment.TickCount - t1).ToString());
                this.rtbdata.Text = ByteFormat.ToHex(data);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    string model = (string)r.ParamGet("/reader/version/model").ToString();
                    if (!model.Equals("M3e"))
                    {
                        if (r.isAntDetectEnabled(antennaList))
                        {
                            Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                            Usage();
                        }
                        //Use first antenna for operation
                        if (antennaList != null)
                        {
                            r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                        }
                    }
                    else
                    {
                        if (antennaList != null)
                        {
                            Console.WriteLine("Module doesn't support antenna input");
                            Usage();
                        }
                    }

                    // This select filter matches all Gen2 tags where bits 32-48 of the EPC are 0x0123
#if ENABLE_FILTER
                    TagFilter filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { 0x01, 0x23 });
#endif
                    if (!model.Equals("M3e"))
                    {
                        //Gen2.TagData epc = new Gen2.TagData(new byte[] {
                        //    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
                        //    0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
                        //});
                        //Gen2.WriteTag tagop = new Gen2.WriteTag(epc);
                        //r.ExecuteTagOp(tagop, null);
                    }

                    // Reads data from a tag memory bank after writing data to the requested memory bank without powering down of tag
#if ENABLE_READ_AFTER_WRITE
                    {
                        //create a tagopList with write tagop followed by read tagop
                        TagOpList tagopList = new TagOpList();
                        byte      wordCount;
                        ushort[]  readData;

                        //Write one word of data to USER memory and read back 8 words from EPC memory using WriteData and ReadData
                        {
                            ushort[] writeData = { 0x9999 };
                            wordCount = 8;
                            Gen2.WriteData wData = new Gen2.WriteData(Gen2.Bank.USER, 2, writeData);
                            Gen2.ReadData  rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);
                            //Gen2.WriteTag wTag = new Gen2.WriteTag(epc);

                            // assemble tagops into list
                            tagopList.list.Add(wData);
                            tagopList.list.Add(rData);

                            Console.WriteLine("###################Embedded Read after write######################");
                            // uncomment the following for embedded read after write.
                            embeddedRead(TagProtocol.GEN2, null, tagopList);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }

                        //clearing the list for next operation
                        tagopList.list.Clear();

                        //Write 12 bytes(6 words) of EPC and read back 8 words from EPC memory using WriteTag and ReadData
                        {
                            Gen2.TagData epc1 = new Gen2.TagData(new byte[] {
                                0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
                                0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
                            });
                            wordCount = 8;
                            Gen2.WriteTag wtag  = new Gen2.WriteTag(epc1);
                            Gen2.ReadData rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);

                            // assemble tagops into list
                            tagopList.list.Add(wtag);
                            tagopList.list.Add(rData);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }
                    }
#endif

                    // Perform read and print UID and tagtype of tag found
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.ISO15693, null, null, 1000);
                    r.ParamSet("/reader/read/plan", plan);
                    TagReadData[] tagReads = r.Read(1000);
                    Console.WriteLine("UID: " + tagReads[0].EpcString);
                    Console.WriteLine("TagType:  " + (Iso15693.TagType)(tagReads[0].TagType));
                    MemoryType  type;
                    MultiFilter mulfilter = null;
                    UInt32      address;
                    byte        length;

#if ENABLE_M3E_FILTER
                    //Initialize filter
                    // Filters the tag based on tagtype
                    TagFilter tagTypeFilter = new Select_TagType((UInt64)((Iso15693.TagType)(tagReads[0].TagType)));
                    // Filters the tag based on UID
                    TagFilter uidFilter = new Select_UID(32, ByteFormat.FromHex(tagReads[0].Tag.EpcString.Substring(0, 8)));
                    // Initialize multi filter
                    mulfilter = new MultiFilter(new TagFilter[] { tagTypeFilter, uidFilter });
#endif

#if ENABLE_M3E_BLOCK_READ_WRITE
                    //Initialize all the fields required for Read Data Tag operation
                    type    = MemoryType.BLOCK_MEMORY;
                    address = 0;
                    length  = 1;

                    // Read memory before write
                    ReadMemory bRead    = new ReadMemory(type, address, length);
                    byte[]     dataRead = (byte[])r.ExecuteTagOp(bRead, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data before performing block write: ");
                    foreach (byte i in dataRead)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
                    // Uncomment this to enable Embedded read memory
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, bRead);

                    // Initialize write memory
                    byte[]      data    = new byte[] { 0x11, 0x22, 0x33, 0x44 };
                    WriteMemory writeOp = new WriteMemory(type, address, data);

                    // Execute the tagop
                    r.ExecuteTagOp(writeOp, mulfilter);
                    // Uncomment this to enable Embedded write data
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, writeOp);

                    //Read memory after block write
                    ReadMemory readOp   = new ReadMemory(type, address, length);
                    byte[]     readData = (byte[])r.ExecuteTagOp(readOp, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data after performing block write operation: ");
                    foreach (byte i in readData)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
#endif

#if ENABLE_M3E_SYSTEM_INFORMATION_MEMORY
                    //Get the system information of tag. Address and length fields have no significance if memory type is BLOCK_SYSTEM_INFORMATION_MEMORY.
                    type    = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY;
                    address = 0;
                    length  = 0;
                    ReadMemory sysInfoOp  = new ReadMemory(type, address, length);
                    byte[]     systemInfo = (byte[])r.ExecuteTagOp(sysInfoOp, mulfilter);

                    // parsing the system info response
                    if (systemInfo.Length > 0)
                    {
                        parseGetSystemInfoResponse(systemInfo);
                    }
#endif

#if ENABLE_M3E_SECURE_ID
                    // Read secure id of tag. Address and length fields have no significance if memory type is SECURE_ID.
                    type    = MemoryType.SECURE_ID;
                    address = 0;
                    length  = 0;
                    ReadMemory secureIdOp = new ReadMemory(type, address, length);
                    byte[]     rspData    = (byte[])r.ExecuteTagOp(secureIdOp, mulfilter);

                    // parse secure id operation response.
                    if (rspData.Length > 0)
                    {
                        parseSecureIdResponse(rspData);
                    }
#endif

#if ENABLE_M3E_BLOCK_PROTECTION_STATUS
                    // Get the block protection status of block 0.
                    type    = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY;
                    address = 0;
                    length  = 1;
                    ReadMemory blkProtectionOp = new ReadMemory(type, address, length);
                    byte[]     statusData      = (byte[])r.ExecuteTagOp(blkProtectionOp, mulfilter);

                    // parse the block protection status response.
                    if (statusData.Length == length)
                    {
                        parseGetBlockProtectionStatusResponse(statusData, address, length);
                    }
#endif
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 != args.Length)
            {
                Console.WriteLine(String.Join("\r\n", new string[] {
                    "Please provide reader URL, such as:",
                    "tmr:///com4",
                    "tmr://my-reader.example.com",
                }));
                Environment.Exit(1);
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (Reader r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        else
                        {
                            r.ParamSet("/reader/region/id", supportedRegions[0]);
                        }
                    }

                    DenatranIAVCustomTagOperations denatranIavCustomTagOp = new DenatranIAVCustomTagOperations();

                    denatranIavCustomTagOp.reader = r;

                    #region Initialsettings
                    //Initial settings
                    //Set BLF 320KHZ
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine("Set BLF to 320KHZ");
                    r.ParamSet("/reader/gen2/blf", Gen2.LinkFrequency.LINK320KHZ);
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine();

                    //Set session
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine("Set session");
                    r.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine();

                    //Set target
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine("Set target");
                    r.ParamSet("/reader/gen2/target", Gen2.Target.AB);
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine();

                    //Set tari
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine("Set tari");
                    r.ParamSet("/reader/gen2/tari", Gen2.Tari.TARI_6_25US);
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine();

                    //Set tagencoding
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine("Set tagencoding");
                    r.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.FM0);
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine();

                    //Set Q
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine("Set Q");
                    Gen2.StaticQ staticQ = new Gen2.StaticQ(0);
                    r.ParamSet("/reader/gen2/q", staticQ);
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine();
                    #endregion Initialsettings

                    TagReadData[] tagReads;
                    // Read
                    tagReads = r.Read(500);

                    if (tagReads.Length == 0)
                    {
                        Console.WriteLine("Error : No tags found");
                    }
                    else
                    {
                        #region Filter initialization
                        //Gen2Select filter
                        Gen2.Select selectfilter = new Gen2.Select(false, Gen2.Bank.EPC, 32,
                                                                   (ushort)(tagReads[0].Epc.Length * 8), ByteFormat.FromHex(tagReads[0].EpcString));
                        //TagData filter
                        TagFilter tagdataFilter = new TagData(ByteFormat.FromHex(tagReads[0].EpcString));

                        #endregion Filter initialization

                        #region Tag Operation Initialization

                        byte   payload     = 0x80;
                        ushort readptr     = 0xFFFF;
                        ushort wordAddress = 0xFFFF;
                        ushort word        = 0xFFFF;
                        //Read ptr for readsec tagop
                        ushort readSecReadPtr = 0x0000;
                        //Set the tag Identification and writeCredentials
                        Gen2.DenatranIAVWriteCredential writeCredential = new Gen2.DenatranIAVWriteCredential
                                                                              (new byte [] { 0x80, 0x10, 0x00, 0x12, 0x34, 0xAD, 0xBD, 0xC0 },
                                                                              new byte [] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                        //Set the data and writeCredentials for WriteSec
                        Gen2.DenatranIAVWriteSecCredential writeSecCredential = new Gen2.DenatranIAVWriteSecCredential
                                                                                    (new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 },
                                                                                    new byte[] { 0x35, 0x49, 0x87, 0xbd, 0xb2, 0xab, 0xd2, 0x7c, 0x2e, 0x34, 0x78, 0x8b, 0xf2, 0xf7, 0x0b, 0xa2 });
                        //IAVDenatran secure tag operation - ActivateSecureMode
                        denatranIavCustomTagOp.tagOpActivateSecureMode = new Gen2.Denatran.IAV.ActivateSecureMode(payload);
                        //IAVDenatran secure tag operation - AuthenticateOBU
                        denatranIavCustomTagOp.tagOpAuthenticateOBU = new Gen2.Denatran.IAV.AuthenticateOBU(payload);
                        //IAVDenatran secure tag operation - ActivateSiniavMode
                        denatranIavCustomTagOp.tagOpActivateSiniavMode = new Gen2.Denatran.IAV.ActivateSiniavMode(0x81, new byte[] { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef });
                        //IAVDenatran secure tag operation - OBUAuthFullPass1
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass1 = new Gen2.Denatran.IAV.OBUAuthFullPass1(payload);
                        //IAVDenatran secure tag operation - OBUAuthFullPass2
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass2 = new Gen2.Denatran.IAV.OBUAuthFullPass2(payload);
                        //IAVDenatran secure tag operation - OBUAuthID
                        denatranIavCustomTagOp.tagOpOBUAuthID = new Gen2.Denatran.IAV.OBUAuthID(payload);
                        //IAVDenatran secure tag operation - OBUReadFromMemMap
                        denatranIavCustomTagOp.tagOpOBUReadFromMemMap = new Gen2.Denatran.IAV.OBUReadFromMemMap
                                                                            (payload, readptr);
                        //IAVDenatran secure tag operation - OBUWriteToMemMap
                        denatranIavCustomTagOp.tagOpOBUWriteToMemMap = new Gen2.Denatran.IAV.OBUWriteToMemMap
                                                                           (payload, wordAddress, word, writeCredential);
                        //IAVDenatran secure tag operation - OBUAuthFullPass
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass = new Gen2.Denatran.IAV.OBUAuthFullPass(payload);
                        //IAVDenatran secure tag operation - GetTokenId
                        denatranIavCustomTagOp.tagOpGetTokenId = new Gen2.Denatran.IAV.GetTokenId();
                        //IAVDenatran secure tag operation - ReadSec
                        denatranIavCustomTagOp.tagOpReadSec = new Gen2.Denatran.IAV.ReadSec
                                                                  (payload, readSecReadPtr);
                        //IAVDenatran secure tag operation - WriteSec
                        denatranIavCustomTagOp.tagOpWriteSec = new Gen2.Denatran.IAV.WriteSec
                                                                   (payload, writeSecCredential);
                        #endregion Tag Operation Initialization

                        #region Standalonetagoperations

                        //Standalone tagop
                        Console.WriteLine("Standalone tagop without filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(null);

                        Console.WriteLine("Standalone tagop with tagdata filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(tagdataFilter);

                        Console.WriteLine("Standalone tagop with gen2Select filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(selectfilter);

                        #endregion Standalonetagoperations

                        #region Embeddedtagoperations

                        //Embedded tagop
                        Console.WriteLine("Embedded tagop without filter and fastsearch : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(null, false);

                        Console.WriteLine("Embedded tagop with tagdata filter and fastsearch enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(tagdataFilter, true);

                        Console.WriteLine("Embedded tagop with gen2select filter and fast search enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(selectfilter, true);

                        #endregion Embeddedtagoperations
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
예제 #11
0
        /// <summary>
        /// Populate access password of the tag
        /// </summary>
        private void PopulateUntraceableData()
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                spUntraceableFields.IsEnabled = true;
                ResetUntraceableActionCheckBoxes();
                if ((bool)rbFirstTagUntraceableTb.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }

                objReader.ParamSet("/reader/tagop/antenna", antenna);


                if ((bool)rbSelectedTagUntraceableTb.IsChecked)
                {
                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(currentEPC);
                    }
                    else
                    {
                        int    dataLength       = 0;
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null != SearchSelectData)
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(accessPwddStartAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                }
                else
                {
                    searchSelect = new TagData(currentEPC);
                }

                //Read Reserved memory bank data
                TagOp    op;
                ushort[] reservedData = null;
                txtbxAccesspaasword.Text = "";
                try
                {
                    string reservedBankData = string.Empty;
                    //Read access password
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != reservedData)
                    {
                        reservedBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }

                    txtbxAccesspaasword.Text = reservedBankData.Trim(' ');
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }
            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }
            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (Reader r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    if (r.isAntDetectEnabled(antennaList))
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }
                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }

                    DenatranIAVCustomTagOperations denatranIavCustomTagOp = new DenatranIAVCustomTagOperations();

                    denatranIavCustomTagOp.reader = r;

                    #region EnablingGEN2DenatranIAVTagOps
                    // Serial reader condition is bypassed to add support for Network readers.
                    Console.WriteLine(String.Format("Get Protocol Extension : {0}", r.ParamGet("/reader/gen2/protocolExtension")));
                    Console.WriteLine();


                    #endregion

                    #region Initialsettings
                    //Initial settings
                    //Set tagencoding
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine("Set tagencoding");
                    r.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.FM0);
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine();

                    //Set BLF 320KHZ
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine("Set BLF to 320KHZ");
                    r.ParamSet("/reader/gen2/blf", Gen2.LinkFrequency.LINK320KHZ);
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine();

                    //Set tari
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine("Set tari");
                    r.ParamSet("/reader/gen2/tari", Gen2.Tari.TARI_6_25US);
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine();

                    //Set session
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine("Set session");
                    r.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine();

                    //Set target
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine("Set target");
                    r.ParamSet("/reader/gen2/target", Gen2.Target.AB);
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine();

                    //Set Q
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine("Set Q");
                    Gen2.StaticQ staticQ = new Gen2.StaticQ(0);
                    r.ParamSet("/reader/gen2/q", staticQ);
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine();
                    #endregion Initialsettings

                    TagReadData[] tagReads;
                    // Read
                    tagReads = r.Read(500);

                    if (tagReads.Length == 0)
                    {
                        Console.WriteLine("Error : No tags found");
                    }
                    else
                    {
                        #region Filter initialization
                        //Gen2Select filter
                        Gen2.Select selectfilter = new Gen2.Select(false, Gen2.Bank.EPC, 32,
                                                                   (ushort)(tagReads[0].Epc.Length * 8), ByteFormat.FromHex(tagReads[0].EpcString));
                        //TagData filter
                        TagFilter tagdataFilter = new TagData(ByteFormat.FromHex(tagReads[0].EpcString));

                        #endregion Filter initialization

                        #region Tag Operation Initialization

                        byte   payload          = 0x80;
                        byte   OBUAuthID        = 0x00;
                        byte   OBUAuthFullPass  = 0x01;
                        byte   OBUAuthFullPass1 = 0x02;
                        ushort readptr          = 0xFFFF;
                        ushort wordAddress      = 0xFFFF;
                        ushort word             = 0xFFFF;
                        //Read ptr for readsec tagop
                        ushort readSecReadPtr = 0x0000;
                        //Set the tag Identification and writeCredentials
                        Gen2.DenatranIAVWriteCredential writeCredential = new Gen2.DenatranIAVWriteCredential
                                                                              (new byte [] { 0x80, 0x10, 0x00, 0x12, 0x34, 0xAD, 0xBD, 0xC0 },
                                                                              new byte [] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                        //Set the data and writeCredentials for WriteSec
                        Gen2.DenatranIAVWriteSecCredential writeSecCredential = new Gen2.DenatranIAVWriteSecCredential
                                                                                    (new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 },
                                                                                    new byte[] { 0x35, 0x49, 0x87, 0xbd, 0xb2, 0xab, 0xd2, 0x7c, 0x2e, 0x34, 0x78, 0x8b, 0xf2, 0xf7, 0x0b, 0xa2 });
                        //IAVDenatran secure tag operation - ActivateSecureMode
                        denatranIavCustomTagOp.tagOpActivateSecureMode = new Gen2.Denatran.IAV.ActivateSecureMode(payload);
                        //IAVDenatran secure tag operation - AuthenticateOBU
                        denatranIavCustomTagOp.tagOpAuthenticateOBU = new Gen2.Denatran.IAV.AuthenticateOBU(payload);
                        //IAVDenatran secure tag operation - ActivateSiniavMode
                        denatranIavCustomTagOp.tagOpActivateSiniavMode = new Gen2.Denatran.IAV.ActivateSiniavMode(0x81, new byte[] { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef });
                        //IAVDenatran secure tag operation - OBUAuthFullPass1
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass1 = new Gen2.Denatran.IAV.OBUAuthFullPass1(payload);
                        //IAVDenatran secure tag operation - OBUAuthFullPass2
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass2 = new Gen2.Denatran.IAV.OBUAuthFullPass2(payload);
                        //IAVDenatran secure tag operation - OBUAuthID
                        denatranIavCustomTagOp.tagOpOBUAuthID = new Gen2.Denatran.IAV.OBUAuthID(payload);
                        //IAVDenatran secure tag operation - OBUReadFromMemMap
                        denatranIavCustomTagOp.tagOpOBUReadFromMemMap = new Gen2.Denatran.IAV.OBUReadFromMemMap
                                                                            (payload, readptr);
                        //IAVDenatran secure tag operation - OBUWriteToMemMap
                        denatranIavCustomTagOp.tagOpOBUWriteToMemMap = new Gen2.Denatran.IAV.OBUWriteToMemMap
                                                                           (payload, wordAddress, word, writeCredential);
                        //IAVDenatran secure tag operation - OBUAuthFullPass
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass = new Gen2.Denatran.IAV.OBUAuthFullPass(payload);
                        //IAVDenatran secure tag operation - GetTokenId
                        denatranIavCustomTagOp.tagOpGetTokenId = new Gen2.Denatran.IAV.GetTokenId();
                        //IAVDenatran secure tag operation - ReadSec
                        denatranIavCustomTagOp.tagOpReadSec = new Gen2.Denatran.IAV.ReadSec
                                                                  (payload, readSecReadPtr);
                        //IAVDenatran secure tag operation - WriteSec
                        denatranIavCustomTagOp.tagOpWriteSec = new Gen2.Denatran.IAV.WriteSec
                                                                   (payload, writeSecCredential);

                        // For G0 Tag
                        denatranIavCustomTagOp.tagOpG0PAOBUAuth          = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthID));
                        denatranIavCustomTagOp.tagOpG0PAOBUAuthFullPass  = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthFullPass));
                        denatranIavCustomTagOp.tagOpG0PAOBUAuthFullPass1 = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthFullPass1));
                        //Uncomment this  for PA tag
                        //denatranIavCustomTagOp.tagOpG0PAOBUAuth = new Gen2.Denatran.IAV.G0PAOBUAuth(payload);

                        #endregion Tag Operation Initialization

                        #region Standalonetagoperations

                        //Standalone tagop
                        Console.WriteLine("Standalone tagop without filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(null);

                        Console.WriteLine("Standalone tagop with tagdata filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(tagdataFilter);

                        Console.WriteLine("Standalone tagop with gen2Select filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(selectfilter);

                        #endregion Standalonetagoperations

                        #region Embeddedtagoperations

                        //Embedded tagop
                        Console.WriteLine("Embedded tagop without filter and fastsearch : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(null, false);

                        Console.WriteLine("Embedded tagop with tagdata filter and fastsearch enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(tagdataFilter, true);

                        Console.WriteLine("Embedded tagop with gen2select filter and fast search enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(selectfilter, true);

                        #endregion Embeddedtagoperations
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
예제 #13
0
        LongTaskExtInfo ParseLongTask()
        {
            LongTaskExtInfo lteinfo = new LongTaskExtInfo();
            List <LongTaskExtInfo.LT_PotlConf> potls = new List <LongTaskExtInfo.LT_PotlConf>();

            if (cbistagopgen2.Checked)
            {
                LongTaskExtInfo.LT_PotlConf gen2potl = new LongTaskExtInfo.LT_PotlConf();
                gen2potl.Potl = TagProtocol.GEN2;

                if (cbistagop6b.Checked)
                {
                    if (tbgen2tagopweight.Text.Trim() == string.Empty || tb6btagopweight.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请协议权重");
                        return(null);
                    }
                    gen2potl.Weight = byte.Parse(tbgen2tagopweight.Text.Trim());
                }

                if (cbisgen2tagopreadbank.Checked)
                {
                    if (cbbgen2tagopbank.SelectedIndex == -1)
                    {
                        MessageBox.Show("请选择gen2标签读哪个bank");
                        return(null);
                    }
                    if (tbgen2tagopaddr.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入gen2标签bank起始地址");
                        return(null);
                    }
                    if (tbgen2tagopblkcnt.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入gen2标签读块数");
                        return(null);
                    }
                    if (cbbgen2tagopbankreadmode.SelectedIndex == -1)
                    {
                        MessageBox.Show("请输入gen2标签bank读取模式");
                        return(null);
                    }
                    gen2potl.Address = UInt16.Parse(tbgen2tagopaddr.Text.Trim());
                    gen2potl.Bank    = (byte)(cbbgen2tagopbank.SelectedIndex + 1);
                    gen2potl.Blkcnt  = byte.Parse(tbgen2tagopblkcnt.Text.Trim());
                    gen2potl.Brmode  = (LongTaskExtInfo.LT_PotlConf.BankReadMode)(cbbgen2tagopbankreadmode.SelectedIndex + 1);
                    gen2potl.Optype  = LongTaskExtInfo.LT_PotlConf.LTTAGOPEXTType.LTTAGOPEXTType_InventoryAndReadBank;
                }
                else
                {
                    gen2potl.Optype = LongTaskExtInfo.LT_PotlConf.LTTAGOPEXTType.LTTAGOPEXTType_Inventory;
                }
                potls.Add(gen2potl);
            }
            if (cbistagop6b.Checked)
            {
                LongTaskExtInfo.LT_PotlConf iso183k6bpotl = new LongTaskExtInfo.LT_PotlConf();
                iso183k6bpotl.Potl = TagProtocol.ISO180006B;
                if (cbistagopgen2.Checked)
                {
                    iso183k6bpotl.Weight = byte.Parse(tb6btagopweight.Text.Trim());
                }

                if (cbis6btagopreadmem.Checked)
                {
                    if (tb6btagopaddr.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入6b标签bank起始地址");
                        return(null);
                    }
                    if (tb6btagopblkcnt.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入6b标签读块数");
                        return(null);
                    }
                    iso183k6bpotl.Address = UInt16.Parse(tb6btagopaddr.Text.Trim());
                    iso183k6bpotl.Blkcnt  = byte.Parse(tb6btagopblkcnt.Text.Trim());
                    iso183k6bpotl.Optype  = LongTaskExtInfo.LT_PotlConf.LTTAGOPEXTType.LTTAGOPEXTType_InventoryAndReadBank;
                }
                else
                {
                    iso183k6bpotl.Optype = LongTaskExtInfo.LT_PotlConf.LTTAGOPEXTType.LTTAGOPEXTType_Inventory;
                }
                potls.Add(iso183k6bpotl);
            }

            if (tbmaxepclen.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入最大epc长度");
                return(null);
            }
            lteinfo.MaxEpcLen = int.Parse(tbmaxepclen.Text.Trim());
            lteinfo.PotlConf  = potls.ToArray();
            if (!(cbisant1.Checked || cbisant2.Checked || cbisant3.Checked || cbisant4.Checked))
            {
                MessageBox.Show("请至少选择一个天线");
                return(null);
            }
            List <int> ants = new List <int>();

            if (cbisant1.Checked)
            {
                ants.Add(1);
            }
            if (cbisant2.Checked)
            {
                ants.Add(2);
            }
            if (cbisant3.Checked)
            {
                ants.Add(3);
            }
            if (cbisant4.Checked)
            {
                ants.Add(4);
            }
            lteinfo.OpAnts = ants.ToArray();
            if (tbreaddur.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入盘存周期");
                return(null);
            }
            lteinfo.InvDur = int.Parse(tbreaddur.Text.Trim());

            if (tbsleepdur.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入盘存间隔");
                return(null);
            }
            lteinfo.InvInterval = int.Parse(tbsleepdur.Text.Trim());

            if (cbisrevertants.Checked)
            {
                lteinfo.IsRevertAnts = true;
            }
            else
            {
                lteinfo.IsRevertAnts = false;
            }

            if (cbisantjudge.Checked)
            {
                if (!(rbantjudalgafttaglv.Checked || rbantjudalgbydur.Checked))
                {
                    MessageBox.Show("请选择天线判决算法");
                    return(null);
                }
                lteinfo.EnableAntJudgeAlgorithm = true;
                LongTaskExtInfo.AntJudgeConf ajc = new LongTaskExtInfo.AntJudgeConf();
                if (rbantjudalgafttaglv.Checked)
                {
                    ajc.AntJudgeAlg =
                        LongTaskExtInfo.AntJudgeConf.AntJudgeAlgorithm.AntJudgeAlgorithm_AfterTagLeave;
                    if (tbantdugaftwaitdur.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入等待时间");
                        return(null);
                    }
                    if (tbantjudafttimeout.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入超时时间");
                        return(null);
                    }
                    ajc.TimeDurAftTagLeaveJudge = int.Parse(tbantdugaftwaitdur.Text.Trim());
                    ajc.TimeoutAftTagLeaveJudge = int.Parse(tbantjudafttimeout.Text.Trim());
                }
                else
                {
                    ajc.AntJudgeAlg =
                        LongTaskExtInfo.AntJudgeConf.AntJudgeAlgorithm.AntJudgeAlgorithm_EachDuration;
                    if (tbantjudcycle.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入判决周期");
                        return(null);
                    }
                    ajc.AntJudgeCycle = int.Parse(tbantjudcycle.Text.Trim());
                }
                lteinfo.AntJudgeAlgConf = ajc;
            }
            else
            {
                lteinfo.EnableAntJudgeAlgorithm = false;
            }
            lteinfo.IsTriggerByGpi = false;
            lteinfo.IsDriveGpo     = false;
            if (cbisackbysid.Checked)
            {
                lteinfo.IsAckBySerialNum = true;
            }
            else
            {
                lteinfo.IsAckBySerialNum = false;
            }

            if (tbrtuploadip.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入实时数据上传地址");
                return(null);
            }
            if (tbrtuploadport.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入实时数据上传端口");
                return(null);
            }
            if (tboluploadip.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入离线数据上传地址");
                return(null);
            }
            if (tboluploadport.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入离线数据上传端口");
                return(null);
            }
            if (tbmaxtagbuffercnt.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入最大缓存数据量");
                return(null);
            }
            if (cbbuploadmode.SelectedIndex == -1)
            {
                MessageBox.Show("请选择数据上传模式");
                return(null);
            }
            if (cbbtcpmode.SelectedIndex == -1)
            {
                MessageBox.Show("请选择TCP连接模式");
                return(null);
            }
            lteinfo.RealTimeUploadIp       = tbrtuploadip.Text.Trim();
            lteinfo.RealTimeUploadPort     = int.Parse(tbrtuploadport.Text.Trim());
            lteinfo.OfflineUploadIp        = tboluploadip.Text.Trim();
            lteinfo.OfflineUploadPort      = int.Parse(tboluploadport.Text.Trim());
            lteinfo.MaxOfflineTagBufferCnt = int.Parse(tbmaxtagbuffercnt.Text.Trim());
            lteinfo.UploadTagMode          = (LongTaskExtInfo.UploadDataMode)(cbbuploadmode.SelectedIndex + 1);
            lteinfo.TcpCnnMode             = (LongTaskExtInfo.TcpConnectionMode)(cbbtcpmode.SelectedIndex + 1);

            if (tbgen2tagoppwd.Text.Trim() == string.Empty)
            {
                lteinfo.AccessPassword = (uint)0;
            }
            else
            {
                byte[] tmp = ByteFormat.FromHex(tbgen2tagoppwd.Text.Trim());
                lteinfo.AccessPassword = (uint)((tmp[0] << 24) | (tmp[1] << 16) | (tmp[2] << 8) | tmp[3]);
            }

            if (cbisjaml0.Checked)
            {
                lteinfo.IsChanPowerWhenJamLevel0 = true;
                if (this.tbjaml0crtime.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别0连续读到时间");
                    return(null);
                }
                lteinfo.TrafficJamLevel0ReadTime = UInt16.Parse(this.tbjaml0crtime.Text.Trim());
                if (this.tbl0gen2ant1pwr.Text.Trim() == string.Empty || this.tbl0gen2ant2pwr.Text.Trim() == string.Empty ||
                    this.tbl0gen2ant3pwr.Text.Trim() == string.Empty || this.tbl0gen2ant4pwr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别0gen2功率");
                    return(null);
                }
                if (this.tbl06bant1pwr.Text.Trim() == string.Empty || this.tbl06bant2pwr.Text.Trim() == string.Empty ||
                    this.tbl06bant3pwr.Text.Trim() == string.Empty || this.tbl06bant4pwr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别06b功率");
                    return(null);
                }

                lteinfo.TrafficJamLevel0Gen2Pwr    = new UInt16[4];
                lteinfo.TrafficJamLevel0Gen2Pwr[0] = UInt16.Parse(this.tbl0gen2ant1pwr.Text.Trim());
                lteinfo.TrafficJamLevel0Gen2Pwr[1] = UInt16.Parse(this.tbl0gen2ant2pwr.Text.Trim());
                lteinfo.TrafficJamLevel0Gen2Pwr[2] = UInt16.Parse(this.tbl0gen2ant3pwr.Text.Trim());
                lteinfo.TrafficJamLevel0Gen2Pwr[3] = UInt16.Parse(this.tbl0gen2ant4pwr.Text.Trim());

                lteinfo.TrafficJamLevel06BPwr    = new UInt16[4];
                lteinfo.TrafficJamLevel06BPwr[0] = UInt16.Parse(this.tbl06bant1pwr.Text.Trim());
                lteinfo.TrafficJamLevel06BPwr[1] = UInt16.Parse(this.tbl06bant2pwr.Text.Trim());
                lteinfo.TrafficJamLevel06BPwr[2] = UInt16.Parse(this.tbl06bant3pwr.Text.Trim());
                lteinfo.TrafficJamLevel06BPwr[3] = UInt16.Parse(this.tbl06bant4pwr.Text.Trim());
            }
            else
            {
                lteinfo.IsChanPowerWhenJamLevel0 = false;
            }

            if (cbisjaml1.Checked)
            {
                lteinfo.IsChanPowerWhenJamLevel1 = true;
                if (this.tbjaml1crtime.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别1连续读到时间");
                    return(null);
                }
                lteinfo.TrafficJamLevel1ReadTime = UInt16.Parse(this.tbjaml1crtime.Text.Trim());
                if (this.tbl1gen2ant1pwr.Text.Trim() == string.Empty || this.tbl1gen2ant2pwr.Text.Trim() == string.Empty ||
                    this.tbl1gen2ant3pwr.Text.Trim() == string.Empty || this.tbl1gen2ant4pwr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别1gen2功率");
                    return(null);
                }
                if (this.tbl16bant1pwr.Text.Trim() == string.Empty || this.tbl16bant2pwr.Text.Trim() == string.Empty ||
                    this.tbl16bant3pwr.Text.Trim() == string.Empty || this.tbl16bant4pwr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("请输入阻塞级别16b功率");
                    return(null);
                }
                if (lteinfo.TrafficJamLevel1ReadTime <= lteinfo.TrafficJamLevel0ReadTime)
                {
                    MessageBox.Show("阻塞级别1连续读取时间必须大于阻塞级别0连续读取时间");
                    return(null);
                }

                lteinfo.TrafficJamLevel1Gen2Pwr    = new UInt16[4];
                lteinfo.TrafficJamLevel1Gen2Pwr[0] = UInt16.Parse(this.tbl1gen2ant1pwr.Text.Trim());
                lteinfo.TrafficJamLevel1Gen2Pwr[1] = UInt16.Parse(this.tbl1gen2ant2pwr.Text.Trim());
                lteinfo.TrafficJamLevel1Gen2Pwr[2] = UInt16.Parse(this.tbl1gen2ant3pwr.Text.Trim());
                lteinfo.TrafficJamLevel1Gen2Pwr[3] = UInt16.Parse(this.tbl1gen2ant4pwr.Text.Trim());

                lteinfo.TrafficJamLevel16BPwr    = new UInt16[4];
                lteinfo.TrafficJamLevel16BPwr[0] = UInt16.Parse(this.tbl16bant1pwr.Text.Trim());
                lteinfo.TrafficJamLevel16BPwr[1] = UInt16.Parse(this.tbl16bant2pwr.Text.Trim());
                lteinfo.TrafficJamLevel16BPwr[2] = UInt16.Parse(this.tbl16bant3pwr.Text.Trim());
                lteinfo.TrafficJamLevel16BPwr[3] = UInt16.Parse(this.tbl16bant4pwr.Text.Trim());
            }
            else
            {
                lteinfo.IsChanPowerWhenJamLevel1 = false;
            }

            return(lteinfo);
        }
예제 #14
0
        private void btnsetimpinjqt_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("请选择操作天线");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            byte[] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("访问密码不能为空");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("访问密码必须是8个16进制数");
                    break;

                case -1:
                    MessageBox.Show("访问密码只能是16进制数字");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }

            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }

            if ((!this.rbimpinjqtread.Checked) && (!this.rbimpinjwrite.Checked))
            {
                MessageBox.Show("请选择命令类型");
                return;
            }

            try
            {
                if (this.rbimpinjqtread.Checked)
                {
                    IMPINJ_M4_QtPara para = new IMPINJ_M4_QtPara(pwd);

                    IMPINJ_M4_QtResult qtret = (IMPINJ_M4_QtResult)mrdr.CustomCmd(filter, CustomCmdType.IMPINJ_M4_Qt, para);
                    if (qtret.MemType == IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Private)
                    {
                        this.rbimpinjqtmemprivate.Checked = true;
                    }
                    else
                    {
                        this.rbimpinjqtmempublic.Checked = true;
                    }
                    if (qtret.RangeType == IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_FarField)
                    {
                        this.rbimpinjqtfarfield.Checked = true;
                    }
                    else
                    {
                        this.rbimpinjqtnearfiled.Checked = true;
                    }
                }
                else
                {
                    if ((!rbimpinjqtnearfiled.Checked) && (!rbimpinjqtfarfield.Checked))
                    {
                        MessageBox.Show("请选择识别距离");
                        return;
                    }
                    if ((!rbimpinjqtmemprivate.Checked) && (!rbimpinjqtmempublic.Checked))
                    {
                        MessageBox.Show("请选择内存视图");
                        return;
                    }
                    if ((!rbimpinjqtperm.Checked) && (!rbimpinjqttemp.Checked))
                    {
                        MessageBox.Show("请选择状态类型");
                        return;
                    }

                    IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type   trange   = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_Invalid;
                    IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Invalid;
                    IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type     tmem     = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Invalid;

                    if (rbimpinjqtnearfiled.Checked)
                    {
                        trange = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_NearField;
                    }
                    else
                    {
                        trange = IMPINJ_M4_QtPara.IMPINJ_Qt_Range_Type.IMPINJ_Qt_Range_FarField;
                    }
                    if (rbimpinjqtmemprivate.Checked)
                    {
                        tmem = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Private;
                    }
                    else
                    {
                        tmem = IMPINJ_M4_QtPara.IMPINJ_Qt_Mem_Type.IMPINJ_Qt_Mem_Public;
                    }
                    if (rbimpinjqtperm.Checked)
                    {
                        tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Perm;
                    }
                    else
                    {
                        tpersist = IMPINJ_M4_QtPara.IMPINJ_Qt_Persist_Type.IMPINJ_Qt_Persist_Temp;
                    }

                    IMPINJ_M4_QtPara para = new IMPINJ_M4_QtPara(pwd, tpersist, trange, tmem);
                    mrdr.CustomCmd(filter, CustomCmdType.IMPINJ_M4_Qt, para);
                }
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("没法发现标签");
                }
                else
                {
                    MessageBox.Show("操作失败:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("操作失败:" + ex.ToString());
                return;
            }
        }
예제 #15
0
        private void btnResetReadProtect_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("请选择操作天线");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            byte[] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("访问密码不能为空");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("访问密码必须是8个16进制数");
                    break;

                case -1:
                    MessageBox.Show("访问密码只能是16进制数字");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }

            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }

            try
            {
                NXP_ResetReadProtectPara para = new NXP_ResetReadProtectPara(pwd);
                mrdr.CustomCmd(filter, CustomCmdType.NXP_ResetReadProtect, para);
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("没法发现标签");
                }
                else
                {
                    MessageBox.Show("操作失败:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("操作失败:" + ex.ToString());
                return;
            }
        }
예제 #16
0
        /// <summary>
        /// Authenticate with key1
        /// </summary>
        private void btnAuthKeyOne_Click(object sender, RoutedEventArgs e)
        {
            Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key1, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";
            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyOne.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyOne.Text);
                Key1 = new ushort[KeytoWrite.Length / 2];
                Key1 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key1", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);

            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);

                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge                  = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblDataValue.Content       = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Auth with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Readbuffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                }
                else
                {
                    //Authenticate with tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    Response = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    if (Response != null)
                    {
                        lblTam2DataValue.Content = ByteFormat.ToHex(Response, "", " ");
                    }
                    lblTam2DataValue.Content = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                returnedIchallenge = new ushort[Challenge.Length / 2];
                returnedIchallenge = ByteConv.ToU16s(Challenge);
                if (returnedIchallenge.SequenceEqual(Ichallenge))
                {
                    MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
예제 #17
0
        private void PopulateData()
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);

                // Create the object to read tag memory
                ReadTagMemory readTagMem = new ReadTagMemory(objReader, model);

                if ((bool)rbFirstTagIns.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }

                objReader.ParamSet("/reader/tagop/antenna", antenna);
                TagFilter searchSelect = null;

                if ((bool)rbSelectedTagIns.IsChecked)
                {
                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(currentEPC);
                    }
                    else
                    {
                        int    dataLength       = 0;
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null != SearchSelectData)
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                }
                else
                {
                    searchSelect = new TagData(currentEPC);
                }

                #region ReadReservedMemory

                //Read Reserved memory bank data
                ushort[] reservedData = null;

                txtKillPassword.Text           = "";
                txtAcessPassword.Text          = "";
                txtReservedMemUnusedValue.Text = "";
                // Hide additional memory textboxes
                lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;

                try
                {
                    readTagMem.ReadTagMemoryData(Gen2.Bank.RESERVED, searchSelect, ref reservedData);
                    // Parse the response to get access pwd, kill pwd and if additional memory exists
                    ParseReservedMemData(reservedData);
                }
                catch (Exception ex)
                {
                    // Hide additional memory textboxes
                    lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                    txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                    lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;
                    txtReservedMemUnusedValue.Text         = "";
                    // If either of the memory is locked get in or else throw the exception.
                    if ((ex is FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception) || (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception))
                    {
                        try
                        {
                            ReadReservedMemData(Gen2.Bank.RESERVED, searchSelect);
                        }
                        catch (Exception e)
                        {
                            txtKillPassword.Text  = e.Message;
                            txtAcessPassword.Text = e.Message;
                        }
                    }
                    else if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtKillPassword.Text  = "Read Error";
                        txtAcessPassword.Text = "Read Error";
                    }
                    else
                    {
                        txtKillPassword.Text  = ex.Message;
                        txtAcessPassword.Text = ex.Message;
                    }
                }
                #endregion ReadReservedMemory

                #region ReadEPCMemory
                //Read EPC bank data
                ushort[] epcData = null;

                txtPC.Text                 = "";
                txtCRC.Text                = "";
                txtEPCData.Text            = "";
                txtEPCValue.Text           = "";
                txtEPCUnused.Text          = "";
                txtEPCUnusedValue.Text     = "";
                txtadditionalMemValue.Text = "";

                // Hide additional memory
                spUnused.Visibility    = System.Windows.Visibility.Collapsed;
                spXPC.Visibility       = System.Windows.Visibility.Collapsed;
                spXPC2.Visibility      = System.Windows.Visibility.Collapsed;
                spAddMemory.Visibility = System.Windows.Visibility.Collapsed;

                try
                {
                    readTagMem.ReadTagMemoryData(Gen2.Bank.EPC, searchSelect, ref epcData);
                    ParseEPCMemData(epcData, searchSelect);
                }
                catch (Exception ex)
                {
                    txtEPCData.Text       = ex.Message;
                    rbEPCAscii.IsEnabled  = false;
                    rbEPCBase36.IsEnabled = false;
                }
                #endregion ReadEPCMemory

                #region ReadTIDMemory
                //Read TID bank data
                ushort[] tidData = null;

                txtClsID.Text         = "";
                txtVendorID.Text      = "";
                txtVendorValue.Text   = "";
                txtModelID.Text       = "";
                txtModeldIDValue.Text = "";
                txtUniqueIDValue.Text = "";

                try
                {
                    readTagMem.ReadTagMemoryData(Gen2.Bank.TID, searchSelect, ref tidData);
                    ParseTIDMemData(tidData);
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtUniqueIDValue.Text = "Read Error";
                    }
                    else
                    {
                        txtUniqueIDValue.Text = ex.Message;
                    }
                }
                #endregion ReadTIDMemory

                #region ReadUserMemory
                //Read USER bank data
                ushort[] userMemData = null;

                txtUserDataValue.Text = "";
                txtUserMemData.Text   = "";

                try
                {
                    readTagMem.ReadTagMemoryData(Gen2.Bank.USER, searchSelect, ref userMemData);
                    ParseUserMemData(userMemData);
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtUserMemData.Text = "Read Error";
                    }
                    else
                    {
                        txtUserMemData.Text = ex.Message;
                    }
                }
                #endregion ReadUserMemory
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
예제 #18
0
        private void btnipset_Click(object sender, EventArgs e)
        {
            if (this.tbipaddr.Text.Trim() == string.Empty || this.tbsubnet.Text.Trim() == string.Empty ||
                this.tbgateway.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input the related items of IP");
                return;
            }
            ReaderIPInfo ipinfo = null;

            try
            {
                ipinfo = ReaderIPInfo.Create(this.tbipaddr.Text.Trim(), this.tbsubnet.Text.Trim(),
                                             this.tbgateway.Text.Trim());
                if (this.cbmacset.Checked)
                {
                    if (this.tbMacAddr.Text.Trim().Length != 12)
                    {
                        MessageBox.Show("invalid MAC address format");
                        return;
                    }
                    else
                    {
                        try
                        {
                            byte[] macb = ByteFormat.FromHex(this.tbMacAddr.Text.Trim());
                            ipinfo.MACADDR = macb;
                        }
                        catch
                        {
                            MessageBox.Show("invalid MAC address format");
                            return;
                        }
                    }
                }
            }
            catch (OpFaidedException exp)
            {
                MessageBox.Show("invalid ip address:" + exp.ToString());
                return;
            }

            if (rdr.HwDetails.board == Reader.MaindBoard_Type.MAINBOARD_ARM9_WIFI)
            {
                if ((!this.rbnettypewifi.Checked) && (!this.rbnettypeeth.Checked))
                {
                    MessageBox.Show("please select using ethernet or wifi");
                    return;
                }

                ReaderIPInfo_Ex.NetType     type = ReaderIPInfo_Ex.NetType.NetType_None;
                ReaderIPInfo_Ex.WifiSetting wifi = null;
                if (this.rbnettypewifi.Checked)
                {
                    if (this.cbbwifiauth.SelectedIndex == -1 || this.tbwifissid.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("please input related items of wifi");
                        return;
                    }

                    ReaderIPInfo_Ex.WifiSetting.AuthMode auth = (ReaderIPInfo_Ex.WifiSetting.AuthMode)(this.cbbwifiauth.SelectedIndex + 1);

                    if (this.cbbwifiauth.SelectedIndex == 0)
                    {
                        wifi = new ReaderIPInfo_Ex.WifiSetting(auth, this.tbwifissid.Text.Trim(),
                                                               ReaderIPInfo_Ex.WifiSetting.KeyType.KeyType_NONE, null);
                    }
                    else
                    {
                        if (this.tbwifikey.Text.Trim() == string.Empty || this.cbbkeytype.SelectedIndex == -1)
                        {
                            MessageBox.Show("please input related items of wifi");
                            return;
                        }
                        if (this.cbbwifiauth.SelectedIndex == 3 || this.cbbwifiauth.SelectedIndex == 4)
                        {
                            if (this.cbbkeytype.SelectedIndex == 1)
                            {
                                MessageBox.Show("secret key type must be ASC2 code");
                                return;
                            }
                        }

                        wifi = new ReaderIPInfo_Ex.WifiSetting(auth, this.tbwifissid.Text.Trim(),
                                                               (ReaderIPInfo_Ex.WifiSetting.KeyType)(this.cbbkeytype.SelectedIndex + 1),
                                                               this.tbwifikey.Text.Trim());
                    }

                    type = ReaderIPInfo_Ex.NetType.NetType_Wifi;
                }
                else
                {
                    type = ReaderIPInfo_Ex.NetType.NetType_Ethernet;
                }

                ReaderIPInfo_Ex ininfoex = new ReaderIPInfo_Ex(ipinfo, type, wifi);
                try
                {
                    rdr.ParamSet("IPAddressEx", ininfoex);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("setting failed:" + ex.ToString());
                }
            }
            else
            {
                try
                {
                    rdr.ParamSet("IPAddress", ipinfo);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("setting failed:" + ex.ToString());
                }
            }

            MessageBox.Show("ip setting success,please reconnect reader");
        }
예제 #19
0
 private void autoAcqData_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (rdr != null)
     {
         try
         {
             tagMutex.WaitOne();
             byte[]        binaryStr = ByteFormat.FromHex(curEPC);
             Gen2TagFilter filter    = new Gen2TagFilter(ByteFormat.FromHex(curEPC), ModuleTech.Gen2.MemBank.EPC, 32, false);
             rdr.ParamSet("Singulation", filter);
             for (int i = 0; i < readCount; i++)
             {
                 TagReadData[] tempData = rdr.Read(200);
                 if (tempData.Length != 0)
                 {
                     tagMutex.ReleaseMutex();
                     return;
                 }
             }
             if (meb != null)
             {
                 initialAllInfo();
             }
             rdr.ParamSet("Singulation", null);
             EmbededCmdData ecd = new EmbededCmdData(MemBank.TID, TIDStart, TIDEnd);
             rdr.ParamSet("EmbededCmdOfInventory", ecd);
             for (int i = 0; i < readCount; i++)
             {
                 TagReadData[] tagDatas = rdr.Read(200);
                 if (tagDatas.Length != 0)
                 {
                     foreach (TagReadData tag in tagDatas)
                     {
                         bool isRead = false;
                         foreach (tagInfo temp in tagList)
                         {
                             if (temp.epcid == tag.EPCString)
                             {
                                 isRead = true;
                             }
                         }
                         if (!isRead)
                         {
                             updateTagData(tag);
                         }
                     }
                 }
             }
             if (meb != null)
             {
                 refreshDataView();
                 if (!sendDataToUser())
                 {
                     MessageBox.Show("发送失败");
                 }
                 else
                 {
                     MessageBox.Show("发送成功,用户可以通过!");
                 }
             }
             tagMutex.ReleaseMutex();
             //autoAcq.Enabled = false;
         }
         catch (OpFaidedException exxx)
         {
             //MessageBox.Show("read wrong");
         }
     }
 }
예제 #20
0
        private void ReadtheTags()
        {
            try
            {
                // Make sure reader is connected
                ReadMgr.GetReader();

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

                if (btnStartReads.Text == "Start Reads")
                {
                    Cursor.Current = Cursors.WaitCursor;
                    try
                    {
                        //Check the battery power level
                        if (CoreDLL.GetSystemPowerStatusEx(status, false) == 1)
                        {
                            if (status.BatteryLifePercent <= 5)
                            {
                                if (status.ACLineStatus == 0)
                                {
                                    MessageBox.Show("Battery level is low to read tags");
                                    return;
                                }
                            }
                        }
                        properties["isreading"] = "yes";
                        Utilities.SaveConfigurations(properties);

                        //disable read power coverage
                        tbTXPower.Enabled = false;

                        ReadMgr.GetReader().ParamSet("/reader/transportTimeout", 2000);
                        int powerLevel = Convert.ToInt32(properties["readpower"]);
                        ReadMgr.GetReader().ParamSet("/reader/radio/readPower", powerLevel);
                        Utilities.SwitchRegion(properties["region"]);
                        ReadMgr.GetReader().ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 1, 1, 1 } });
                        ant.Add(1);
                        SimpleReadPlan plan = new SimpleReadPlan(ant.ToArray(), TagProtocol.GEN2);
                        ReadMgr.GetReader().ParamSet("/reader/read/plan", plan);
                        //int readPower = Convert.ToInt32(properties["readpower"].ToString()) * 100;
                        //tbTXPower.Value = (readPower - 1000) / 50;

                        tmrBackLightControl.Enabled = true;
                        miGoToMain.Enabled          = false;

                        //set properties
                        ReadMgr.GetReader().ParamSet("/reader/read/asyncOffTime", 50);
                        ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.FULL);

                        //set the tag population settings
                        ReadMgr.GetReader().ParamSet("/reader/gen2/target", Gen2.Target.A);//default target
                        string tagPopulation = properties["tagpopulation"];
                        switch (tagPopulation)
                        {
                        case "small":
                            ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(2));
                            ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S0);
                            ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                            break;

                        case "medium":
                            ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(4));
                            ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S1);
                            ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                            break;

                        case "large":
                            ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(6));
                            ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S1);
                            ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M2);
                            break;

                        default: break;
                        }

                        if (null != properties)
                        {
                            Utilities.SetReaderSettings(ReadMgr.GetReader(), properties);
                        }
                        else
                        {
                            MessageBox.Show("properties are null");
                        }
                        //set the read plan and filter
                        TagFilter filter;
                        int       addressToRead = int.Parse(properties["selectionaddress"]);
                        Gen2.Bank bank          = Gen2.Bank.EPC;
                        switch (properties["tagselection"].ToLower())
                        {
                        case "None":
                        case "epc": bank = Gen2.Bank.EPC; break;

                        case "tid": bank = Gen2.Bank.TID; break;

                        case "user": bank = Gen2.Bank.USER; break;

                        case "reserved": bank = Gen2.Bank.RESERVED; break;

                        default: break;
                        }
                        if ("yes" == properties["ismaskselected"])
                        {
                            filter = new Gen2.Select(true, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                        }
                        else
                        {
                            filter = new Gen2.Select(false, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                        }

                        SimpleReadPlan srp;
                        if (properties["tagselection"].ToLower() == "none")
                        {
                            srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, null, 0);
                        }
                        else
                        {
                            srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, filter, 0);
                        }
                        ReadMgr.GetReader().ParamSet("/reader/read/plan", srp);

                        btnStartReads.Text = "Stop Reads";
                        setStatus("Reading", System.Drawing.Color.DarkGoldenrod);
                        ReadMgr.GetReader().ReadException += ReadException;
                        ReadMgr.GetReader().TagRead       += PrintTagRead;
                        ReadMgr.GetReader().StartReading();
                        if (properties["audiblealert"].ToLower() == "yes")
                        {
                            if (readTriggeredByTap)
                            {
                                playStartSound();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString());
                        tbTXPower.Enabled = true;
                        //MessageBox.Show("Error connecting to reader: " + ex.Message.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        btnStartReads.Text = "Start Reads";
                        setStatus(Status.IDLE);
                        ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.MAXSAVE);
                        miGoToMain.Enabled          = true;
                        tmrBackLightControl.Enabled = false;
                        properties["isreading"]     = "no";
                        Utilities.SaveConfigurations(properties);
                        throw ex;
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
                else if (btnStartReads.Text == "Stop Reads")
                {
                    logger.Debug("Stop Reads pressed: Calling StopReads from ReadtheTags");
                    StopReads();
                    logger.Debug("Stop Reads pressed: Called StopReads from ReadtheTags");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (-1 != ex.Message.IndexOf("RFID reader was not found"))
                {
                    MessageBox.Show(ex.Message, "Error");
                }
                else
                {
                    btnStartReads.Text = "Start Reads";
                    setStatus(Status.IDLE);
                    properties["isreading"] = "no";
                    Utilities.SaveConfigurations(properties);
                    throw ex;
                }
            }
        }
예제 #21
0
        private void btnsetlongtask_Click(object sender, EventArgs e)
        {
            if ((!this.rbexeinstant.Checked) && (!this.rbexepoweron.Checked))
            {
                MessageBox.Show("please select operation property");
                return;
            }
            if ((!this.rbsearchtag.Checked) && (!this.rbsearandread.Checked) && (!this.rbseaandwrite.Checked))
            {
                MessageBox.Show("please select operation type");
                return;
            }
            if ((!this.cbant1.Checked) && (!this.cbant2.Checked) &&
                (!this.cbant3.Checked) && (!this.cbant4.Checked))
            {
                MessageBox.Show("please select antennas for inventory");
                return;
            }
            if ((!this.rbgen2.Checked) && (!this.rb180006b.Checked))
            {
                MessageBox.Show("please select tag protocol");
                return;
            }
            if (this.tbuploadintv.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input upload interval");
                return;
            }
            if (this.tbuploadip.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input upload ip address");
                return;
            }
            if (this.tbuploadport.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input upload tcp port");
                return;
            }
            if (this.tbreaddur.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input inventory cycle ");
                return;
            }
            if (this.tbreadinterval.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input inventory interval");
                return;
            }
            if (this.rbsearandread.Checked)
            {
                if (this.tbblkcnt.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("please input blocks to read");
                    return;
                }
            }
            if (this.rbseaandwrite.Checked)
            {
                if (this.rtbwdata.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("please input data to write");
                    return;
                }
            }

            if (this.rbsearandread.Checked || this.rbseaandwrite.Checked)
            {
                if (this.cbbbank.SelectedIndex == -1)
                {
                    MessageBox.Show("please select bank");
                    return;
                }
                if (this.tbstartaddr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("please input starting address");
                    return;
                }
            }

            LongTaskInfo ltinfo = new LongTaskInfo();

            if (this.tbpwd.Text.Trim() == string.Empty)
            {
                ltinfo.AccessPassword = (uint)0;
            }
            else
            {
                byte[] tmp = ByteFormat.FromHex(this.tbpwd.Text.Trim());
                ltinfo.AccessPassword = (uint)((tmp[0] << 24) | (tmp[1] << 16) | (tmp[2] << 8) | tmp[3]);
            }
            ltinfo.InvDur         = int.Parse(this.tbreaddur.Text.Trim());
            ltinfo.InvInterval    = int.Parse(this.tbreadinterval.Text.Trim());
            ltinfo.UploadPort     = int.Parse(this.tbuploadport.Text.Trim());
            ltinfo.UploadIp       = this.tbuploadip.Text.Trim();
            ltinfo.UploadInterval = int.Parse(this.tbuploadintv.Text.Trim());
            List <int> ants = new List <int>();

            if (this.cbant1.Checked)
            {
                ants.Add(1);
            }
            if (this.cbant2.Checked)
            {
                ants.Add(2);
            }
            if (this.cbant3.Checked)
            {
                ants.Add(3);
            }
            if (this.cbant4.Checked)
            {
                ants.Add(4);
            }
            ltinfo.OpAnts = ants.ToArray();
            if (this.rb180006b.Checked)
            {
                ltinfo.Potl = TagProtocol.ISO180006B;
            }
            else
            {
                ltinfo.Potl = TagProtocol.GEN2;
            }
            if (this.rbsearchtag.Checked)
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTag;
            }
            else if (this.rbsearandread.Checked)
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTagAndReadBank;
            }
            else
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTagAndWriteBank;
            }
            if (this.rbexeinstant.Checked)
            {
                ltinfo.Action = LongTaskInfo.LongTaskAction.LTA_Start_Instant;
            }
            else
            {
                ltinfo.Action = LongTaskInfo.LongTaskAction.LTA_Start_PowerOn;
            }

            if (this.rbsearandread.Checked || this.rbseaandwrite.Checked)
            {
                ltinfo.OpBank    = this.cbbbank.SelectedIndex;
                ltinfo.StartAddr = int.Parse(this.tbstartaddr.Text.Trim());
            }

            if (this.rbsearandread.Checked)
            {
                ltinfo.BlkCnt = int.Parse(this.tbblkcnt.Text.Trim());
            }
            if (this.rbseaandwrite.Checked)
            {
                ltinfo.Wdata = ByteFormat.FromHex(this.rtbwdata.Text.Trim());
            }

            try
            {
                rdr.ParamSet("LongTaskSetting", ltinfo);
                this.tblocalport.Text = this.tbuploadport.Text;
                MessageBox.Show("setting sucess");
            }
            catch
            {
                MessageBox.Show("setting failed");
            }
        }
예제 #22
0
        private void btnsetlongtask_Click(object sender, EventArgs e)
        {
            if ((!this.rbexeinstant.Checked) && (!this.rbexepoweron.Checked))
            {
                MessageBox.Show("请选择操作属性");
                return;
            }
            if ((!this.rbsearchtag.Checked) && (!this.rbsearandread.Checked) && (!this.rbseaandwrite.Checked))
            {
                MessageBox.Show("请选择操作类型");
                return;
            }
            if ((!this.cbant1.Checked) && (!this.cbant2.Checked) &&
                (!this.cbant3.Checked) && (!this.cbant4.Checked))
            {
                MessageBox.Show("请选择天线");
                return;
            }
            if ((!this.rbgen2.Checked) && (!this.rb180006b.Checked))
            {
                MessageBox.Show("请选择协议");
                return;
            }
            if (this.tbuploadintv.Text.Trim() == string.Empty)
            {
                MessageBox.Show("输入上传间隔");
                return;
            }
            if (this.tbuploadip.Text.Trim() == string.Empty)
            {
                MessageBox.Show("输入上传地址");
                return;
            }
            if (this.tbuploadport.Text.Trim() == string.Empty)
            {
                MessageBox.Show("输入上传端口");
                return;
            }
            if (this.tbreaddur.Text.Trim() == string.Empty)
            {
                MessageBox.Show("输入读时长");
                return;
            }
            if (this.tbreadinterval.Text.Trim() == string.Empty)
            {
                MessageBox.Show("输入读间隔");
                return;
            }
            if (this.rbsearandread.Checked)
            {
                if (this.tbblkcnt.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("输入读块数");
                    return;
                }
            }
            if (this.rbseaandwrite.Checked)
            {
                if (this.rtbwdata.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("输入写入数据");
                    return;
                }
            }

            if (this.rbsearandread.Checked || this.rbseaandwrite.Checked)
            {
                if (this.cbbbank.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择bank");
                    return;
                }
                if (this.tbstartaddr.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("输入起始地址");
                    return;
                }
            }

            LongTaskInfo ltinfo = new LongTaskInfo();

            if (this.tbpwd.Text.Trim() == string.Empty)
            {
                ltinfo.AccessPassword = (uint)0;
            }
            else
            {
                byte[] tmp = ByteFormat.FromHex(this.tbpwd.Text.Trim());
                ltinfo.AccessPassword = (uint)((tmp[0] << 24) | (tmp[1] << 16) | (tmp[2] << 8) | tmp[3]);
            }
            ltinfo.InvDur         = int.Parse(this.tbreaddur.Text.Trim());
            ltinfo.InvInterval    = int.Parse(this.tbreadinterval.Text.Trim());
            ltinfo.UploadPort     = int.Parse(this.tbuploadport.Text.Trim());
            ltinfo.UploadIp       = this.tbuploadip.Text.Trim();
            ltinfo.UploadInterval = int.Parse(this.tbuploadintv.Text.Trim());
            List <int> ants = new List <int>();

            if (this.cbant1.Checked)
            {
                ants.Add(1);
            }
            if (this.cbant2.Checked)
            {
                ants.Add(2);
            }
            if (this.cbant3.Checked)
            {
                ants.Add(3);
            }
            if (this.cbant4.Checked)
            {
                ants.Add(4);
            }
            ltinfo.OpAnts = ants.ToArray();
            if (this.rb180006b.Checked)
            {
                ltinfo.Potl = TagProtocol.ISO180006B;
            }
            else
            {
                ltinfo.Potl = TagProtocol.GEN2;
            }
            if (this.rbsearchtag.Checked)
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTag;
            }
            else if (this.rbsearandread.Checked)
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTagAndReadBank;
            }
            else
            {
                ltinfo.OpType = LongTaskInfo.TagOpType.TagOp_SearchTagAndWriteBank;
            }
            if (this.rbexeinstant.Checked)
            {
                ltinfo.Action = LongTaskInfo.LongTaskAction.LTA_Start_Instant;
            }
            else
            {
                ltinfo.Action = LongTaskInfo.LongTaskAction.LTA_Start_PowerOn;
            }

            if (this.rbsearandread.Checked || this.rbseaandwrite.Checked)
            {
                ltinfo.OpBank    = this.cbbbank.SelectedIndex;
                ltinfo.StartAddr = int.Parse(this.tbstartaddr.Text.Trim());
            }

            if (this.rbsearandread.Checked)
            {
                ltinfo.BlkCnt = int.Parse(this.tbblkcnt.Text.Trim());
            }
            if (this.rbseaandwrite.Checked)
            {
                ltinfo.Wdata = ByteFormat.FromHex(this.rtbwdata.Text.Trim());
            }

            try
            {
                //       ltinfo.IsTriggerByGpi = true;
                //       ltinfo.GpiBitMap = 0xf;
                ltinfo.IsDriveGpo     = false;
                ltinfo.IsTriggerByGpi = false;
                //ltinfo.OpGpiBitMap = 0x7;
                //ltinfo.SuccesGpoBitMap = 0xf;
                //ltinfo.DefaultGpoBitMap = 0x01;
                //ltinfo.SucGpoBitMapDur = 2;
                rdr.ParamSet("LongTaskSetting", ltinfo);
                this.tblocalport.Text = this.tbuploadport.Text;
                MessageBox.Show("设置成功");
            }
            catch
            {
                MessageBox.Show("设置失败");
            }
        }
예제 #23
0
        private void btnwrite_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }
            if (selants.Count != 1)
            {
                MessageBox.Show("must and only select one antenna");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("please select the id of tag to operate");
                return;
            }
            string sltag = listBox2.SelectedItem.ToString();


            if (IsValidHexstr(this.rtbdata.Text.Trim(), 432) != 0)
            {
                MessageBox.Show("data for writing must be hexadecimal numbers and the length of data must be multiple of 2 and no less than 432");
                return;
            }

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("please input the starting address");
                return;
            }

            int bytecnt = this.rtbdata.Text.Trim().Length / 2;

            try
            {
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                int    addrst = int.Parse(this.tbStartAddr.Text.Trim());
                int    st     = Environment.TickCount;
                byte[] wdata  = ByteFormat.FromHex(this.rtbdata.Text.Trim());
                Modrdr.ParamSet("OpTimeout", (ushort)6500);
                Modrdr.WriteTagMemBytes(new ISO180006bTagData(ByteFormat.FromHex(sltag)), MemBank.ISO180006BMEM, addrst, wdata);
                this.label3.Text  = (Environment.TickCount - st).ToString();
                this.rtbdata.Text = "writing success";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Modrdr.ParamSet("OpTimeout", (ushort)1000);
            }
        }
예제 #24
0
        // TODO: Merge common functionality between KeyboardWedgeRead and ReadTags.ReadtheTags
        private void KeyboardWedgeRead()
        {
            List <SendInputWrapper.INPUT> inputList = new List <SendInputWrapper.INPUT>();
            string startIndicator = ".";

            // Signal start of read
            inputList.Clear();
            AddKeypresses(inputList, startIndicator);
            SendInput(inputList);

            properties = Utilities.GetProperties();

            SoundPlayer startSound = new SoundPlayer(properties["startscanwavefile"]);

            if (properties["audiblealert"].ToLower() == "yes")
            {
                startSound.Play();
            }
            SoundPlayer stopSound = new SoundPlayer(properties["endscanwavefile"]);

            stopSound.LoadAsync();

            CoreDLL.SYSTEM_POWER_STATUS_EX status = new CoreDLL.SYSTEM_POWER_STATUS_EX();
            //Check the battery power level
            if (CoreDLL.GetSystemPowerStatusEx(status, false) == 1)
            {
                if (status.BatteryLifePercent <= 5)
                {
                    if (status.ACLineStatus == 0)
                    {
                        MessageBox.Show("Battery level is low to read tags");
                        return;
                    }
                }
            }
            try
            {
                TagReadData[] reads;

                //Utilities.PowerManager.PowerNotify += new PowerManager.PowerEventHandler(PowerManager_PowerNotify);
                using (ThingMagic.RFIDSearchLight.ReadMgr.Session rsess = ThingMagic.RFIDSearchLight.ReadMgr.GetSession())
                {
#if DEBUG
                    if (properties["audiblealert"].ToLower() == "yes")
                    {
                        startSound.Play();
                    }
#endif

                    int radioPower = 0;
                    if (properties["readpower"].ToString() == "")
                    {
                        radioPower = 2300;//While reading read power should be max
                    }
                    else
                    {
                        radioPower = Convert.ToInt32(properties["readpower"].ToString());
                    }

                    //Set the region
                    string region = properties["region"];
                    try
                    {
                        Utilities.SwitchRegion(region);
                    }
                    catch (ArgumentException)
                    {
                        MessageBox.Show(
                            "Unknown Region: " + region + "\r\n" +
                            "Please run RFIDSearchLight to initialize the region."
                            );
                    }

                    rsess.Reader.ParamSet("/reader/powerMode", Reader.PowerMode.FULL);
                    rsess.Reader.ParamSet("/reader/radio/readPower", radioPower);
                    rsess.Reader.ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 1, 1, 1 } });
                    List <int> ant = new List <int>();
                    ant.Add(1);
                    //set the tag population settings
                    rsess.Reader.ParamSet("/reader/gen2/target", Gen2.Target.A);//default target
                    string tagPopulation = properties["tagpopulation"];
                    switch (tagPopulation)
                    {
                    case "small":
                        rsess.Reader.ParamSet("/reader/gen2/q", new Gen2.StaticQ(2));
                        rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                        rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                        break;

                    case "medium":
                        rsess.Reader.ParamSet("/reader/gen2/q", new Gen2.StaticQ(4));
                        rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S1);
                        rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                        break;

                    case "large":
                        rsess.Reader.ParamSet("/reader/gen2/q", new Gen2.StaticQ(6));
                        rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S2);
                        rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M2);
                        break;

                    default: break;
                    }
                    //set the read plan and filter
                    TagFilter filter;
                    int       addressToRead = int.Parse(properties["selectionaddress"]);
                    Gen2.Bank bank          = Gen2.Bank.EPC;
                    switch (properties["tagselection"].ToLower())
                    {
                    case "None":
                    case "epc": bank = Gen2.Bank.EPC; break;

                    case "tid": bank = Gen2.Bank.TID; break;

                    case "user": bank = Gen2.Bank.USER; break;

                    case "reserved": bank = Gen2.Bank.RESERVED; break;

                    default: break;
                    }
                    if ("yes" == properties["ismaskselected"])
                    {
                        filter = new Gen2.Select(true, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                    }
                    else
                    {
                        filter = new Gen2.Select(false, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                    }
                    //set the read plan
                    SimpleReadPlan srp;
                    if (properties["tagselection"].ToLower() == "none")
                    {
                        srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, null, 0);
                    }
                    else
                    {
                        srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, filter, 0);
                    }
                    rsess.Reader.ParamSet("/reader/read/plan", srp);

                    double readDuration = Convert.ToDouble(properties["scanduration"].ToString()) * 1000;
                    int    readTimeout  = Convert.ToInt32(readDuration);

                    //Do a sync read for the readduration
#if DEBUG
                    if (properties["audiblealert"].ToLower() == "yes")
                    {
                        startSound.Play();
                    }
#endif
                    reads = rsess.Reader.Read(readTimeout);

                    rsess.Reader.ParamSet("/reader/powerMode", Reader.PowerMode.MINSAVE);
                    if (properties["audiblealert"].ToLower() == "yes")
                    {
                        stopSound.Play();
                    }
                    // Clear start indicator
                    inputList.Clear();
                    for (int i = 0; i < startIndicator.Length; i++)
                    {
                        AddKeypresses(inputList, new byte[] {
                            // Don't send Backspace -- that's one of our hotkeys,
                            // so it'll put us in an infinite loop.
                            (byte)Keys.Left,
                            (byte)Keys.Delete,
                        });
                    }
                    SendInput(inputList);
                }

                inputList.Clear();
                //HideWindow();
                bool     timestamp = false, rssi = false, position = false;
                string[] metadata = properties["metadatatodisplay"].Split(',');
                //Metadata boolean variables
                foreach (string mdata in metadata)
                {
                    switch (mdata.ToLower())
                    {
                    case "timestamp": timestamp = true; break;

                    case "rssi": rssi = true; break;

                    case "position": position = true; break;

                    default: break;
                    }
                }
                string metadataseparator       = properties["metadataseparator"];
                byte   metadataseparatorInByte = 0x00;
                switch (metadataseparator.ToLower())
                {
                //The byte representation of special characters can be found here - http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
                case "comma": metadataseparatorInByte = 0xBC; break;

                case "space": metadataseparatorInByte = 0x20; break;

                case "enter": metadataseparatorInByte = 0x0D; break;

                case "tab": metadataseparatorInByte = 0x09; break;

                default: break;
                }
                //Print the epc in caps
                AddKeypress(inputList, (byte)Keys.Capital);  // Toggle Caps Lock

                //Print the tag reads
                foreach (TagReadData dat in reads)
                {
                    string tagData = string.Empty;
                    string epc     = string.Empty;
                    if (properties["displayformat"] == "base36")
                    {
                        epc = ConvertEPC.ConvertHexToBase36(dat.EpcString);
                    }
                    else
                    {
                        epc = dat.EpcString;
                    }

                    AddKeypresses(inputList, properties["prefix"].ToUpper());
                    AddKeypresses(inputList, epc.ToUpper());
                    AddKeypresses(inputList, properties["suffix"].ToUpper());

                    if (timestamp)
                    {
                        AddKeypress(inputList, metadataseparatorInByte);
                        AddKeypresses(inputList, dat.Time.ToString("yyyy-MM-dd-HH-mm-ss"));
                    }
                    if (rssi)
                    {
                        AddKeypress(inputList, metadataseparatorInByte);
                        AddKeypresses(inputList, dat.Rssi.ToString());
                    }
                    if (position)
                    {
                        AddKeypress(inputList, metadataseparatorInByte);
                        AddKeypresses(inputList, GpsMgr.LatLonString);
                    }

                    switch (properties["multipletagseparator"].ToLower())
                    {
                    case "comma": AddKeypress(inputList, 0xBC); break;

                    case "space": AddKeypress(inputList, 0x20); break;

                    case "enter": AddKeypress(inputList, 0x0D); break;

                    case "tab": AddKeypress(inputList, 0x09); break;

                    case "pipe":
                        AddInput(inputList, SHIFT_DOWN);
                        AddKeypress(inputList, 0xDC);
                        AddInput(inputList, SHIFT_UP);
                        break;

                    default: break;
                    }
                    // Send keystrokes after each tag read record -- input buffer
                    // isn't big enough to hold more than a few lines
                    SendInput(inputList);
                    inputList.Clear();
                }
                //Turn caps lock back off
                AddKeypress(inputList, (byte)Keys.Capital);  // Toggle Caps Lock
                SendInput(inputList);
            }

            catch (Exception ex)
            {
                logger.Error("In KeyboardWedgeRead(): " + ex.ToString());
                //MessageBox.Show(ex.Message);
                //Debug.Log(ex.ToString());
            }
        }
예제 #25
0
        private void btnResetReadProtect_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("please select antenna");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            byte[] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("please input access password");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("access password must be 8 of hexadecimal numbers");
                    break;

                case -1:
                    MessageBox.Show("access password must be 8 of hexadecimal numbers");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }

            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }

            try
            {
                NXP_ResetReadProtectPara para = new NXP_ResetReadProtectPara(pwd);
                mrdr.CustomCmd(filter, CustomCmdType.NXP_ResetReadProtect, para);
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("no tag");
                }
                else
                {
                    MessageBox.Show("operation failed:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("operation failed:" + ex.ToString());
                return;
            }
        }
예제 #26
0
        /// <summary>
        /// Authenticate with key0
        /// </summary>
        private void btnAuthKeyZero_Click(object sender, RoutedEventArgs e)
        {
            //Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key0, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";

            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyZero.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyZero.Text);
                Key0 = new ushort[KeytoWrite.Length / 2];
                Key0 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key0", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);
            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Authentication with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    returnedIchallenge         = new ushort[Challenge.Length / 2];
                    returnedIchallenge         = ByteConv.ToU16s(Challenge);
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0).ToArray());
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Read Buffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0));
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    //Authenticate with tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
예제 #27
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }

            if (selants.Count != 1)
            {
                MessageBox.Show("必须且只能选择个一个天线");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("请选中要操作的卡号");
                return;
            }

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入起始地址");
                return;
            }
            if (this.tbBlkCnt.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入要读块数");
                return;
            }

            string sltag = listBox2.SelectedItem.ToString();

            try
            {
                int addrst = int.Parse(this.tbStartAddr.Text.Trim());
                int blkcnt = int.Parse(this.tbBlkCnt.Text.Trim());
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                int    t1   = Environment.TickCount;
                byte[] data = Modrdr.ReadTagMemBytes(new ISO180006bTagData(ByteFormat.FromHex(sltag)), MemBank.ISO180006BMEM, addrst, blkcnt);
                Debug.WriteLine((Environment.TickCount - t1).ToString());
                this.rtbdata.Text = ByteFormat.ToHex(data);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #28
0
        /// <summary>
        /// Populate keys of the tag
        /// </summary>
        private void PopulateAuthenticateData()
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                ResetUntraceableFields();
                if ((bool)rbFirstTagAuthenticateTb.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }
                objReader.ParamSet("/reader/tagop/antenna", antenna);

                if ((bool)rbSelectedTagAuthenticateTb.IsChecked)
                {
                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(currentEPC);
                    }
                    else
                    {
                        int    dataLength       = 0;
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null != SearchSelectData)
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                }
                else
                {
                    searchSelect = new TagData(currentEPC);
                }


                TagOp op;
                try
                {
                    ushort[] Key0           = null;
                    string   CurrentKeyZero = string.Empty;
                    op   = new Gen2.ReadData(Gen2.Bank.USER, 0xC0, 8);
                    Key0 = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != Key0)
                    {
                        CurrentKeyZero = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(Key0), "", " ");
                    }

                    crntKey0Value.Content  = CurrentKeyZero;
                    txtbxKeyZero.IsEnabled = true;
                    txtbxKeyZero.Text      = CurrentKeyZero;
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        crntKey0Value.Content  = "Key0 is inserted and activated";
                        txtbxKeyZero.IsEnabled = false;
                    }
                }
                try
                {
                    ushort[] Key1          = null;
                    string   CurrentKeyOne = string.Empty;
                    op   = new Gen2.ReadData(Gen2.Bank.USER, 0xD0, 8);
                    Key1 = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != Key1)
                    {
                        CurrentKeyOne = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(Key1), "", " ");
                    }

                    crntKey1Value.Content = CurrentKeyOne;
                    txtbxKeyOne.IsEnabled = true;
                    txtbxKeyOne.Text      = CurrentKeyOne;
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        crntKey1Value.Content = "Key1 is inserted and activated";
                        txtbxKeyOne.IsEnabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
예제 #29
0
        private void btnlock_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }
            if (selants.Count != 1)
            {
                MessageBox.Show("必须且只能选择个一个天线");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("请选中要操作的卡号");
                return;
            }
            string sltag = listBox2.SelectedItem.ToString();

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入起始地址");
                return;
            }
            try
            {
                int addrst = int.Parse(this.tbStartAddr.Text.Trim());
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                Modrdr.LockTag(new ISO180006bTagData(ByteFormat.FromHex(sltag)), new ISO180006bLockAction(addrst));
                this.rtbdata.Text = "锁成功";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #30
0
        private void btnChangeEAS_Click(object sender, EventArgs e)
        {
            int         ret;
            TagChipType nxpchiptype = TagChipType.TagChipType_None;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("请选择操作天线");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if ((!this.rbEASset.Checked) && (!this.rbEASreset.Checked))
            {
                MessageBox.Show("请选择EAS状态");
                return;
            }

            if (this.cbbnxpchiptype.SelectedIndex == -1)
            {
                MessageBox.Show("请选择芯片类型");
                return;
            }
            else
            {
                if (this.cbbnxpchiptype.SelectedIndex == 0)
                {
                    nxpchiptype = TagChipType.TagChipType_NXP_G2X;
                }
                else if (this.cbbnxpchiptype.SelectedIndex == 1)
                {
                    nxpchiptype = TagChipType.TagChipType_NXP_G2i;
                }
            }

            bool isSet = false;

            if (this.rbEASset.Checked)
            {
                isSet = true;
            }
            else
            {
                isSet = false;
            }

            byte [] pwd = null;

            ret = Form1.IsValidPasswd(this.tbaccesspasswd.Text.Trim());
            {
                switch (ret)
                {
                case -3:
                    MessageBox.Show("访问密码不能为空");
                    break;

                case -2:
                case -4:
                    MessageBox.Show("访问密码必须是8个16进制数");
                    break;

                case -1:
                    MessageBox.Show("访问密码只能是16进制数字");
                    break;
                }
            }
            if (ret != 0)
            {
                return;
            }
            else
            {
                pwd = ByteFormat.FromHex(this.tbaccesspasswd.Text.Trim());
            }
            Gen2TagFilter filter = null;

            if (checkfilter(ref filter) != 0)
            {
                return;
            }
            NXP_ChangeEASPara ChEasPara = new NXP_ChangeEASPara(pwd, isSet, nxpchiptype);

            try
            {
                mrdr.CustomCmd(filter, CustomCmdType.NXP_ChangeEAS, ChEasPara);
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("没法发现标签");
                }
                else
                {
                    MessageBox.Show("操作失败:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ChangeEAS失败:" + ex.ToString());
                return;
            }
        }