示例#1
0
        /// <summary>
        /// Test if a tag Matches this filter. Only applies to selects based
        /// on the EPC.
        /// </summary>
        /// <param name="t">tag data to screen</param>
        /// <returns>Return true to allow tag through the filter.
        /// Return false to reject tag.</returns>
        public bool Matches(TagData t)
        {
            foreach( TagFilter filter in filters )
            {
                if( !filter.Matches(t) )
                    return false;
            }

            return true;
        }
        /// <summary>
        /// Populate access password of the tag
        /// </summary>
        private void PopulateUserData()
        {
            try
            {
                // Clear the previous error
                ResetLockActionCheckBoxes();
                grpbxLockTgAccessPwd.IsEnabled = true;

                Mouse.SetCursor(Cursors.Wait);
                if ((bool)rbFirstTagLockTagTb.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }

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

                if ((bool)rbSelectedTagLockTagTb.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;
                    if (model.Equals("M5e") || model.Equals("M5e EU") || model.Equals("M5e Compact") || model.Equals("Astra"))
                    {
                        ReadData(Gen2.Bank.RESERVED, searchSelect, out reservedData);
                    }
                    else
                    {
                        op = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 0);
                        reservedData = (ushort[])objReader.ExecuteTagOp(op, searchSelect);
                    }

                    if (null != reservedData)
                        reservedBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    
                    txtbxAccesspaasword.Text = reservedBankData.Trim(' ');
                    grpbxLockTgApplyLocks.IsEnabled = true;
                    grpbxLockTgLockActns.IsEnabled = true;
                    btnWriteAccessPwd.IsEnabled = true;
                }
                catch (Exception ex)
                {
                    // Show the error in access password section if failed
                    txtblkErrorAccessPassword.Visibility = System.Windows.Visibility.Visible;
                    grpbxLockTgApplyLocks.IsEnabled = false;
                    grpbxLockTgLockActns.IsEnabled = false;
                    btnWriteAccessPwd.IsEnabled = false;
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtblkErrorAccessPassword.Text = "Error: Read Error";
                    }
                    else if (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception)
                    {
                        txtblkErrorAccessPassword.Text = "Error: Could not read access password. Access Password may be locked. You must enter the correct Access Password to proceed with locking"; 
                    }
                    else
                    {
                        txtblkErrorAccessPassword.Text = "Error: "+ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
        /// <summary>
        /// Current access password, epc and tid need to be saved before applying the lock on access password"
        /// </summary>
        private void SaveAccessPassword()
        {
            try
            {
                MessageBox.Show("Current access password need to be saved before applying the lock on Access Password","Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);            
                string accessPwdSaveFileDialogFileName =  "AccessPwd";
                SaveFileDialog accessPwdSaveFileDialog = new SaveFileDialog();
                accessPwdSaveFileDialog.Filter = "Text Files (.txt)|*.txt";
                accessPwdSaveFileDialog.FileName = accessPwdSaveFileDialogFileName;
                if ((bool)accessPwdSaveFileDialog.ShowDialog())
                {
                    accessPwdSaveFileDialogFileName = accessPwdSaveFileDialog.FileName;
                    TextWriter txtWriter = new StreamWriter(accessPwdSaveFileDialogFileName);
                    StringBuilder stringAccesspAssword = new StringBuilder();               

                    Mouse.SetCursor(Cursors.Wait);
                    if ((bool)rbFirstTagLockTagTb.IsChecked)
                    {
                        antenna = GetSelectedAntennaList()[0];
                    }

                    objReader.ParamSet("/reader/tagop/antenna", antenna);
                    TagFilter searchSelect = null;
                    stringAccesspAssword.Append("EPC: "+currentEPC);
                    stringAccesspAssword.Append(Environment.NewLine);
                    if ((bool)rbSelectedTagLockTagTb.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 TID bank data
                    ushort[] tidData = null;
                    TagOp op;
                    try
                    {
                        string tidBankData = string.Empty;
                        if (model.Equals("M5e") || model.Equals("M5e EU") || model.Equals("M5e Compact") || model.Equals("Astra"))
                        {
                            ReadData(Gen2.Bank.TID, searchSelect, out tidData);
                        }
                        else
                        {
                            op = new Gen2.ReadData(Gen2.Bank.TID, 0, 0);
                            tidData = (ushort[])objReader.ExecuteTagOp(op, searchSelect);
                        }

                        if (null != tidData)
                            tidBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(tidData), "", " ");

                        if (tidBankData.Length > 0)
                        {
                            stringAccesspAssword.Append("TID: "+tidBankData.Replace(" ",""));
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                        {
                            stringAccesspAssword.Append("TID: Read Error");
                        }
                        else
                        {
                            stringAccesspAssword.Append("TID: "+ex.Message);
                        }
                    }
                    stringAccesspAssword.Append(Environment.NewLine);
                    stringAccesspAssword.Append("AccessPassword: 0x"+txtbxAccesspaasword.Text.Replace(" ",""));
                    stringAccesspAssword.Append(Environment.NewLine);
                    txtWriter.WriteLine(stringAccesspAssword.ToString());
                    txtWriter.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }        
        private void btnApplyLockActions_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                statusLockActions.Clear();

                // Atleast one lock action need be selected to perform apply
                if (!(selectedLockActions.Count > 0))
                {
                    MessageBox.Show("Please select atleast one lock action to perform", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                // Either of the lock/unlock need to be selected, if Permanent? is selected.
                if ((bool)chkbxPermaLockAccessPwd.IsChecked)
                {
                    if (false == ((bool)chkbxLockAccessPwd.IsChecked || (bool)chkbxUnLocAccessPwd.IsChecked))
                    {
                        MessageBox.Show("Read/Write Lock or UnLock need to be selected, if Permanent? for Access Password is checked", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }

                // Either of the lock/unlock need to be selected, if Permanent? is selected.
                if ((bool)chkbxPermaLockKillPwd.IsChecked)
                {
                    if (false == ((bool)chkbxLockKillPwd.IsChecked || (bool)chkbxUnLockKillPwd.IsChecked))
                    {
                        MessageBox.Show("Read/Write Lock or UnLock need to be selected, if Permanent? for Kill Password is checked", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }

                // Either of the lock/unlock need to be selected, if Permanent? is selected.
                if ((bool)chkbxPermaLockTIDMem.IsChecked)
                {
                    if (false == ((bool)chkbxLockTIDMem.IsChecked || (bool)chkbxUnLockTIDMem.IsChecked))
                    {
                        MessageBox.Show("Write Lock or UnLock need to be selected, if Permanent? for TID Memory is checked", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }

                // Either of the lock/unlock need to be selected, if Permanent? is selected.
                if ((bool)chkbxPermaLockUserMem.IsChecked)
                {
                    if (false == ((bool)chkbxLockUserMem.IsChecked || (bool)chkbxUnLockUserMem.IsChecked))
                    {
                        MessageBox.Show("Write Lock or UnLock need to be selected, if Permanent? for User Memory is checked", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }

                // Either of the lock/unlock need to be selected, if Permanent? is selected.
                if ((bool)chkbxPermaLockEPCMem.IsChecked)
                {
                    if (false == ((bool)chkbxLockEPCMem.IsChecked || (bool)chkbxUnLockEPCMem.IsChecked))
                    {
                        MessageBox.Show("Write Lock or UnLock need to be selected, if Permanent? for EPC Memory is checked", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }

                // Access password can't be empty
                if (txtbxAccesspaasword.Text.Length <= 0)
                {
                    MessageBox.Show("Access password can't be empty", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                // Locking the tag with zero access password provides no security
                if (ByteConv.ToU32(ByteFormat.FromHex(txtbxAccesspaasword.Text.Replace(" ", "")), 0) == 0)
                {
                    MessageBoxResult result = MessageBox.Show("Locking with Access Password = 0 provides no security, memory will be fully accessible. Continue?", "Universal Reader Assistant", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                    if (result.Equals(MessageBoxResult.Cancel))
                    {
                        return;
                    }
                }

                List<string> temp = new List<string>();
                temp = selectedLockActions.ToList<string>();
                foreach (string lck in temp)
                {
                    if (lck.Contains("_PERMALOCK"))
                    {
                        MessageBoxResult result = MessageBox.Show("Are you sure you want the locking action "+lck+" to be made Permanent?. This cannot be undone.", "Universal Reader Assistant", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                        if (result.Equals(MessageBoxResult.Cancel))
                        {
                            selectedLockActions.Remove(lck);
                        }
                    }
                }

                if (selectedLockActions.Contains("Gen2.LockAction.ACCESS_LOCK") || selectedLockActions.Contains("Gen2.LockAction.ACCESS_PERMALOCK"))
                {
                    SaveAccessPassword();
                }               

                Mouse.SetCursor(Cursors.Wait);

                if ((bool)rbFirstTagLockTagTb.IsChecked)
                {
                    antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
                }

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

                if ((bool)rbSelectedTagLockTagTb.IsChecked)
                {
                    TagFilter searchSelect = null;


                    if (selectMemBank == Gen2.Bank.EPC)
                    {
                        searchSelect = new TagData(txtEpc.Text);
                    }
                    else
                    {
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null == SearchSelectData)
                        {
                            dataLength = 0;
                        }
                        else
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(accessPwddStartAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                    ApplyLock(searchSelect);
                }
                else
                {
                    ApplyLock(null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
示例#5
0
 /// <summary>
 /// Write a new ID to a tag.
 /// </summary>
 /// <param name="target">the tag target to operate on</param>
 /// <param name="epc">the tag ID to write</param>
 public override void WriteTag(TagFilter target, TagData epc)
 {
     ExecuteTagOp(new Gen2.WriteTag(new Gen2.TagData(epc.EpcBytes)), target);
 }
        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]);
                        }
                    }
                    Gen2ReadAllMemoryBanks prgm = new Gen2ReadAllMemoryBanks();
                    prgm.reader = r;

                    // Read Plan
                    byte length;
                    string model = (string)r.ParamGet("/reader/version/model");
                    if ("M6e".Equals(model)
                        || "M6e PRC".Equals(model)
                        || "M6e Micro".Equals(model)
                        || "Mercury6".Equals(model)
                        || "Astra-EX".Equals(model))
                    {
                        // Specifying the readLength = 0 will return full TID for any tag read in case of M6e varients, M6 and Astra-EX reader.
                        length = 0;
                    }
                    else
                    {
                        length = 2;
                    }
                    prgm.PerformWriteOperation();

                    TagReadData[] tagReadsFilter = r.Read(500);

                    if (tagReadsFilter.Length == 0)
                    {
                        Console.WriteLine("No tags found");
                        return;
                    }

                    TagFilter filter = new TagData(tagReadsFilter[0].EpcString);

                    Console.WriteLine("Perform embedded and standalone tag operation - read only user memory without filter");
                    Console.WriteLine();
                    TagOp op = new Gen2.ReadData(Gen2.Bank.USER, 0, length);
                    prgm.PerformReadAllMemOperation(null, op);
                    Console.WriteLine();

                    Console.WriteLine("Perform embedded and standalone tag operation - read user memory, reserved memory, tid memory and epc memory without filter");
                    Console.WriteLine();
                    op = null;
                    op = new Gen2.ReadData(Gen2.Bank.USER | Gen2.Bank.GEN2BANKUSERENABLED | Gen2.Bank.GEN2BANKRESERVEDENABLED | Gen2.Bank.GEN2BANKEPCENABLED | Gen2.Bank.GEN2BANKTIDENABLED, 0, length);
                    prgm.PerformReadAllMemOperation(null, op);
                    Console.WriteLine();

                    Console.WriteLine("Perform embedded and standalone tag operation - read only user memory with filter");
                    Console.WriteLine();
                    op = null;
                    op = new Gen2.ReadData(Gen2.Bank.USER, 0, length);
                    prgm.PerformReadAllMemOperation(filter, op);
                    Console.WriteLine();

                    Console.WriteLine("Perform embedded and standalone tag operation - read user memory, reserved memory with filter");
                    Console.WriteLine();
                    op = null;
                    op = new Gen2.ReadData(Gen2.Bank.USER | Gen2.Bank.GEN2BANKUSERENABLED | Gen2.Bank.GEN2BANKRESERVEDENABLED, 0, length);
                    prgm.PerformReadAllMemOperation(filter, op);
                    Console.WriteLine();

                    Console.WriteLine("Perform embedded and standalone tag operation - read user memory, reserved memory and tid memory with filter");
                    Console.WriteLine();
                    op = null;
                    op = new Gen2.ReadData(Gen2.Bank.USER | Gen2.Bank.GEN2BANKUSERENABLED | Gen2.Bank.GEN2BANKRESERVEDENABLED | Gen2.Bank.GEN2BANKTIDENABLED, 0, length);
                    prgm.PerformReadAllMemOperation(filter, op);
                    Console.WriteLine();

                    Console.WriteLine("Perform embedded and standalone tag operation - read user memory, reserved memory, tid memory and epc memory with filter");
                    Console.WriteLine();
                    op = null;
                    op = new Gen2.ReadData(Gen2.Bank.USER | Gen2.Bank.GEN2BANKUSERENABLED | Gen2.Bank.GEN2BANKRESERVEDENABLED | Gen2.Bank.GEN2BANKEPCENABLED | Gen2.Bank.GEN2BANKTIDENABLED, 0, length);
                    prgm.PerformReadAllMemOperation(filter, op);
                    Console.WriteLine();
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
        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);
            }
        }
示例#8
0
        /// <summary>
        /// Write a new ID to a tag.
        /// </summary>
        /// <param name="target">the tag target to operate on</param>
        /// <param name="epc">the tag ID to write</param>

        public override void WriteTag(TagFilter target, TagData epc)
        {
            // Validate parameters
            TagProtocol protocol = (TagProtocol)ParamGet("/reader/tagop/protocol");
            switch (protocol)
            {
                case TagProtocol.ISO180006B:
                case TagProtocol.ISO180006B_UCODE:
                    if (null == target)
                    {
                        throw new ReaderException("ISO18000-6B does not yet support writing ID to unspecified tags.  Please provide a TagFilter.");
                    }
                    break;
            }

            PrepForTagop();
            SetField("tag_id.id", new WriteTagArgs(target, epc));
        }
示例#9
0
 private void button3_Click(object sender, EventArgs e)
 {
     DateTime timeBeforeRead = DateTime.Now;
     try
     {
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             TagData epc = new TagData(textBox1.Text);
             reader.WriteTag(tagData, epc);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         if (ex.Message.StartsWith("General Tag Error"))
         {
             MessageBox.Show("No Tag Found");
         }
         else
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
示例#10
0
        //private string pvtReadTagData(int addressToRead, int byteCount, Gen2.Bank bankTORead)
        //{
        //    string readData = null;
        //    if (0 != (byteCount % 2))
        //    {
        //        throw new ArgumentException("Byte count must be an even number");
        //    }
        //    try
        //    {
        //        using(Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
        //        {
        //            DateTime timeBeforeRead = DateTime.Now;
        //            readData = ByteFormat.ToHex(reader.ReadTagMemBytes(tagData, (int)bankTORead, addressToRead, byteCount));
        //            DateTime timeAfterRead = DateTime.Now;
        //            TimeSpan timeElapsed = timeAfterRead - timeBeforeRead;
        //            commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
        //            return readData;
        //        }
        //        }
        //    }
        //    catch (Exception exp)
        //    {
        //        MessageBox.Show(exp.Message);
        //        return null;
        //    }
        //}
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime timeBeforeRead = DateTime.Now;
            try
            {
                using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
                {
                    reader.Connect();

                    tagData = reader.Read(100)[0].Tag;

                    textBox1.Text = tagData.EpcString;
                }
                DateTime timeAfterRead = DateTime.Now;
                TimeSpan timeElapsed = timeAfterRead - timeBeforeRead;
                commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
            }
            catch (Exception ex)
            {
                if (ex.Message.StartsWith("Index was outside"))
                {
                    MessageBox.Show("No Tag Found");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#11
0
 static void PrintTagDatas(TagData[] reads)
 {
     foreach (TagData read in reads)
     {
         Console.WriteLine(read.ToString());
     }
 }
示例#12
0
        private static void TestStrFilterReadPlansFunc(Reader rdr, ArgParser pargs)
        {
            Gen2.Select g2s = new Gen2.Select(false, Gen2.Bank.EPC, 16, 16, new byte[] { 0x12, 0x34 });
            Console.WriteLine(g2s);
            Gen2.Select notg2s = new Gen2.Select(true, Gen2.Bank.EPC, 16, 16, new byte[] { 0x12, 0x34 });
            Console.WriteLine(notg2s);
            Iso180006b.Select i6bs = new Iso180006b.Select(false, Iso180006b.SelectOp.EQUALS, 0, 0xC0, new byte[] { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            Console.WriteLine(i6bs);
            Iso180006b.Select noti6bs = new Iso180006b.Select(true, Iso180006b.SelectOp.EQUALS, 0, 0xC0, new byte[] { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            Console.WriteLine(noti6bs);
            TagData td = new TagData("1234567890ABCDEF");
            Console.WriteLine(td);
            MultiFilter mf = new MultiFilter(new TagFilter[] { g2s, i6bs, td });
            Console.WriteLine(mf);

            SimpleReadPlan srp1 = new SimpleReadPlan(null, TagProtocol.GEN2, g2s, 1000);
            Console.WriteLine(srp1);
            SimpleReadPlan srp2 = new SimpleReadPlan(new int[] { 1, 2 }, TagProtocol.ISO180006B, i6bs, 1000);
            Console.WriteLine(srp2);
            MultiReadPlan mrp = new MultiReadPlan(new ReadPlan[] { srp1, srp2 });
            Console.WriteLine(mrp);
        }
示例#13
0
        private static void TestMatchesFunc(Reader rdr, ArgParser pargs)
        {
            List<Gen2.TagData> list = new List<Gen2.TagData>();
            list.Add(MakeGen2TagData("3000", "0x044D00000000040005010064", "CEDA"));
            list.Add(MakeGen2TagData("3000", "044D00000000040007010070", "7107"));
            list.Add(MakeGen2TagData("3000", "044D0000000004000701006E", "82F8"));
            list.Add(MakeGen2TagData("3000", "044D0000000004000401006B", "4981"));
            list.Add(MakeGen2TagData("3000", "044D0000000004000E01006C", "51CD"));
            list.Add(MakeGen2TagData("3000", "044D0000000004000601006D", "C42F"));
            list.Add(MakeGen2TagData("3000", "3028354D8202000000001A6B", "1119"));
            list.Add(MakeGen2TagData("3000", "050000000000000000003E61", "5911"));
            list.Add(MakeGen2TagData("3000", "C8399E480126DC040101006B", "E90C"));
            list.Add(MakeGen2TagData("3000", "2B3A27B0A182AF350101005C", "3548"));
            list.Add(MakeGen2TagData("3000", "88C10D7556FFCAB801010085", "87E8"));
            list.Add(MakeGen2TagData("3000", "050000000000000000003E62", "6972"));
            list.Add(MakeGen2TagData("3000", "D54F973EB39959DC0101007B", "A9D7"));
            list.Add(MakeGen2TagData("3000", "017DD52B43277B3B0101006A", "5E15"));
            list.Add(MakeGen2TagData("3000", "050000000000000000003E63", "7953"));
            list.Add(MakeGen2TagData("3000", "B4759AAAE63B8777010100DC", "1D17"));
            list.Add(MakeGen2TagData("3000", "48C4A2C790E52858020100A3", "D4FB"));
            list.Add(MakeGen2TagData("3000", "A726B70BA4B0566501010055", "3C5D"));
            list.Add(MakeGen2TagData("3000", "EA37F41943C9897901010098", "D187"));
            list.Add(MakeGen2TagData("3000", "A969352F11405A8001010080", "B69B"));
            list.Add(MakeGen2TagData("3000", "12BF6BAB28F2122801010079", "7201"));
            list.Add(MakeGen2TagData("3000", "F0581C70A5E07DF7010100B3", "1B3C"));
            list.Add(MakeGen2TagData("3000", "FE911EEF7B009548010100C2", "059C"));
            list.Add(MakeGen2TagData("3000", "7CDAAD120A073CE90101007A", "64FB"));
            list.Add(MakeGen2TagData("3000", "F1AA7950D9DCA7D6010100AF", "5DEA"));
            list.Add(MakeGen2TagData("3000", "7062721836BE7E9C010100C8", "CBBE"));
            list.Add(MakeGen2TagData("3000", "7F38863B16B4DE5501010050", "27CB"));
            list.Add(MakeGen2TagData("3000", "2D6FB358C2ED07960201004F", "F803"));
            list.Add(MakeGen2TagData("3000", "CC3797853CA8DB8102010058", "F117"));
            list.Add(MakeGen2TagData("3000", "7AF713E5D9ECD647020100B2", "BD94"));
            list.Add(MakeGen2TagData("3000", "069B3ED79043CBCE0101009A", "B18F"));
            list.Add(MakeGen2TagData("3000", "300833B2DDD9014035050000", "42E7"));
            list.Add(MakeGen2TagData("3000", "6EECABF073C4FD980101007C", "C2AE"));
            list.Add(MakeGen2TagData("3000", "349D9427086A289002010056", "C57B"));
            list.Add(MakeGen2TagData("3000", "D4E8CFB7D2D51C7F010100AB", "1250"));
            list.Add(MakeGen2TagData("3000", "69AE2A765487268601010099", "F8B9"));

            TestFilter("No Filter", null, list);
            Gen2.Select startsWithC = new Gen2.Select(false, Gen2.Bank.EPC, 32, 4, new byte[] { 0xC0 });
            TestFilter("EPCs starting with C", startsWithC, list);
            Gen2.Select endsWith100xx = new Gen2.Select(false, Gen2.Bank.EPC, 32 + 96 - (5 * 4), 12, new byte[] { 0x10, 0x00 });
            TestFilter("EPCs ending in 100xx", endsWith100xx, list);
            Gen2.Select doesntEndWith100xx = new Gen2.Select(true, Gen2.Bank.EPC, 32 + 96 - (5 * 4), 12, new byte[] { 0x10, 0x00 });
            TestFilter("EPCs NOT ending in 100xx", doesntEndWith100xx, list);

            MultiFilter startsWithCAndEndsWith100xx = new MultiFilter(new TagFilter[] {
                startsWithC,
                endsWith100xx,
            });
            TestFilter("EPCs starting with C AND ending in 100xx", startsWithCAndEndsWith100xx, list);

            TagData specificTag = new TagData("A726B70BA4B0566501010055");
            TestFilter("Matches A726B70BA4B0566501010055", specificTag, list);
        }
示例#14
0
 /// <summary>
 /// Validates EPC String and formats valid strings into EPC
 /// </summary>
 /// <param name="epcString">Valid/Invalid EPC String</param>
 /// <returns>Valid TagData used for selection</returns>
 private TagData validateEpcStringAndReturnTagData(string epcString)
 {
     TagData validTagData = null;
     if (epcString.Contains(" "))
     {
         validTagData = null;
     }
     else
     {
         if (epcString.Length == 0)
         {
             validTagData = null;
         }
         else
         {
             if (epcString.Contains("0x"))
             {
                 validTagData = new TagData(epcString.Remove(0, 2));
             }
             validTagData = new TagData(epcString);
         }
     }
     return validTagData;
 }
示例#15
0
        private void ParseNotifyTag(MSG_RO_ACCESS_REPORT msg)
        {
            if (null == tagReads)
            {
                tagReads = new List<TagReadData>();
            }
            TagReadData tag = null;
            if (null != msg)
            {
                for (int i = 0; i < msg.TagReportData.Length; i++)
                {
                    try
                    {
                        tag = new TagReadData();
                        if (msg.TagReportData[i].EPCParameter.Count > 0)
                        {
                            string epc;
                            // reports come in two flavors.  Get the right flavor
                            if (msg.TagReportData[i].EPCParameter[0].GetType() == typeof(PARAM_EPC_96))
                            {
                                epc = ((PARAM_EPC_96)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            else
                            {
                                epc = ((PARAM_EPCData)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            TagData td = new TagData(ByteFormat.FromHex(epc));
                            TagProtocol tagProtocol = 0;
                            //Match the recieved rospec id with the rospec id stored in the hashtable at the time of setting readplan
                            if (roSpecProtcolTable.ContainsKey(msg.TagReportData[i].ROSpecID.ROSpecID))
                            {
                                tagProtocol = (TagProtocol)roSpecProtcolTable[msg.TagReportData[i].ROSpecID.ROSpecID];
                            }
                            if (TagProtocol.GEN2.Equals(tagProtocol))
                            {
                                //Get crc and pc bits
                                UNION_AirProtocolTagData tagdata = msg.TagReportData[i].AirProtocolTagData;
                                td = new Gen2.TagData(ByteFormat.FromHex(epc), ByteConv.EncodeU16(((PARAM_C1G2_CRC)tagdata[1]).CRC), ByteConv.EncodeU16(((PARAM_C1G2_PC)tagdata[0]).PC_Bits));
                            }
                            else if (TagProtocol.ISO180006B.Equals(tagProtocol))
                            {
                                td = new Iso180006b.TagData(ByteFormat.FromHex(epc));
                            }
                            else
                            {
                                td = new TagData(ByteFormat.FromHex(epc));
                            }
                            tag.Reader = this;
                            tag._tagData = td;
                            tag._antenna = (int)msg.TagReportData[i].AntennaID.AntennaID;
                            UInt64 usSinceEpoch = msg.TagReportData[i].LastSeenTimestampUTC.Microseconds;
                            tag._baseTime = epochTime.AddMilliseconds(usSinceEpoch / 1000);
                            tag._readOffset = 0;
                            // Since Spruce release firmware doesn't support phase, there won't be PARAM_ThingMagicTagReportContentSelector 
                            // custom paramter in ROReportSpec
                            string[] ver = softwareVersion.Split('.');
                            if (((Convert.ToInt32(ver[0]) == 4) && (Convert.ToInt32(ver[1]) >= 17)) ||
                                (Convert.ToInt32(ver[0]) > 4))
                            {
                                tag._phase = Convert.ToInt32(((PARAM_ThingMagicRFPhase)msg.TagReportData[i].Custom[0]).Phase);
                            }
                            tag.Rssi = Convert.ToInt32(msg.TagReportData[i].PeakRSSI.PeakRSSI.ToString());
                            tag.ReadCount = msg.TagReportData[i].TagSeenCount.TagCount;

                            int chIndex = Convert.ToInt32(msg.TagReportData[i].ChannelIndex.ChannelIndex);
                            List<uint> freq = frequencyHopTable[0].Frequency.data;
                            tag._frequency = Convert.ToInt32(freq[chIndex - 1]);
                            UNION_AccessCommandOpSpecResult opSpecResult = msg.TagReportData[i].AccessCommandOpSpecResult;

                            tag._data = EMPTY_DATA;
                            // Use try-finally to to keep failed tagops from preventing report of TagReadData
                            try
                            {
                                if (null != opSpecResult)
                                {
                                    if (opSpecResult.Count > 0)
                                    {
                                        ParseTagOpSpecResultType(opSpecResult, ref tag);
                                    }
                                }
                            }
                            finally
                            {
                                if (continuousReading)
                                {
                                    OnTagRead(tag);
                                }
                                else
                                {
                                    tagReads.Add(tag);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ReaderException rx;
                        if (ex is ReaderException)
                        {
                            rx = (ReaderException)ex;
                        }
                        else
                        {
                            rx = new ReaderException(ex.ToString());
                        }
                        //Release the TagQueueEmptyEvent when parsing exception raised
                        TagQueueEmptyEvent.Set();
                        ReadExceptionPublisher expub = new ReadExceptionPublisher(this, rx);

                        Thread trd = new Thread(expub.OnReadException);
                        trd.Name = "OnReadException";
                        trd.Start();
                    }
                    finally
                    {
                        tag = null;
                    }
                }
                TagQueueEmptyEvent.Set();
            }
        }
        private void btnWriteAccessPwd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);

                if (txtbxAccesspaasword.Text.Length <= 0)
                {
                    MessageBox.Show("Access password can't be empty", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                if ((bool)rbFirstTagLockTagTb.IsChecked)
                {
                    antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
                }

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

                if ((bool)rbSelectedTagLockTagTb.IsChecked)
                {
                    TagFilter searchSelect = null;


                    if (selectMemBank == Gen2.Bank.EPC)
                    {
                        searchSelect = new TagData(txtEpc.Text);
                    }
                    else
                    {
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null == SearchSelectData)
                        {
                            dataLength = 0;
                        }
                        else
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(accessPwddStartAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                    WriteAccessPassword(searchSelect);
                }
                else
                {
                    WriteAccessPassword(null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            } 
        }  
示例#17
0
        static void Main(string[] args)
        {
            // Program setup
            if (args.Length != 1)
            {
                Console.WriteLine("Please provide reader URL, such as:\n"
                                 + "tmr:///com4\n"
                                 + "tmr://my-reader.example.com\n");
                Environment.Exit(1);
            }

            // Create Reader object, connecting to physical device
            try
            {
                Reader r;
                TagReadData[] tagReads, filteredTagReads;
                TagFilter filter;

                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]);
                    }
                }

                // In the current system, sequences of Gen2 operations require Session 0,
                // since each operation resingulates the tag.  In other sessions,
                // the tag will still be "asleep" from the preceding singulation.
                Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session");
                Gen2.Session newSession = Gen2.Session.S0;
                Console.WriteLine("Changing to Session "+newSession+" (from Session "+oldSession+")");
                r.ParamSet("/reader/gen2/session", newSession);
                Console.WriteLine();

                try
                {
                    Console.WriteLine("Unfiltered Read:");
                    // Read the tags in the field
                    tagReads = r.Read(500);
                    foreach (TagReadData tr in tagReads)
                        Console.WriteLine(tr.ToString());
                    Console.WriteLine();

                    if (0 == tagReads.Length)
                    {
                        Console.WriteLine("No tags found.");
                    }
                    else
                    {
                        // A TagData object may be used as a filter, for example to
                        // perform a tag data operation on a particular tag.
                        Console.WriteLine("Filtered Tagop:");
                        // Read kill password of tag found in previous operation
                        filter = tagReads[0].Tag;
                        Console.WriteLine("Read kill password of tag {0}", filter);
                        Gen2.ReadData tagop = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2);
                        try
                        {
                            ushort[] data = (ushort[])r.ExecuteTagOp(tagop, filter);
                            foreach (ushort word in data)
                            {
                                Console.Write("{0:X4}", word);
                            }
                            Console.WriteLine();
                        }
                        catch (ReaderException ex)
                        {
                            Console.WriteLine("Can't read tag: {0}", ex.Message);
                        }
                        Console.WriteLine();


                        // Filter objects that apply to multiple tags are most useful in
                        // narrowing the set of tags that will be read. This is
                        // performed by setting a read plan that contains a filter.

                        // A TagData with a short EPC will filter for tags whose EPC
                        // starts with the same sequence.
                        filter = new TagData(tagReads[0].Tag.EpcString.Substring(0, 4));
                        Console.WriteLine("EPCs that begin with {0}:", filter);
                        r.ParamSet("/reader/read/plan",
                            new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                            Console.WriteLine(tr.ToString());
                        Console.WriteLine();

                        // A filter can also be an full Gen2 Select operation.  For
                        // example, this filter matches all Gen2 tags where bits 8-19 of
                        // the TID are 0x003 (that is, tags manufactured by Alien
                        // Technology).
                        Console.WriteLine("Tags with Alien Technology TID");
                        filter = new Gen2.Select(false, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 });
                        r.ParamSet("/reader/read/plan", new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                            Console.WriteLine(tr.ToString());
                        Console.WriteLine();

                        // Gen2 Select may also be inverted, to give all non-matching tags
                        Console.WriteLine("Tags without Alien Technology TID");
                        filter = new Gen2.Select(true, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 });
                        r.ParamSet("/reader/read/plan", new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                            Console.WriteLine(tr.ToString());
                        Console.WriteLine();

                        // Filters can also be used to match tags that have already been
                        // read. This form can only match on the EPC, as that's the only
                        // data from the tag's memory that is contained in a TagData
                        // object.
                        // Note that this filter has invert=true. This filter will match
                        // tags whose bits do not match the selection mask.
                        // Also note the offset - the EPC code starts at bit 32 of the
                        // EPC memory bank, after the StoredCRC and StoredPC.
                        filter = new Gen2.Select(true, Gen2.Bank.EPC, 32, 2, new byte[] { (byte)0xC0 });
                        Console.WriteLine("EPCs with first 2 bits equal to zero (post-filtered):");
                        foreach (TagReadData tr in tagReads) // unfiltered tag reads from the first example
                            if (filter.Matches(tr.Tag))
                                Console.WriteLine(tr.ToString());
                        Console.WriteLine();
                    }
                }
                finally
                {
                    // Restore original settings
                    Console.WriteLine("Restoring Session " + oldSession);
                    r.ParamSet("/reader/gen2/session", oldSession);
                }

                // Shut down reader
                r.Destroy();
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
        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);
            }
        }
示例#19
0
 public WriteTagArgs(TagFilter target, TagData epc)
 {
     Target = target;
     Epc = epc;
 }
        private void btnWrite_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                
                if ((bool)rbFirstTag.IsChecked)
                {
                    antenna = ((null != GetSelectedAntennaList()) ? ( GetSelectedAntennaList()[0]) : antenna);
                }

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

                if ((bool)rbSelectedTag.IsChecked)
                {
                    TagFilter searchSelect = null;


                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(txtEpc.Text);
                    }
                    else
                    {
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null == SearchSelectData)
                        {
                            dataLength = 0;
                        }
                        else
                        {
                            dataLength = SearchSelectData.Length;
                        }
                        
                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                    WriteEPC(searchSelect, txtWriteEPC.Text);
                }
                else
                {
                    WriteEPC(null, txtWriteEPC.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
示例#21
0
 /// <summary>
 /// Test if a tag Matches this filter. Only applies to selects based
 /// on the EPC.
 /// </summary>
 /// <param name="t">tag data to screen</param>
 /// <returns>Return true to allow tag through the filter.
 /// Return false to reject tag.</returns>
 public bool Matches(TagData t)
 {
     for (int i = 0 ; i < EpcBytes.Length && i < t.EpcBytes.Length ; i++)
         if (EpcBytes[i] != t.EpcBytes[i])
             return false;
     return true;
 }
        private void SetReadPlan()
        {
           
            TagFilter filter = null;


            if (selectMemBank == Gen2.Bank.EPC) 
            {
                if (txtEpc.Text != "")
                {
                    filter = new TagData(txtEpc.Text);
                }
            }
            else
            {
                byte[] data = ByteFormat.FromHex(txtData.Text);

                if (null == data)
                {
                    dataLength = 0;
                }
                else
                {
                    dataLength = data.Length;
                }

                filter = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), data);
            }
            
            SimpleReadPlan srp = new SimpleReadPlan(new int[]{antenna}, TagProtocol.GEN2, filter, 1000);
            objReader.ParamSet("/reader/read/plan", srp);
        }
示例#23
0
 /// <summary>
 /// Constructor to initialize the parameters of WriteTag
 /// </summary>
 /// <param name="epc">the new tag ID to write</param>
 /// 
 public WriteTag(TagData epc)
 {
     this.Epc = epc;
 }
示例#24
0
        public ReadPlan LoadSimpleReadPlan(string valstr)
        {
            Object value = ParseValue(valstr);
            string str   = string.Empty;

            //Reamoves leading string for ex: SimpleReadPlan:
            str = valstr.Remove(0, 15);
            SimpleReadPlan srp = new SimpleReadPlan();
            //Regular expression to remove leading and trailing square brackets
            string remove = Regex.Replace(str, @"]$|^\[", "");

            //Regular expression to split the string
            string[]  lines = Regex.Split(remove, @",(?![^\[\]]*\])");
            TagFilter tf    = null;
            TagOp     op    = null;

            foreach (string line in lines)
            {
                if (-1 != line.IndexOf("Antennas"))
                {
                    ArrayList list    = new ArrayList();
                    int[]     antList = null;
                    object    value1  = ParseValue(line.Split('=')[1]);
                    if (value1 != null)
                    {
                        antList = (int[])((ArrayList)value1).ToArray(typeof(int));
                    }
                    srp.Antennas = antList;
                }
                else if (-1 != line.IndexOf("Protocol"))
                {
                    srp.Protocol = (TagProtocol)Enum.Parse(typeof(TagProtocol), line.Split('=')[1], true);
                }
                else if (-1 != line.IndexOf("Filter"))
                {
                    string filterData = line.Split('=')[1];
                    if (-1 != filterData.IndexOf("Gen2.Select"))
                    {
                        str = line.Remove(0, 19);
                        //Regular expression to remove leading and trailing square brackets
                        str = Regex.Replace(str, @"]$|^\[", "");
                        //Regular expression to split the string
                        string[]  select     = Regex.Split(str, @"[ ,;]+");
                        bool      Invert     = false;
                        Gen2.Bank bank       = Gen2.Bank.EPC;
                        uint      BitPointer = 0;
                        ushort    BitLength  = 0;
                        byte[]    mask       = null;
                        if (select.Length != 5)
                        {
                            throw new Exception("Invalid number of arguments for ReadPlan filter");
                        }
                        foreach (string arg in select)
                        {
                            if (-1 != arg.IndexOf("Invert"))
                            {
                                Invert = Convert.ToBoolean(arg.Split('=')[1]);
                            }
                            else if (-1 != arg.IndexOf("Bank"))
                            {
                                bank = (Gen2.Bank)Enum.Parse(typeof(Gen2.Bank), arg.Split('=')[1], true);
                            }
                            else if (-1 != arg.IndexOf("BitPointer"))
                            {
                                BitPointer = Convert.ToUInt32(arg.Split('=')[1]);
                            }
                            else if (-1 != arg.IndexOf("BitLength"))
                            {
                                BitLength = Convert.ToUInt16(arg.Split('=')[1]);
                            }
                            else if (-1 != arg.IndexOf("Mask"))
                            {
                                mask = StringToByteArray(arg.Split('=')[1]);
                            }
                            else
                            {
                                throw new Exception("Invalid Argument in ReadPlan");
                            }
                        }
                        tf = new Gen2.Select(Invert, bank, BitPointer, BitLength, mask);
                    }
                    else if (-1 != filterData.IndexOf("EPC"))
                    {
                        str = line.Remove(0, 15);
                        str = Regex.Replace(str, @"]$|^\[", "");
                        tf  = new TagData(StringToByteArray((str.Split('=')[1])));
                    }
                    else
                    {
                        if (!filterData.Equals("null"))
                        {
                            throw new Exception("Invalid Argument in ReadPlan");
                        }
                    }
                }
                else if (-1 != line.IndexOf("Op"))
                {
                    string tagOpData = line.Split('=')[1];
                    if (tagOpData != null)
                    {
                        if (-1 != tagOpData.IndexOf("ReadData"))
                        {
                            str = line.Remove(0, 12);
                            //Regular expression to remove leading and trailing square brackets
                            str = Regex.Replace(str, @"]$|^\[", "");
                            //Regular expression to split the string
                            string[]  select      = Regex.Split(str, @"[ ,;]+");
                            Gen2.Bank bank        = Gen2.Bank.EPC;
                            uint      wordAddress = 0;
                            byte      length      = 0;
                            foreach (string arg in select)
                            {
                                if (-1 != arg.IndexOf("Bank"))
                                {
                                    bank = (Gen2.Bank)Enum.Parse(typeof(Gen2.Bank), arg.Split('=')[1], true);
                                }
                                else if (-1 != arg.IndexOf("WordAddress"))
                                {
                                    wordAddress = Convert.ToUInt32(arg.Split('=')[1]);
                                }
                                else if (-1 != arg.IndexOf("Len"))
                                {
                                    length = Convert.ToByte(arg.Split('=')[1]);
                                }
                                else
                                {
                                    throw new Exception("Invalid Argument in ReadPlan TagOp");
                                }
                            }
                            op = new Gen2.ReadData(bank, wordAddress, length);
                        }
                        else
                        {
                            if (!tagOpData.Equals("null"))
                            {
                                throw new Exception("Invalid Argument in ReadPlan");
                            }
                        }
                    }
                }
                else if (-1 != line.IndexOf("UseFastSearch"))
                {
                    srp.UseFastSearch = Convert.ToBoolean(line.Split('=')[1]);
                }
                else if (-1 != line.IndexOf("Weight"))
                {
                    srp.Weight = Convert.ToInt32(lines[5].Split('=')[1]);
                }
                else
                {
                    throw new Exception("Invalid Argument in ReadPlan");
                }
            }
            srp.Filter = tf;
            srp.Op     = op;
            return(srp);
        }