예제 #1
0
        public static void LedOnAll(RFID_Device localDevice, List <string> tagsList)
        {
            int nbTagToLight = tagsList.Count; // initial number of tags

            localDevice.TestLighting(tagsList);

            string message = String.Format("{0} tags to find : {1} have been found.", nbTagToLight,
                                           nbTagToLight - tagsList.Count);

            if (tagsList.Count > 0) // some tag UIDs are still in the list : they've not been found
            {
                message += "\nMissing tags ID :";

                foreach (string missingTag in tagsList)
                {
                    message = String.Format("{0}\n{1}", message, missingTag);
                }
            }

            MessageBox.Show(message);       // while user doesn't close the dialog, the led-lighting thread is still running

            localDevice.StopLightingLeds(); // stops lighting once user closed MessageBox
        }
        private void toolStripButtonFindByLed_Click(object sender, EventArgs e)
        {
            if (currentDevice == null)
            {
                return;
            }
            List <string> selectedTags = new List <string>();

            foreach (ListViewItem currentItem in dataListView.Items)
            {
                OLVColumn olcevent  = dataListView.GetColumn(0);
                string    eventtype = currentItem.SubItems[olcevent.Index].Text;
                if (eventtype.Equals("Removed"))
                {
                    continue;
                }

                OLVColumn olc   = dataListView.GetColumn(1);
                string    tagId = currentItem.SubItems[olc.Index].Text;
                selectedTags.Add(tagId);
            }

            int nbTagToLight = selectedTags.Count;

            if (nbTagToLight == 0)
            {
                return;
            }

            if ((currentDevice.ConnectionStatus == ConnectionStatus.CS_Connected) &&
                (currentDevice.DeviceStatus == DeviceStatus.DS_Ready))
            {
                currentDevice.TestLighting(selectedTags);
                string message = string.Empty;

                if ((nbTagToLight == 1) && ((nbTagToLight - selectedTags.Count) == 1))
                {
                    message = String.Format(ResStrings.str_LedTagFound, nbTagToLight, nbTagToLight - selectedTags.Count);
                }
                else if ((nbTagToLight - selectedTags.Count) == 1)
                {
                    message = String.Format(ResStrings.str_LedFound2, nbTagToLight, nbTagToLight - selectedTags.Count);
                }
                else
                {
                    message = String.Format(ResStrings.str_LedFound3, nbTagToLight, nbTagToLight - selectedTags.Count);
                }

                if (selectedTags.Count > 0)
                {
                    message += ResStrings.str_LedMissing;

                    foreach (string missingTag in selectedTags)
                    {
                        message = String.Format("{0}\n{1}", message, missingTag);
                    }
                }

                MessageBox.Show(message, ResStrings.str_LED_Information, MessageBoxButtons.OK, MessageBoxIcon.Information);

                currentDevice.StopLightingLeds();
            }
        }
        /// <summary>
        /// Click on "Step by step" button. Only available for USB devices.
        /// Enable lighting on all device's axises and send lighting order to each selected tag.
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void buttonLedOn_Click(object sender, EventArgs e)
        {
            buttonLedOn.Enabled = false;
            Cursor.Current      = Cursors.WaitCursor;

            if (_currentUSBDevice.get_RFID_Device.HardwareVersion.StartsWith("11"))
            {
                buttonLedOnAll_Click(null, null);
                return;
            }

            List <string> tags             = new List <string>();
            Hashtable     tagLedStateTable = new Hashtable();

            foreach (string item in listBoxTag.SelectedItems)
            {
                tags.Add(item);
                tagLedStateTable.Add(item, false);
            }

            int  nbLighted = 0, totalLighted = 0, currentChannel = 0;
            bool userChoice = true, isLastStep = false;

            for (int i = 1; i < 5; ++i)
            {
                _currentUSBDevice.get_RFID_Device.StartLedOn(i);
            }

            while (userChoice && !isLastStep) // While users want to go on searching and we didn't browse all device axis
            {
                isLastStep = _currentUSBDevice.StartLightingLeds(tags, tagLedStateTable, out currentChannel, out nbLighted);

                if (nbLighted == 0)
                {
                    continue;
                }

                totalLighted += nbLighted;

                if (totalLighted == tags.Count)
                {
                    break;
                }

                string message = String.Format("Channel {3} : {0} / {1} found. Until now : {2} / {1} found. Continue ?",
                                               nbLighted,
                                               tags.Count, totalLighted, currentChannel);

                DialogResult dialogChoice = MessageBox.Show(message, "Research in progress...", MessageBoxButtons.YesNo,
                                                            MessageBoxIcon.Question);
                userChoice = (dialogChoice != DialogResult.No);
            }


            if (totalLighted == tags.Count)
            {
                string message = String.Format("Channel {3} : {0} / {1} found. Total : {2} / {1} found.",
                                               nbLighted,
                                               tags.Count, totalLighted, currentChannel);
                MessageBox.Show(message, "Research over", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                if (isLastStep)
                {
                    string message = String.Format("All axis have been browsed. {0} tags not found. Missing tags ID :", tags.Count - totalLighted);

                    foreach (DictionaryEntry entryTag in tagLedStateTable)
                    {
                        if (!(bool)entryTag.Value)
                        {
                            message = String.Format("{0}\n{1}", message, entryTag.Key);
                        }
                    }

                    MessageBox.Show(message, "Research over", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            _currentUSBDevice.StopLightingLeds();

            Cursor.Current      = Cursors.Default;
            buttonLedOn.Enabled = true;
        }