コード例 #1
0
        /// <summary>
        /// Read tag memory for readers or modules other the M5e variants
        /// </summary>
        /// <param name="bank">Gen2 memory bank</param>
        /// <param name="filter">filter</param>
        /// <param name="MemData">Data read from tag memory</param>
        private void ReadMemoryM6eVariants(Gen2.Bank bank, TagFilter filter, ref ushort[] MemData)
        {
            try
            {
                // Read tag memory with zero as start address and lenght of words to read as zero
                TagOp op = new Gen2.ReadData(bank, 0, 0);
                MemData = (ushort[])objectReader.ExecuteTagOp(op, filter);

                if (MemData.Length < 64)
                {
                    // If data read is less then 64 words, then perform read word by word to make sure
                    // all the data is read from the tag memory
                    ReadTagMemoryWordByWord(bank, filter, ref MemData);
                }
                else
                {
                    // If data read is more then 64 words then perform read with start address as 64 words
                    // and length as zero
                    ReadLargeTagMemory(bank, filter, ref MemData);
                }
            }
            catch (Exception ex)
            {
                if ((ex is FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception) || ((ex is FAULT_NO_TAGS_FOUND_Exception)))
                {
                    // Perform read when the tag has mem more then 128 bytes and doesn't support
                    // Zero start address and number of words to read as zero
                    ReadLargeTagMemoryWithoutZeroLengthSupport(bank, filter, ref MemData);
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Load Authentication memory to insert and activate keys
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="address"></param>
        /// <param name="selectedBank"></param>
        /// <param name="selectedTagRed"></param>
        /// <param name="readerModel"></param>
        public void LoadAuthenticateMemory(Reader reader, uint address, Gen2.Bank selectedBank, TagReadRecord selectedTagRed, string readerModel)
        {
            objReader    = reader;
            startAddress = address;
            model        = readerModel;

            spAuthenticate.IsEnabled              = true;
            rbFirstTagAuthenticateTb.IsEnabled    = true;
            rbSelectedTagAuthenticateTb.IsChecked = true;
            rbSelectedTagAuthenticateTb.IsEnabled = true;

            btnRead.Content       = "Refresh";
            selectedTagReadRecord = selectedTagRed;
            antenna       = selectedTagRed.Antenna;
            selectMemBank = selectedBank;
            //txtEPCData.Text = selectedTagRed.EPC;
            string[] stringData = selectedTagRed.Data.Split(' ');
            txtEpc.Text  = selectedTagRed.EPC;
            currentEPC   = txtEpc.Text;
            txtData.Text = string.Join("", stringData);
            Window       mainWindow = App.Current.MainWindow;
            ucTagResults tagResults = (ucTagResults)mainWindow.FindName("TagResults");

            switch (selectedBank)
            {
            case Gen2.Bank.EPC:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "Showing tag: EPC data at decimal address " + address.ToString() + "  = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                }
                break;

            case Gen2.Bank.TID:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "Showing tag: TID data at decimal address " + address.ToString() + " = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                }
                break;

            case Gen2.Bank.USER:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "Showing tag: User data at decimal address " + address.ToString() + " = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                }
                break;
            }
            PopulateAuthenticateData();
        }
コード例 #3
0
ファイル: ucWriteEPC.xaml.cs プロジェクト: shahbazp12/Samples
        public void Load(Reader reader, uint address, int length, Gen2.Bank selectedBank, TagReadRecord selectedTagRed)
        {
            InitializeComponent();
            objReader     = reader;
            startAddress  = address;
            dataLength    = length;
            selectMemBank = selectedBank;

            spWriteEPC.IsEnabled    = true;
            rbSelectedTag.IsChecked = true;
            rbSelectedTag.IsEnabled = true;

            string[] stringData = selectedTagRed.Data.Split(' ');
            txtEpc.Text  = selectedTagRed.EPC;
            txtData.Text = string.Join("", stringData);
            Window       mainWindow = App.Current.MainWindow;
            ucTagResults tagResults = (ucTagResults)mainWindow.FindName("TagResults");

            switch (selectedBank)
            {
            case Gen2.Bank.EPC:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "EPC Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                }
                break;

            case Gen2.Bank.TID:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "TID Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                }
                break;

            case Gen2.Bank.USER:
                if (tagResults.txtSelectedCell.Text == "Data")
                {
                    lblSelectFilter.Content = "User Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                }
                else
                {
                    lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                }
                break;
            }
            txtCurrentEpc.Text = selectedTagRed.EPC;
            currentEpc         = txtCurrentEpc.Text;
            antenna            = selectedTagRed.Antenna;
        }
コード例 #4
0
        /// <summary>
        /// Load reserved memory to get access password of the tag
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="address"></param>
        /// <param name="selectedBank"></param>
        /// <param name="selectedTagRed"></param>
        /// <param name="readerModel"></param>
        public void LoadReservedMemory(Reader reader, uint address, Gen2.Bank selectedBank, TagReadRecord selectedTagRed, string readerModel)
        {
            objReader = reader;
            accessPwddStartAddress = address;
            model = readerModel;
            spLockTag.IsEnabled = true;
            rbFirstTagLockTagTb.IsEnabled = true;
            rbSelectedTagLockTagTb.IsChecked = true;
            rbSelectedTagLockTagTb.IsEnabled = true;

            btnRead.Content = "Refresh";
            selectedTagReadRecord = selectedTagRed;
            antenna = selectedTagRed.Antenna;
            selectMemBank = selectedBank;
            //txtEPCData.Text = selectedTagRed.EPC;
            string[] stringData = selectedTagRed.Data.Split(' ');
            txtEpc.Text = selectedTagRed.EPC;
            currentEPC = txtEpc.Text;
            txtData.Text = string.Join("", stringData);
            Window mainWindow = App.Current.MainWindow;
            ucTagResults tagResults = (ucTagResults)mainWindow.FindName("TagResults");
            switch (selectedBank)
            {
                case Gen2.Bank.EPC:
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "Showing tag: EPC data at decimal address " + address.ToString() + "  = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                    }
                    break;
                case Gen2.Bank.TID:
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "Showing tag: TID data at decimal address " + address.ToString() + " = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                    }
                    break;
                case Gen2.Bank.USER:
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "Showing tag: User data at decimal address " + address.ToString() + " = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "Showing tag: EPC ID = " + selectedTagRed.EPC;
                    }
                    break;
            }
            PopulateUserData();
        }
コード例 #5
0
        public void Load(Reader reader,uint address, int length, Gen2.Bank selectedBank,TagReadRecord selectedTagRed)
        {
            InitializeComponent();
            objReader = reader;
            startAddress = address;
            dataLength = length;
            selectMemBank = selectedBank;

            spWriteEPC.IsEnabled = true;
            rbSelectedTag.IsChecked = true;
            rbSelectedTag.IsEnabled = true;
            
            string[] stringData = selectedTagRed.Data.Split(' ');
            txtEpc.Text = selectedTagRed.EPC;
            txtData.Text = string.Join("", stringData);
            Window mainWindow = App.Current.MainWindow;
            ucTagResults tagResults = (ucTagResults)mainWindow.FindName("TagResults");
            switch(selectedBank)
            {
                case Gen2.Bank.EPC:                    
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "EPC Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                    }
                    break;
                case Gen2.Bank.TID:
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "TID Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                    }
                    break;
                case Gen2.Bank.USER:
                    if (tagResults.txtSelectedCell.Text == "Data")
                    {
                        lblSelectFilter.Content = "User Memory, Decimal Address = " + address.ToString() + " and Data = " + txtData.Text;
                    }
                    else
                    {
                        lblSelectFilter.Content = "EPC ID = " + selectedTagRed.EPC;
                    }                    
                    break;
            }            
            txtCurrentEpc.Text = selectedTagRed.EPC;
            currentEpc = txtCurrentEpc.Text;
            antenna = selectedTagRed.Antenna;
        }
コード例 #6
0
 /// <summary>
 /// Read specified tag memory bank
 /// </summary>
 /// <param name="bank">Gen2 bank</param>
 /// <param name="filter">filter</param>
 /// <param name="MemData">Data read from the tag memory</param>
 public void ReadTagMemoryData(Gen2.Bank bank, TagFilter filter, ref ushort[] MemData)
 {
     if (modelReader.Equals("M5e") || modelReader.Equals("M5e EU") || modelReader.Equals("M5e Compact") || modelReader.Equals("M5e PRC") || modelReader.Equals("Astra"))
     {
         // Read tag memory word by word for M5e variants
         ReadMemoryM5eVariants(bank, filter, ref MemData);
     }
     else
     {
         // Read tag memory for m6e variants
         ReadMemoryM6eVariants(bank, filter, ref MemData);
     }
 }
コード例 #7
0
 /// <summary>
 /// Read tag memory word by word. If FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception
 /// or Non-specific reader error or General Tag Error or Tag data access failed exception
 /// is received. Memory reading is stopped and the already read data is returned
 /// </summary>
 /// <param name="bank">Gen2 memory bank</param>
 /// <param name="filter">Select filter</param>
 /// <param name="data">Read tag memory data is returned</param>
 private void ReadTagMemoryWordByWord(Gen2.Bank bank, TagFilter filter, ref ushort[] data)
 {
     lock (new Object())
     {
         List <ushort> dataTemp     = new List <ushort>();
         uint          startaddress = 0;
         if (data != null)
         {
             // if the data variable already contains the data, then add that data
             // to data temp and change the start address to total data length
             dataTemp.AddRange(data);
             startaddress = (uint)data.Length;
         }
         int   words = 1;
         TagOp op;
         bool  isAllDataReceived = false;
         while (false == isAllDataReceived)
         {
             try
             {
                 // Read tag memory word by word
                 op = new Gen2.ReadData(bank, startaddress, Convert.ToByte(words));
                 dataTemp.AddRange(((ushort[])objectReader.ExecuteTagOp(op, filter)));
                 startaddress += 1;
             }
             catch (Exception exception)
             {
                 if (exception is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != exception.Message.IndexOf("Non-specific reader error")) || (-1 != exception.Message.IndexOf("General Tag Error")) || (-1 != exception.Message.IndexOf("Tag data access failed")) || (exception.Message.Contains("Tag memory overrun error") ||
                                                                                                                                                                                                                                                                                     (exception.Message.Contains("Gen2 unspecific error"))))
                 {
                     if (dataTemp.Count > 0)
                     {
                         // Just skip the exception and move on. So as not to lose the already read data.
                         isAllDataReceived = true;
                     }
                     else
                     {
                         // throw the exception if the data received is null for the first iteration itself
                         throw;
                     }
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         data = dataTemp.ToArray();
     }
 }
コード例 #8
0
        // read multiple registers from one tag singulated by its EPC
        public static short[] ReadMemBlockByEpc(Reader reader, TagReadData tag, Gen2.Bank bank, int address, int length, int attempts)
        {
            Gen2.Select resetFilter = CreateGen2Select(4, 4, Gen2.Bank.TID, 0x00, 16, new byte[] { 0xE2, 0x82 });
            Gen2.Select epcFilter   = CreateGen2Select(4, 0, Gen2.Bank.EPC, 0x20, tag.Epc.Length * 8, tag.Epc);
            MultiFilter selects     = new MultiFilter(new Gen2.Select[] { resetFilter, epcFilter });

            Gen2.ReadData  operation = new Gen2.ReadData(bank, (uint)address, (byte)length);
            SimpleReadPlan config    = new SimpleReadPlan(new int[] { tag.Antenna }, TagProtocol.GEN2, selects, operation, 1000);

            short[] values = null;
            try
            {
                reader.ParamSet("/reader/read/plan", config);
                for (int i = 0; i < attempts; i++)
                {
                    if (values != null)
                    {
                        break;
                    }
                    TagReadData[] readResults = reader.Read(readTime);
                    foreach (TagReadData readResult in readResults)
                    {
                        if (tag.EpcString.Equals(readResult.EpcString))
                        {
                            byte[] dataBytes = readResult.Data;
                            if (dataBytes.Length != 0)
                            {
                                values = ConvertByteArrayToShortArray(dataBytes);
                                break;
                            }
                        }
                    }
                }
            }
            catch (ReaderException e)
            {
                Console.WriteLine("Error: " + e.ToString());
                Environment.Exit(-1);
            }
            if (values == null)
            {
                throw new SystemException("Tag not found");
            }
            return(values);
        }
コード例 #9
0
        /// <summary>
        /// Read additional reserved memory for m5e variants
        /// </summary>
        /// <param name="bank"></param>
        /// <param name="startAddress"></param>
        /// <param name="filter"></param>
        /// <param name="data"></param>
        private void ReadAdditionalReservedMemDataM5eVariants(Gen2.Bank bank, uint startAddress, TagFilter filter, out ushort[] data)
        {
            data = null;
            int   words = 1;
            TagOp op;

            while (true)
            {
                try
                {
                    op   = new Gen2.ReadData(bank, startAddress, Convert.ToByte(words));
                    data = (ushort[])objReader.ExecuteTagOp(op, filter);
                    words++;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Read tag memory for M5e Variants. If FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception
 /// or Non-specific reader error or General Tag Error or Tag data access failed exception
 /// is received. Memory reading is stopped and the already read data is returned
 /// </summary>
 /// <param name="bank">Gen2 memory bank</param>
 /// <param name="filter">Select filter</param>
 /// <param name="data">Read tag memory data is returned</param>
 private void ReadMemoryM5eVariants(Gen2.Bank bank, TagFilter filter, ref ushort[] data)
 {
     lock (new Object())
     {
         List <ushort> dataTemp     = new List <ushort>();
         uint          startaddress = 0;
         int           words        = 64;
         if (data != null)
         {
             // if the data variable already contains the data, then add that data
             // to data temp and change the start address to total data length
             dataTemp.AddRange(data);
             startaddress = (uint)data.Length;
         }
         TagOp op;
         bool  isAllDataReceived = false;
         while (false == isAllDataReceived)
         {
             try
             {
                 // Read tag memory
                 op = new Gen2.ReadData(bank, startaddress, Convert.ToByte(words));
                 dataTemp.AddRange(((ushort[])objectReader.ExecuteTagOp(op, filter)));
                 startaddress += 64;
             }
             catch (Exception exception)
             {
                 if (exception is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != exception.Message.IndexOf("Non-specific reader error")) || (-1 != exception.Message.IndexOf("General Tag Error")) || (-1 != exception.Message.IndexOf("Tag data access failed")))
                 {
                     data = dataTemp.ToArray();
                     ReadTagMemoryWordByWord(bank, filter, ref data);
                     isAllDataReceived = true;
                 }
                 else
                 {
                     throw;
                 }
             }
         }
     }
 }
コード例 #11
0
ファイル: Gen2.cs プロジェクト: colombmo/itsi-gamification
 /// <summary>
 /// Erase tag specific block
 /// </summary>
 /// <param name="bank">the tag memory bank to erase</param>
 /// <param name="wordPtr">the word address to start erase to</param>
 /// <param name="wordCount">no of words to erase</param>
 public BlockErase(Gen2.Bank bank, UInt32 wordPtr, byte wordCount)
 {
     this.Bank = bank;
     this.WordPtr = wordPtr;
     this.WordCount = wordCount;                
 }
コード例 #12
0
ファイル: Gen2.cs プロジェクト: colombmo/itsi-gamification
            /// <summary>
            /// Constructor to initialize the parameters of BlockPermaLock
            /// </summary>
            /// <param name="readLock">Read or Lock?</param>
            /// <param name="bank">Gen2 Memory Bank to perform Lock</param>
            /// <param name="blockPtr">starting address of the blocks to operate</param>
            /// <param name="blockRange">number of 16 blocks</param>
            /// <param name="mask">mask</param>
         
            public BlockPermaLock(byte readLock,Gen2.Bank bank, uint blockPtr, byte blockRange, ushort[] mask)
            {
                this.ReadLock = readLock;
                this.Bank = bank;
                this.BlockPtr = blockPtr;
                this.BlockRange = blockRange;
                this.Mask = mask;

            }
コード例 #13
0
ファイル: Gen2.cs プロジェクト: colombmo/itsi-gamification
 /// <summary>
 /// Constructor to initialize the parameters of BlockWrite
 /// </summary>
 /// <param name="bank">Gen2 memory bank to write to</param>
 /// <param name="wordPtr">the word address to start writing to</param>
 /// <param name="data">the data to write</param>
 public BlockWrite(Gen2.Bank bank, uint wordPtr, ushort[] data)
 {
     this.Bank = bank;
     this.WordPtr=wordPtr;
     this.Data = data;
 }
コード例 #14
0
ファイル: Gen2.cs プロジェクト: colombmo/itsi-gamification
 /// <summary>
 /// Constructor to initialize the parameters of ReadData
 /// </summary>
 /// <param name="bank">The memory bank to read</param>
 /// <param name="wordAddress">Read starting address</param>
 /// <param name="length">The length of data to read</param>
 public ReadData(Gen2.Bank bank, UInt32 wordAddress, byte length)
 {
     this.Bank = bank;
     this.WordAddress = wordAddress;
     this.Len = length;
 }
コード例 #15
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());
            }
        }
コード例 #16
0
 /// <summary>
 /// Read tag memory when tag has more then 64 words or 128 bytes. And module doesn't supports zero address and zero length.
 /// Reads the tag memory with 0 address and length of words as 64. If memory overrun received. Initiates reading of tag
 /// word by word with start address as length of already read data and length of words to read as 0. Returns the data read from
 /// tag memory.
 /// </summary>
 /// <param name="bank">Gen2 memory bank</param>
 /// <param name="filter">filter</param>
 /// <param name="data">Data read from tag memory</param>
 private void ReadLargeTagMemoryWithoutZeroLengthSupport(Gen2.Bank bank, TagFilter filter, ref ushort[] data)
 {
     lock (new Object())
     {
         data = null;
         // Data from tag memory
         List <ushort> dataTemp = new List <ushort>();
         // Number of words to read
         int words = 64;
         // Start address
         uint  startaddress = 0;
         TagOp op;
         bool  isAllDataReceived = false;
         // Read till all the data from the tag memory is read
         while (false == isAllDataReceived)
         {
             try
             {
                 op = new Gen2.ReadData(bank, startaddress, Convert.ToByte(words));
                 dataTemp.AddRange(((ushort[])objectReader.ExecuteTagOp(op, filter)));
                 // Increment the start address to 64 and keep length of words to read as 64 for
                 // all the iterations
                 startaddress += 64;
             }
             catch (Exception ex)
             {
                 try
                 {
                     if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != ex.Message.IndexOf("Non-specific reader error")) || (-1 != ex.Message.IndexOf("General Tag Error")) || (-1 != ex.Message.IndexOf("Tag data access failed")))
                     {
                         // If the memory to read requested is more then the available memory in the tag, then initiate
                         // reading the tag memory word by word with start address as length of already read data if exists
                         // and length of words to read is 1
                         if (dataTemp.Count > 0)
                         {
                             // If some data is already read then include this data also so that
                             // reading of memory doesn't continue from zero and the list should
                             // not contain same data twice
                             data = dataTemp.ToArray();
                         }
                         ReadTagMemoryWordByWord(bank, filter, ref data);
                         // Come out of main while loop. And read the already read data
                         isAllDataReceived = true;
                     }
                     else
                     {
                         throw;
                     }
                 }
                 catch (Exception exception)
                 {
                     // If more then once the below exceptions are received then come out of the loop.
                     if (exception is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != exception.Message.IndexOf("Non-specific reader error")) || (-1 != exception.Message.IndexOf("General Tag Error")) || (-1 != exception.Message.IndexOf("Tag data access failed")))
                     {
                         if (dataTemp.Count > 0)
                         {
                             // Just skip the exception and move on. So as not to lose the already read data.
                             isAllDataReceived = false;
                         }
                         else
                         {
                             // throw the exception if the data received is null for the first iteration itself
                             throw;
                         }
                     }
                     else
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
コード例 #17
0
 // read one register from one tag singulated by its EPC
 public static short ReadMemByEpc(Reader reader, TagReadData tag, Gen2.Bank bank, int address, int attempts)
 {
     short[] values = ReadMemBlockByEpc(reader, tag, bank, address, 1, attempts);
     return(values[0]);
 }
コード例 #18
0
 /// <summary>
 /// Read tag memory which has more then 64 words or 128 bytes. Returns the data read from tag memory.
 /// Stops reading the tag memory if FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception exception is received
 /// more then once. If the data read from tag memory is less then 64 words then initiates reading tag
 /// memory word by word
 /// </summary>
 /// <param name="bank"> Gen2 memory bank</param>
 /// <param name="filter">filter</param>
 /// <param name="data">Memory data obtained from the tag</param>
 private void ReadLargeTagMemory(Gen2.Bank bank, TagFilter filter, ref ushort[] data)
 {
     lock (new Object())
     {
         List <ushort> dataTemp = new List <ushort>();
         if (data != null)
         {
             dataTemp.AddRange(data);
         }
         int   words        = 0;
         uint  startaddress = 64;
         TagOp op;
         bool  isAllDataReceived = false;
         while (false == isAllDataReceived)
         {
             try
             {
                 op = new Gen2.ReadData(bank, startaddress, Convert.ToByte(words));
                 ushort[] tempDataReceived = (ushort[])objectReader.ExecuteTagOp(op, filter);
                 dataTemp.AddRange(tempDataReceived);
                 startaddress += 64;
                 if (tempDataReceived.Length < 64)
                 {
                     isAllDataReceived = true;
                     // If data received is less then 64 words, perform word by word with start address as length
                     // of the data and number of words to read is 1
                     data = dataTemp.ToArray();
                     ReadTagMemoryWordByWord(bank, filter, ref data);
                 }
             }
             catch (Exception ex)
             {
                 if (ex is FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception)
                 {
                     try
                     {
                         // If read is success then continue the while loop with incremented start address and length as 0
                         words = 64;
                         op    = new Gen2.ReadData(bank, startaddress, Convert.ToByte(words));
                         dataTemp.AddRange(((ushort[])objectReader.ExecuteTagOp(op, filter)));
                         startaddress += 64;
                         words         = 0;
                     }
                     catch (Exception et)
                     {
                         // If consecutively we get FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception exception blindly come out of the loop to avoid
                         // dead lock
                         if (et is FAULT_PROTOCOL_BIT_DECODING_FAILED_Exception)
                         {
                             isAllDataReceived = true;
                         }
                         else
                         {
                             throw;
                         }
                     }
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         data = dataTemp.ToArray();
     }
 }
コード例 #19
0
        private void ReadReservedMemData(Gen2.Bank bank, TagFilter filter)
        {
            ushort [] reservedData;
            TagOp     op;

            try
            {
                try
                {
                    // Read kill password
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    if (null != reservedData)
                    {
                        txtKillPassword.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }
                    else
                    {
                        txtKillPassword.Text = "";
                    }
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtKillPassword.Text = "Read Error";
                    }
                    else
                    {
                        txtKillPassword.Text = ex.Message;
                    }
                }

                try
                {
                    // Read access password
                    reservedData = null;
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    if (null != reservedData)
                    {
                        txtAcessPassword.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }
                    else
                    {
                        txtAcessPassword.Text = "";
                    }
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtAcessPassword.Text = "Read Error";
                    }
                    else
                    {
                        txtAcessPassword.Text = ex.Message;
                    }
                }

                // Read additional memory password
                try
                {
                    reservedData = null;
                    if (model.Equals("M5e") || model.Equals("M5e EU") || model.Equals("M5e Compact") || model.Equals("M5e PRC") || model.Equals("Astra"))
                    {
                        ReadAdditionalReservedMemDataM5eVariants(Gen2.Bank.RESERVED, 4, filter, out reservedData);
                    }
                    else
                    {
                        op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 4, 0);
                        reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    }

                    if (null != reservedData)
                    {
                        txtReservedMemUnusedValue.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                        // Visible additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Visible;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Visible;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        txtReservedMemUnusedValue.Text = "";
                    }
                }
                catch
                {
                    // catch the exception and move on. Only some tags has aditional memory
                    txtReservedMemUnusedValue.Text = "";
                    // Hide additional memory textboxes
                    lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                    txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                    lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #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
ファイル: RFIDScanner.cs プロジェクト: ediux/WBeParkingPDA
        public void EnableReader()
        {
            try
            {
                // Make sure reader is connected
                _ObjReader = ReadMgr.GetReader();

                if (_ObjReader == null)
                {
                    //if (scannerstatuslabel != null)
                    //{
                    //    scannerstatuslabel.Text = "RFID Reader Failed!";
                    //    scannerstatuslabel.Visible = true;
                    //}
                    if (OnTagReadException != null)
                    {
                        OnTagReadException.Invoke(this, new ReaderExceptionEventArgs(new ReaderException("RFID Reader Failed!")));
                    }
                    return;
                }

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

                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    // MCS++
                    //Check the battery power level
                    switch (BatteryStatusCheck())
                    {
                    case 1:         //Battery percentage low
                        throw new Exception("Battery level is too low to read tags.");

                    //MessageBox.Show();
                    //return;
                    case 2:         //Battery Voltage low
                        throw new Exception("Battery voltage is too low to read tags.");
                        //MessageBox.Show();
                        //return;
                    }
                    // MCS--

                    properties["isreading"] = "yes";
                    Utility.SaveConfigurations(properties);

                    //disable read power coverage

                    ReadMgr.GetReader().ParamSet("/reader/transportTimeout", 2000);
                    string storagevalue = properties["readpower"];
                    int    powerLevel   = Convert.ToInt32(storagevalue);
                    ReadMgr.GetReader().ParamSet("/reader/radio/readPower", powerLevel);
                    Utility.SwitchRegion(properties["region"]);
                    // MCS++
#if MCS_NOMAD
                    ReadMgr.GetReader().ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 1, 1, 1 } });
                    ant.Add(1);
#else
                    // MCS++ - Will we use 1 or 2 antenna?
                    ReadMgr.GetReader().ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 2, 2, 2 } });
                    // MCS--
#endif
                    // MCS--
                    SimpleReadPlan plan = new SimpleReadPlan(ant.ToArray(), TagProtocol.GEN2);
                    ReadMgr.GetReader().ParamSet("/reader/read/plan", plan);

                    //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)
                    {
                        Utility.SetReaderSettings(ReadMgr.GetReader(), properties);
                    }
                    else
                    {
                        throw new Exception("properties are null");
                    }
                    //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"]));
                    }

                    // MCS++
#if MCS_NOMAD
                    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);
#else
                    // MCS++ - use antenna 2
                    SimpleReadPlan srp;
                    if (properties["tagselection"].ToLower() == "none")
                    {
                        //srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, null, 0);
                        srp = new SimpleReadPlan(new int[] { 2 }, TagProtocol.GEN2, null, 0);
                    }
                    else
                    {
                        //srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, filter, 0);
                        srp = new SimpleReadPlan(new int[] { 2 }, TagProtocol.GEN2, filter, 0);
                    }
                    ReadMgr.GetReader().ParamSet("/reader/read/plan", srp);
                    // MCS--
#endif
                    // MCS--
                    ReadMgr.GetReader().ReadException += _ObjReader_ReadException;
                    ReadMgr.GetReader().TagRead       += _ObjReader_TagRead;
                    ReadMgr.GetReader().StartReading();
                }
                catch (Exception ex)
                {
                    writeErrorLog(ex.Message, ex);
                    ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.MAXSAVE);
                    properties["isreading"] = "no";
                    Utility.SaveConfigurations(properties);
                    throw ex;
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                writeErrorLog(ex.ToString(), ex);
                if (-1 != ex.Message.IndexOf("RFID reader was not found"))
                {
                    //MessageBox.Show(ex.Message, "Error");
                    throw ex;
                }
                else
                {
                    properties["isreading"] = "no";
                    Utility.SaveConfigurations(properties);
                    throw ex;
                }
            }
        }
コード例 #22
0
        // create an RFID Gen2 Select Command with custom parameters
        public static Gen2.Select CreateGen2Select(int target, int action, Gen2.Bank bank, int pointer, int length, byte[] mask)
        {
            Gen2.Select select = new Gen2.Select(false, bank, (uint)pointer, (ushort)length, mask);
            switch (target)
            {
            case 0:
                select.target = Gen2.Select.Target.Inventoried_S0;
                break;

            case 1:
                select.target = Gen2.Select.Target.Inventoried_S1;
                break;

            case 2:
                select.target = Gen2.Select.Target.Inventoried_S2;
                break;

            case 3:
                select.target = Gen2.Select.Target.Inventoried_S3;
                break;

            case 4:
                select.target = Gen2.Select.Target.Select;
                break;

            default:
                throw new ArgumentException("invalid target value");
            }
            switch (action)
            {
            case 0:
                select.action = Gen2.Select.Action.ON_N_OFF;
                break;

            case 1:
                select.action = Gen2.Select.Action.ON_N_NOP;
                break;

            case 2:
                select.action = Gen2.Select.Action.NOP_N_OFF;
                break;

            case 3:
                select.action = Gen2.Select.Action.NEG_N_NOP;
                break;

            case 4:
                select.action = Gen2.Select.Action.OFF_N_ON;
                break;

            case 5:
                select.action = Gen2.Select.Action.OFF_N_NOP;
                break;

            case 6:
                select.action = Gen2.Select.Action.NOP_N_ON;
                break;

            case 7:
                select.action = Gen2.Select.Action.NOP_N_NEG;
                break;

            default:
                throw new ArgumentException("invalid action value");
            }
            return(select);
        }
コード例 #23
0
        // read one register from one tag singulated by its EPC
        public static short ReadMemByEpc(Reader reader, TagReadData tag, Gen2.Bank bank, int address)
        {
            short value = ReadMemByEpc(reader, tag, bank, address, 3);

            return(value);
        }
コード例 #24
0
ファイル: Gen2.cs プロジェクト: colombmo/itsi-gamification
 /// <summary>
 /// Constructor to initialize the parameters of WriteData
 /// </summary>
 /// <param name="bank">The memory bank to write</param>
 /// <param name="wordAddress">Write starting address</param>
 /// <param name="data">The data to write</param>
 public WriteData(Gen2.Bank bank, UInt32 wordAddress, ushort[] data)
 {
     this.Bank = bank;
     this.WordAddress = wordAddress;
     this.Data = data;
 }
コード例 #25
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);
        }
コード例 #26
0
 /// <summary>
 /// Read specified tag memory bank
 /// </summary>
 /// <param name="bank">Gen2 bank</param>
 /// <param name="filter">filter</param>
 /// <param name="MemData">Data read from the tag memory</param>
 public static ushort[] ReadTagMemoryData(Reader reader, Gen2.Bank bank, TagFilter filter)
 {
     return(ReadMemoryM6eVariants(reader, bank, filter));
 }
コード例 #27
0
 // read multiple registers from one tag singulated by its EPC
 public static short[] ReadMemBlockByEpc(Reader reader, TagReadData tag, Gen2.Bank bank, int address, int length)
 {
     short[] values = ReadMemBlockByEpc(reader, tag, bank, address, length, 3);
     return(values);
 }