/// <summary>
        /// <c>buttonStop_Click</c> is called when user clicks on Stop button.
        /// This function calls <c>StopScan</c> (from USBFeatures) to stop scanning.
        /// </summary>
        private void buttonStop_Click(object sender, EventArgs e)
        {
            if (tabControl.SelectedIndex == 0) // (USB) local device
            {
                USBFeatures.StopScan(_currentUSBDevice);
            }

            else // (Ethernet) Remote device
            {
                TCPFeatures.StopScan(_currentEthernetDevice, tcpClient);
                UpdateStatusBar("Scan request has been sent to Ethernet device");
            }
        }
        private void buttonLedOnAll_Click(object sender, EventArgs e)
        {
            if (tabControl.SelectedIndex == 0) // (USB) local device
            {
                USBFeatures.LedOnAll(_currentUSBDevice, listBoxTag.SelectedItems.Cast <string>().ToList());
            }

            else // (Ethernet) Remote device
            {
                TCPFeatures.LedOnAll(_currentEthernetDevice, tcpClient, listBoxTag.SelectedItems.Cast <string>().ToList());
                UpdateStatusBar("Led on All request has been sent to Ethernet device");
            }
        }
        /// <summary>
        /// <c>buttonStart_Click</c> is called when user clicks on Scan button.
        /// This function calls <c>ScanDevice</c> (from USBFeatures).
        /// </summary>
        private void buttonStart_Click(object sender, EventArgs e)
        {
            listBoxTag.Invoke((MethodInvoker) delegate
            {
                listBoxTag.Items.Clear();
                tagsCountLabel.Text = "0";
            });
            if (tabControl.SelectedIndex == 0) // (USB) local device
            {
                if (!USBFeatures.StartScan(_currentUSBDevice, true))
                {
                    MessageBox.Show("Device is not ready or not connected");
                }
            }

            else // (Ethernet) Remote device
            {
                InventoryData lastScanInventory;
                if (TCPFeatures.StartScan(_currentEthernetDevice, tcpClient, out lastScanInventory) !=
                    TcpIpClient.RetCode.RC_Succeed)
                {
                    UpdateStatusBar("Ethernet Device scanning has failed");
                    return;
                }

                UpdateStatusBar("Ethernet Device scanning completed.");
                Invoke((MethodInvoker) delegate
                {
                    listBoxTag.Items.Clear();

                    tagsCountLabel.Text = lastScanInventory.nbTagAll.ToString();

                    foreach (string tagUID in lastScanInventory.listTagAll)
                    {
                        listBoxTag.Items.Add(tagUID);
                    }
                });
            }
        }
        private void buttonUpdateUID_Click(object sender, EventArgs e)
        {
            if (listBoxTag.SelectedItems.Count > 1)
            {
                MessageBox.Show("Please update only one tag at a time.");
                return;
            }
            if (tabControl.SelectedIndex == 0) // (USB) local device
            {
                double fv = 0.0;
                double.TryParse(_currentUSBDevice.get_RFID_Device.FirmwareVersion.Replace(",", "."), NumberStyles.Number, CultureInfo.InvariantCulture, out fv);

                if (fv <= 2.54)
                {
                    MessageBox.Show("Please update device firmware with 2.55 or above version");
                    return;
                }
            }
            else
            {
                double      fv  = 0.0;
                TcpIpClient tcp = new TcpIpClient();
                tcp.RequestFirmwareVersion(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server,
                                           out fv);
                if (fv <= 3.54)
                {
                    MessageBox.Show("Please update device firmware with 3.55 or above version");
                    return;
                }
            }


            string oldUID = listBoxTag.SelectedItem.ToString();

            using (NewUIDPrompt newUIDPrompt = new NewUIDPrompt(oldUID))
            {
                if (newUIDPrompt.ShowDialog(this) == DialogResult.OK)
                {
                    WriteCode writingResult;

                    string newUID    = newUIDPrompt.NewUID;
                    int    writeMode = newUIDPrompt.modeWrite;

                    if (tabControl.SelectedIndex == 0) // (USB) local device
                    {
                        if ((_currentUSBDevice.ConnectionStatus == ConnectionStatus.CS_Connected) &&
                            (_currentUSBDevice.DeviceStatus == DeviceStatus.DS_Ready))
                        {
                            writingResult = USBFeatures.WriteNewUID(_currentUSBDevice, oldUID, newUID, writeMode);
                        }

                        else
                        {
                            MessageBox.Show("RFID device not ready");
                            return;
                        }
                    }

                    else // (Ethernet) Remote device
                    {
                        writingResult = TCPFeatures.WriteNewUID(_currentEthernetDevice, tcpClient, oldUID, newUID, writeMode);
                    }

                    switch (writingResult)
                    {
                    case WriteCode.WC_Error:
                        MessageBox.Show("An unexpected error occurred. Operation failed !");
                        break;

                    case WriteCode.WC_TagNotDetected:
                        MessageBox.Show("Tag not detected. Operation failed !");
                        break;

                    case WriteCode.WC_TagNotConfirmed:
                        MessageBox.Show("Tag not confirmed. Operation failed !");
                        break;

                    case WriteCode.WC_TagBlockedOrNotSupplied:
                        MessageBox.Show("Tag blocked or not well supplied. Operation failed !");
                        break;

                    case WriteCode.WC_TagBlocked:
                        MessageBox.Show("Tag blocked. Operation failed !");
                        break;

                    case WriteCode.WC_TagNotSupplied:
                        MessageBox.Show("Tag not well supplied. Operation failed !");
                        break;

                    case WriteCode.WC_ConfirmationFailed:
                        MessageBox.Show("Updated tag confirmation has failed.");
                        break;

                    case WriteCode.WC_Success:
                        MessageBox.Show("Tag UID succesfully updated.");
                        break;
                    }
                }
            }
        }