예제 #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 btnTagAction_Click(object sender, EventArgs e)
        {
            int  back      = 0;
            uint BlockSize = 0;

            byte[] Data     = null;
            byte[] respData = null;
            Dictionary <string, FedmIscTagHandler> .ValueCollection listTagHandler;

            if (!connected)
            {
                return;
            }

            listTagHandler = TagList.Values;
            foreach (FedmIscTagHandler tag in listTagHandler)
            {
                if (tag is FedmIscTagHandler_ISO15693)
                {
                    FedmIscTagHandler_ISO15693 newTag = (FedmIscTagHandler_ISO15693)tag;
                    Console.WriteLine(newTag.GetTagName());

                    // read data blocks and write same data back to tag
                    back = newTag.ReadMultipleBlocks((uint)4, (uint)4, out BlockSize, out Data);
                    back = newTag.WriteMultipleBlocks(4, 4, 4, Data);
                }
                else if (tag is FedmIscTagHandler_ISO14443)
                {
                    FedmIscTagHandler newTag = null;

                    // execute a select command for MIFARE DESFire
                    // TagSelect creates a new TagHandler object internally
                    newTag = Reader.TagSelect(tag, 9);

                    if (newTag is FedmIscTagHandler_ISO14443_4_MIFARE_DESFire)
                    {
                        FedmIscTagHandler_ISO14443_4_MIFARE_DESFire desfireTag = (FedmIscTagHandler_ISO14443_4_MIFARE_DESFire)newTag;

                        Console.WriteLine(desfireTag.GetTagName());

                        // read version information
                        // use the internal Interface IFlexSoftCrypto
                        back = desfireTag.IFlexSoftCrypto.GetVersion((byte)0, out respData);
                    }
                }
                else if (tag is OBID.TagHandler.FedmIscTagHandler_EPC_Class1_Gen2)
                {
                    FedmIscTagHandler_EPC_Class1_Gen2 newTag = (FedmIscTagHandler_EPC_Class1_Gen2)tag;
                    Console.WriteLine(newTag.GetTagName());

                    // write a new EPC number (without password)
                    back = newTag.WriteEPC("1102030405060708090A0B0C", "");
                }
            }
        }
예제 #3
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());
                }
            }
        }