Example #1
0
        /* tasked method which searches for new tasks in the field of the reader
         * adds only distinct chips the the list of scanned tags */
        private void Scanner()
        {
            while (Scanning)
            {
                try
                {
                    var tagList = _reader.TagInventory(true, 0x00, 1);

                    Logger.GetInstance().Log("SC: Tagged Inventory");

                    if (tagList.Count > 0)
                    {
                        Logger.GetInstance().Log($"tagList.Count = {tagList.Count}");
                        var listTagHandler = tagList.Values;

                        foreach (FedmIscTagHandler th in listTagHandler)
                        {
                            if (th == null)
                            {
                                continue;
                            }

                            var tagHandler = th;

                            tagHandler = _reader.TagSelect(tagHandler, 0);
                            Logger.GetInstance().Log("SC: Called TagSelect");

                            if (!(tagHandler is FedmIscTagHandler_ISO15693))
                            {
                                continue;
                            }

                            var scannedTag = (FedmIscTagHandler_ISO15693)tagHandler;

                            lock (_scannedTags)  // lock object because same list is used as return value in asynchronous main thread
                            {
                                if (!_scannedTags.ContainsKey(scannedTag.GetUid()))
                                {
                                    _scannedTags.Add(scannedTag.GetUid(), scannedTag.ToString());       // info about tag gets saved into list if its not already inside
                                }
                            }
                        }

                        System.Threading.Thread.Sleep(100); // if tags could have been found, wait for 100 ms // TODO maybe switch with event based waking up
                    }
                    else
                    {
                        Logger.GetInstance().Log("SC: No Tags received");
                        System.Threading.Thread.Sleep(200); // if no tags could have been found, wait for 200 ms // TODO maybe switch with event based waking up
                    }
                }
                catch (Exception e)
                {
                    Logger.GetInstance().Log("SC: --EXCEPTION caught while scanning: " + e.Message + e.GetType());
                }
            }
        }
        private void btnInventory_Click(object sender, EventArgs e)
        {
            Dictionary <string, FedmIscTagHandler> .ValueCollection listTagHandler;

            if (!connected)
            {
                return;
            }

            // RF-Reset
            Reader.SendProtocol(0x69);

            // execute Inventory for all tags with Mode=0 at first Antenna
            TagList        = Reader.TagInventory(true, 0x00, 0x01);
            listTagHandler = TagList.Values;
            foreach (FedmIscTagHandler tag in listTagHandler)
            {
                Console.WriteLine(tag.GetUid());
            }
        }
Example #3
0
        public string[] TagInventory()
        {
            var tagsInventory = _reader.TagInventory(true, 0x10, Settings.Instance.AntennaByte);

            return(tagsInventory.Keys.Select(key => HexConverter.ConvertHexToAsciiString(key)).ToArray());
        }
Example #4
0
        /* tasked method which searches for new tasks in the field of the reader
         * adds only distinct chips the the list of scanned tags */
        private void Scanner()
        {
            while (Scanning)
            {
                try
                {
                    var tagList = _reader.TagInventory(true, 0x00, 1);

                    if (tagList.Count > 0)
                    {
                        Logger.GetInstance().Log($"tagList.Count = {tagList.Count}");
                        var listTagHandler = tagList.Values;

                        foreach (FedmIscTagHandler th in listTagHandler)
                        {
                            if (th == null)
                            {
                                continue;
                            }

                            FedmIscTagHandler tagHandler;

                            try
                            {
                                tagHandler = _reader.TagSelect(th, 0);
                            }
                            catch (Exception e)
                            {
                                Logger.GetInstance().Log("--Exception caught in SC: " + e.Message);
                                continue;
                            }

                            Logger.GetInstance().Log("SC: Called TagSelect");

                            // Check if the scanned tag is of the correct type
                            if (!(tagHandler is FedmIscTagHandler_ISO15693))
                            {
                                continue;
                            }

                            try
                            {
                                // Create TagData from tag
                                TagData scannedTag = FormatTagHandlerToTagData((FedmIscTagHandler_ISO15693)tagHandler);

                                lock (_scannedTags
                                      ) // lock object because same list is used as return value in asynchronous main thread
                                {
                                    if (!_scannedTags.Contains(scannedTag))
                                    {
                                        _scannedTags
                                        .Add(
                                            scannedTag);     // info about tag gets saved into list if its not already inside
                                        OnNewTagScanned(scannedTag);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.GetInstance().Log("--Exception caught in SC: " + e.Message);
                            }
                        }

                        System.Threading.Thread.Sleep(100); // if tags could have been found, wait for 100 ms
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(200); // if no tags could have been found, wait for 200 ms
                    }
                }
                catch (Exception e)
                {
                    Logger.GetInstance().Log("SC: --EXCEPTION caught while scanning: " + e.Message + e.GetType());
                }
            }
        }