/// <summary>
        /// Handles the SelectedTagChanged event of the nxpTagListView control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void nxpTagListView_SelectedTagChanged(object sender, EventArgs e)
        {
            // Update tag list
            NurApi.Tag selectedTag = nxpTagListView.SelectedTag;
            if (selectedTag != null)
            {
                // Get EPC from selection
                byte[] targetEPC = selectedTag.epc;
                // Fill TargerTag fied
                targetEpcTextBox.Text = NurApi.BinToHexString(targetEPC);
                try
                {
                    // Read NXP configuration word
                    byte[] confWord = hNur.ReadSingulatedTag(0, false, NurApi.BANK_EPC, 32, selectedTag.epc, NurApi.BANK_EPC, 0x200 / 16, 2);
                    configurationLabel.Text = "0x" + NurApi.BinToHexString(confWord);
                }
                catch (NurApiException)
                {
                    configurationLabel.Text = "???";
                }
            }

            // Update button(s)
            UpdateButtons();
        }
Пример #2
0
        /// <summary>
        /// Handles the SelectedTagChanged event of the nxpTagListView control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void nxpTagListView_SelectedTagChanged(object sender, EventArgs e)
        {
            // Update tag list
            NurApi.Tag selectedTag = nxpTagListView.SelectedTag;
            if (selectedTag != null)
            {
                // Get EPC from selection
                byte[] targetEPC = selectedTag.epc;
                try
                {
                    // Get Access password from selected tag
                    uint accessPassword = hNur.GetAccessPassword(0, false, NurApi.BANK_EPC, 32, targetEPC.Length * 8, targetEPC);
                    // Fill Access password fied
                    byte[] accPwdBytes = Utils.ConvertToBigEndiaBytes(accessPassword);
                    accessPasswordTextBox.Text = NurApi.BinToHexString(accPwdBytes);
                }
                catch (Exception)
                {
                    accessPasswordTextBox.Text = "unknown";
                }
                // Fill TargerTag fied
                targetEpcTextBox.Text = NurApi.BinToHexString(targetEPC);
            }

            // Update button(s)
            UpdateButtons();
        }
Пример #3
0
 /// <summary>
 /// Handles the SelectedTagChanged event of the writeTagListView control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void writeTagListView_SelectedTagChanged(object sender, EventArgs e)
 {
     NurApi.Tag selectedTag = writeTagListView.SelectedTag;
     if (selectedTag != null)
     {
         SetTargetTag(NurApi.BANK_EPC, 32, selectedTag.epc);
     }
 }
Пример #4
0
 private void tagListBox_SelectedTagChanged(object sender, EventArgs e)
 {
     NurApi.Tag tag = tagListBox.SelectedTag;
     if (tag != null)
     {
         InitFilter(tag.GetEpcString());
     }
 }
Пример #5
0
 public TagItem(NurApi.Tag tag)
 {
     this.Tag         = tag;
     this.TagViewItem = new ListViewItem(new string[] {
         tag.rssi.ToString(),
         tag.GetEpcString()
     });
     this.TagViewItem.Tag = this;
 }
Пример #6
0
        /// <summary>
        /// Constructor that takes in NurApi and a NurApi.Tag object.
        /// </summary>
        /// <param name="hApi">A valid, connected NurApi object.</param>
        /// <param name="tag">A tag object that is either built by the application or received though an inventory.</param>
        /// <remarks><para>This constructor also creates the BIN arrays.</para></remarks>
        /// <remarks><para>BIN high limits: <seealso cref="BINHLIMIT"/></para></remarks>
        /// <remarks><para>BIN sample times: <seealso cref="BINSAMPLETIME"/></para></remarks>
        /// <remarks><para>BIN thresholds: <seealso cref="BINTHRESHOLD"/></para></remarks>
        /// <remarks><para>BIN counters: <seealso cref="BINCOUNTER"/></para></remarks>
        public RT0005Tag(NurApi hApi, NurApi.Tag tag)
            : base(tag)
        {
            base.hApi = hApi;

            BINLimit      = new BINHLIMIT(this);
            BINSampleTime = new BINSAMPLETIME(this);
            BINThreshold  = new BINTHRESHOLD(this);
            BINCounter    = new BINCOUNTER(this);
        }
Пример #7
0
        private void readTag_Button_Click(object sender, EventArgs e)
        {
            NurApi.Tag tag = null;
            int        usedTxLevel;

            if (NurUtils.SearchNearestTag(hNur, true, out tag, out usedTxLevel) > 0)
            {
                InitFilter(tag.GetEpcString());
            }
        }
 public TagItem(NurApi.Tag tag)
 {
     this.Tag         = tag;
     this.TagViewItem = new ListViewItem(new string[] {
         tag.rssi.ToString(),
         tag.GetEpcString(),
         tag.irData != null ? NurApi.BinToHexString(tag.irData) : "-"
     });
     this.TagViewItem.Tag = this;
 }
Пример #9
0
 /// <summary>
 /// Handles the SelectedTagChanged event of the tagListView control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void tagListView_SelectedTagChanged(object sender, EventArgs e)
 {
     NurApi.Tag selectedTag = tagListView.SelectedTag;
     if (selectedTag != null)
     {
         // Unselect preset list.
         presetListBox.SelectedIndex = -1;
         // Set EPC to target.
         bankCB.SelectedIndex = NurApi.BANK_EPC;
         startUD.Value        = 32;
         tagToLocate.Text     = selectedTag.GetEpcString();
         lengthUD.Value       = tagToLocate.Text.Length * 4;
     }
 }
Пример #10
0
        public bool InitTag(long uidTarget)
        {
            try
            {
                hNur.ClearTags();
                NurApi.InventoryResponse response;          //Information about inventory store here
                response = hNur.SimpleInventory();          //Make Inventory..
                NurApi.TagStorage inv = hNur.FetchTags(true);
                NurApi.Tag        tag = null;

                if (response.numTagsFound > 1)
                {
                    throw new Exception("more than one tag found in the antena writing EPC");
                }

                tag = inv[0];
                byte[] uid = convertLongToByteArray(uidTarget, 6);
                byte[] EPC = new byte[EPCbyteCount];

                Array.Copy(uid, 0, EPC, 0, 6);
                tag.WriteTag(0, false, EPCbank, 2, EPC);

                hNur.ClearTags();
                response = hNur.SimpleInventory();          //Make Inventory..
                inv      = hNur.FetchTags(true);
                tag      = null;

                if (response.numTagsFound > 1)
                {
                    throw new Exception("more than one tag found in the antena writing userdata");
                }

                tag = inv[0];

                byte[] USERDATA = new byte[USERbyteCount];
                USERDATA[0] = (byte)(USERDATA[0]);
                tag.WriteTag(0, false, USERbank, 0, USERDATA);

                return(true);
            }
            catch (Exception ex)
            {
                _Error = "Error initializing RFID tag " + ex.Message;
                return(false);
            }
        }
Пример #11
0
        /// <summary>
        /// Constructor v1.
        /// </summary>
        /// <param name="tag">A tag object that is received e.g. from an inventory.</param>
        public EM4325Tag(NurApi.Tag tag) : base(tag)
        {
            ushort pc = tag.pc;
            int    checkLen;

            hNur = tag.hApi;
            /* Check for XPC presence. */

            checkLen  = (pc >> 11) - 1;
            checkLen *= 2;

            if ((checkLen != tag.epc.Length) && (pc & 0x0200) != 0)
            {
                int newLen;

                hNur.ULog("Fixing EPC " + tag.GetEpcString() + " (len = " + tag.epc.Length + ", checkLen = " + checkLen + ", PC = 0x" + tag.pc.ToString("X4") + ").");

                newLen = tag.epc.Length - 2;

                pc >>= 11;
                pc--;
                pc     &= 0x1F;
                pc    <<= 11;
                tag.pc |= pc;

                mEPC = new byte[newLen];
                System.Array.Copy(tag.epc, 2, mEPC, 0, newLen);
                base.epc = new byte[newLen];
                System.Array.Copy(mEPC, 0, base.epc, 0, newLen);
                hNur.ULog("Fixed EPC = " + base.GetEpcString() + ".");
            }
            else
            {
                mEPC = new byte[tag.epc.Length];
                System.Array.Copy(tag.epc, mEPC, mEPC.Length);
            }
        }
Пример #12
0
        private void ScanTagThread()
        {
            int i;

            NurApi.TriggerReadData trg;
            bool tagFound = false;

            byte[]     testData;
            NurApi.Tag tag;
            int        epcLength = 0;

            byte[] epc = null;

            mTag = null;

            for (i = 0; i < SCAN_ROUNDS && !mInterrupted && !tagFound; i++)
            {
                tagFound = false;
                ControlText(StatusText, "Scan: " + (i + 1).ToString() + " / " + SCAN_ROUNDS);
                try
                {
                    trg       = hNur.ScanSingle(SCANTIME);
                    epcLength = trg.epcLen;
                    epc       = new byte[epcLength];
                    System.Array.Copy(trg.epc, epc, epcLength);
                    tagFound = true;
                }
                catch (NurApiException e)
                {
                    if (e.error == NurApiErrors.NUR_ERROR_TR_NOT_CONNECTED)
                    {
                        mBusy = false;
                        return;
                    }
                }

                if (tagFound)
                {
                    try
                    {
                        tag     = new NurApi.Tag(hNur);
                        tag.epc = new byte[epcLength];
                        System.Array.Copy(epc, tag.epc, epcLength);

                        testData = hNur.ReadTag(mPassword, mSecured, NurApi.BANK_PASSWD, RTConst.PASSWD_EXTRA_ADDR, RTConst.NR_PASSWD_EXTRA_BYTES);

                        mTag         = new RT0005Tag(hNur, tag);
                        mBusy        = false;
                        mInterrupted = false;
                        ControlText(StatusText, "Tag found, ready.");
                        mBusy = false;
                        BeginInvoke(mTagFoundDelegate);
                    }
                    catch
                    {
                        tagFound = false;
                    }
                }
            }

            if (!tagFound)
            {
                ControlText(StatusText, "No tag found.");
            }

            mBusy        = false;
            mInterrupted = false;
        }
Пример #13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tag">The NurApi.tag class, <see cref="NurApi.Tag"/></param>
 public SL900ATag(NurApi.Tag tag) : base(tag)
 {
     hLocalApi = tag.hApi;
 }
Пример #14
0
        private void DoGetTags()
        {
            if (!hNur.IsConnected())
            {
                AddLog("Connection required.");
                return;
            }

            CurrentTag = null;
            AllTags.Clear();
            TagListView.Items.Clear();
            TagLabel.Text = "---";

            try
            {
                ResetToA();

                hNur.ClearTagsEx();



                NurApi.InventoryExParams   invParam;
                NurApi.InventoryExFilter[] invFilters;

                // Disable EPC+DATA mode
                hNur.InventoryReadCtl = false;
                // Configure InventoryExParams for Temperature read
                invParam.inventorySelState = NurApi.SELSTATE_SL;
                invParam.inventoryTarget   = NurApi.INVTARGET_A;
                invParam.Q           = hNur.InventoryQ;
                invParam.rounds      = hNur.InventoryRounds;
                invParam.session     = NurApi.SESSION_S0;
                invParam.transitTime = 0;                 // Disable
                // Configure InventoryExFilter
                invFilters                  = new NurApi.InventoryExFilter[1];
                invFilters[0].action        = NurApi.FACTION_0;
                invFilters[0].address       = 0;
                invFilters[0].bank          = NurApi.BANK_TID;
                invFilters[0].maskData      = new byte[] { 0xE2, 0x80, 0xB0, 0x40 };
                invFilters[0].maskBitLength = (invFilters[0].maskData.Length * 8) - 4;
                invFilters[0].target        = NurApi.SESSION_SL;
                invFilters[0].truncate      = false;
                // Read
                NurApi.InventoryResponse resp = hNur.InventoryEx(ref invParam, invFilters);
                // Fetch tags from the module
                NurApi.TagStorage tagStorage = hNur.FetchTags(true);

                for (int i = 0; i < tagStorage.Count; i++)
                {
                    NurApi.Tag tag = tagStorage[i];
                    AllTags.Add(new EM4325Tag(tag));
                    ListViewItem lvi = new ListViewItem(tag.GetEpcString());
                    lvi.SubItems.Add(tag.rssi.ToString());
                    lvi.SubItems.Add(tag.antennaId.ToString());
                    TagListView.Items.Add(lvi);
                }
                columnHeader_EPC.Width   = -2;
                columnHeader_RSSI.Width  = -2;
                columnHeader_AntID.Width = -2;
            }
            catch (Exception ex)
            {
                AddLog("Inventory error.");
                AddLog("Message: " + ex.Message);
            }
        }
Пример #15
0
        void FindThread()
        {
            int  scanRound;
            bool possiblyFound;

            NurApi.TriggerReadData rd;
            byte[]     epc;
            NurApi.Tag theTag;
            byte[]     testData;

            int startTime, execTime;

            startTime = 0;

            possiblyFound = false;
            mTag          = null;

            execTime = 0;
            epc      = null;

            mAsyncUpdate = false;
            ControlState(TagLabel, STATE_RUN, "Scanning...");
            ControlEnable(ScanBtn, false);
            ControlEnable(AntennaBtn, false);
            HandleBinStateGroup(true, NO_TAG, NOT_LOGGING);

            mAsyncUpdate = true;
            ProgressInit(ScanProgress, 0, mTryCount, 1);

            for (scanRound = 0; scanRound < mTryCount && !possiblyFound; scanRound++)
            {
                ProgressStep(ScanProgress);
                try
                {
                    startTime = System.Environment.TickCount;
                    rd        = hNur.ScanSingle(500);
                    execTime  = System.Environment.TickCount - startTime;

                    epc = new byte[rd.epcLen];
                    System.Array.Copy(rd.epc, epc, rd.epcLen);

                    ControlState(TagLabel, STATE_RUN, "Verify...");

                    testData = hNur.ReadTagByEPC(mPassword, mSecured, epc, NurApi.BANK_PASSWD, RTConst.PASSWD_EXTRA_ADDR, RTConst.NR_PASSWD_EXTRA_BYTES);

                    /* Guess that this is OK tag. */
                    possiblyFound = (testData != null && testData.Length == RTConst.NR_PASSWD_EXTRA_BYTES);
                    if (possiblyFound)
                    {
                        theTag      = new NurApi.Tag();
                        theTag.hApi = hNur;
                        theTag.epc  = new byte[rd.epcLen];
                        System.Array.Copy(rd.epc, theTag.epc, rd.epcLen);

                        theTag.antennaId = (byte)rd.antennaID;
                        theTag.channel   = 0;
                        theTag.frequency = 0;                           // Huh.

                        mTag = new RT0005Tag(hNur, theTag);

                        mTag.ProgressEvent += new EventHandler <RTProgressEvent>(mTag_ProgressEvent);
                    }
                }
                catch (Exception e)
                {
                    if (e is NurApiException && ((NurApiException)e).error == NurApiErrors.NUR_ERROR_TR_NOT_CONNECTED)
                    {
                        break;
                    }

                    if (execTime < 500)
                    {
                        System.Threading.Thread.Sleep(500 - execTime);
                    }

                    ControlState(TagLabel, STATE_RUN, "Scanning...");
                }
            }

            while (scanRound < mTryCount)
            {
                scanRound++;
                ProgressStep(ScanProgress);
            }

            mBusy = false;

            ControlEnable(ScanBtn, hNur.IsConnected());
            ControlEnable(AntennaBtn, hNur.IsConnected());

            ProgressInit(ScanProgress, 0, mTryCount, 1);

            mScanThread = null;

            TempTagReady(possiblyFound, epc);
        }
Пример #16
0
        /// <summary>
        /// Searches the nearest tag.
        /// </summary>
        /// <param name="hNur">The NurApi header.</param>
        /// <param name="autoTxLevel">if set to <c>true</c> [use auto tx level].</param>
        /// <param name="tag">reference for the nearest tag</param>
        /// <param name="usedTxLevel">reference for the used TxLevel.</param>
        /// <returns>
        /// The number of found tags.
        /// </returns>
        public static int SearchNearestTag(NurApi hNur, bool autoTxLevel, out NurApi.Tag tag, out int usedTxLevel)
        {
            // Set the used TxLevel
            usedTxLevel = hNur.TxLevel;
            // Clear previously inventoried tags from memory
            hNur.ClearTags();
            NurApi.TagStorage inventoriedTags = null;

            if (autoTxLevel)
            {
                // Backup TX Level
                int backupTxLevel = hNur.TxLevel;
                // Search Tags with auto TX Level
                for (int tx = MIN_TX_LEVEL; tx >= MAX_TX_LEVEL; tx--)
                {
                    // Set TX Level
                    hNur.TxLevel = tx;
                    // Set the used TxLevel
                    usedTxLevel = tx;
                    // Perform simple inventory
                    NurApi.InventoryResponse ir = hNur.SimpleInventory();
                    // Did we find any Tag
                    if (ir.numTagsMem > 0)
                    {
                        // Yes we did
                        break;
                    }
                }
                // Fetch tags from module, including tag meta
                inventoriedTags = hNur.FetchTags(true);
                // Restore TX Level
                hNur.TxLevel = backupTxLevel;
            }
            else
            {
                // Search Tags with fixed TX Level
                for (int i = 0; i < RETRIES; i++)
                {
                    // Perform simple inventory
                    NurApi.InventoryResponse ir = hNur.SimpleInventory();
                    // Did we find any Tag
                    if (ir.numTagsMem > 0)
                    {
                        // Yes we did
                        break;
                    }
                }
                // Fetch tags from module, including tag meta
                inventoriedTags = hNur.FetchTags(true);
            }

            // Search stongest Tag
            tag = null;
            int maxRssi = -128;

            for (int i = 0; i < inventoriedTags.Count; i++)
            {
                if (maxRssi < inventoriedTags[i].rssi)
                {
                    maxRssi = inventoriedTags[i].rssi;
                    tag     = inventoriedTags[i];
                }
            }

            // Return number of found tags
            return(inventoriedTags.Count);
        }
Пример #17
0
        public bool WriteTagByUID(long uidTarget, long NewUID, bool checkOnlyOne, bool writeUserData)
        {
            long thisTagUID = 0;
            int  num        = 0;
            int  invIndex   = 0;

            try
            {
                hNur.ClearTags();
                NurApi.InventoryResponse response;          //Information about inventory store here
                response = hNur.SimpleInventory();          //Make Inventory..
                NurApi.TagStorage inv = hNur.FetchTags(true);
                NurApi.Tag        tag = null;
                if (checkOnlyOne)
                {
                    if (response.numTagsFound > 1)
                    {
                        throw new Exception("more than one tag found in the antena");
                    }
                }

                for (num = 0; num < inv.Count; num++)
                {
                    tag = inv[num];
                    byte[] EPCbytes = tag.ReadTag(0, false, EPCbank, 2, EPCbyteCount);
                    byte[] eUID     = new byte[6];
                    Array.Copy(EPCbytes, 0, eUID, 0, 6);
                    thisTagUID = convertByteArrayToLong(eUID);
                    if (thisTagUID == uidTarget)
                    {
                        break;                            // found in the antena
                    }
                }

                if (num >= inv.Count)
                {
                    throw new Exception("uidTarget not found in the antena");
                }

                //Verifica se o inventário já consta o novo UID:
                for (invIndex = 0; invIndex < _InventoryInfo.numTagsFound; invIndex++)
                {
                    if (_InventoryInfo.EPCuid[invIndex] == uidTarget || _InventoryInfo.EPCuid[invIndex] == NewUID)
                    {
                        break;
                    }
                }
                if (invIndex >= _InventoryInfo.numTagsFound)
                {
                    throw new Exception("uidTarget not found in 'inventoryInfo'");
                }

                // start writing
                byte[] EPC = new byte[EPCbyteCount];
                Array.Copy(convertLongToByteArray(_InventoryInfo.EPCuid[invIndex], 6), 0, EPC, 0, 6);
                Array.Copy(convertLongToByteArray(_InventoryInfo.EPCref[invIndex], 6), 0, EPC, 6, 6);
                Array.Copy(convertLongToByteArray(_InventoryInfo.EPCdate[invIndex], 2), 0, EPC, 12, 2);
                Array.Copy(convertLongToByteArray(_InventoryInfo.EPCcontrol[invIndex], 2), 0, EPC, 14, 2);
                tag.WriteTag(0, false, EPCbank, 2, EPC);

                if (writeUserData)
                {
                    hNur.ClearTags();
                    response = hNur.SimpleInventory();          //Make Inventory..
                    inv      = hNur.FetchTags(true);
                    tag      = null;
                    if (checkOnlyOne)
                    {
                        if (response.numTagsFound > 1)
                        {
                            throw new Exception("more than one tag found in the antena");
                        }
                    }

                    for (num = 0; num < inv.Count; num++)
                    {
                        tag = inv[num];
                        byte[] EPCbytes = tag.ReadTag(0, false, EPCbank, 2, EPCbyteCount);
                        byte[] eUID     = new byte[6];
                        Array.Copy(EPCbytes, 0, eUID, 0, 6);
                        thisTagUID = convertByteArrayToLong(eUID);
                        if (thisTagUID == uidTarget)
                        {
                            break;                            // found in the antena
                        }
                    }

                    if (num >= inv.Count)
                    {
                        throw new Exception("uidTarget not found in the antena");
                    }

                    for (invIndex = 0; invIndex < _InventoryInfo.numTagsFound; invIndex++)
                    {
                        if (_InventoryInfo.EPCuid[invIndex] == uidTarget)
                        {
                            break;                                                // found in the struct
                        }
                    }
                    if (invIndex >= _InventoryInfo.numTagsFound)
                    {
                        throw new Exception("uidTarget not found in 'inventoryInfo'");
                    }

                    byte[] USERDATA = new byte[USERbyteCount];
                    Array.Copy(convertLongToByteArray(_InventoryInfo.USERdata[invIndex], 4), 0, USERDATA, 0, 4);
                    tag.WriteTag(0, false, USERbank, 0, USERDATA);
                }

                return(true);
            }
            catch (Exception ex)
            {
                _Error = "Error writting in RFID tag " + ex.Message;
                return(false);
            }
        }