Beispiel #1
0
 private static void Console_Execute_Identify(DocInterfaceControl _docIntControl)
 {
     m_LastTagID = null;
     //First make sure DocInterfaceControl is initialized
     if (_docIntControl != null)
     {
         if (_docIntControl.IsInitialized)
         {
             try
             {
                 DateTime startTime = DateTime.UtcNow;
                 //Call Identify and show result
                 var      tagScanInfo = _docIntControl.Identify();
                 TimeSpan processSpan = DateTime.UtcNow - startTime;
                 if (tagScanInfo != null)
                 {
                     Console.WriteLine("");
                     Console.WriteLine("IdentifyResult:");
                     Console.WriteLine(tagScanInfo.ToString());
                     Console.WriteLine(string.Format("(Duration: {0})", processSpan));
                     //TagScanInfo can be either HfScanResultInfo (for HF scan) or UhfScanResultInfo (for UHF scan).
                     //  check type to obtain TagID and save it into global variable to be used by ReadBytes/WriteBytes
                     if (tagScanInfo is HfScanResultInfo)
                     {
                         m_LastTagID = (tagScanInfo as HfScanResultInfo).TagID;
                     }
                     if (tagScanInfo is UhfScanResultInfo)
                     {
                         //For UHF more than one TAG can be found at once. For demo purposes select first TagID
                         var uhfScan = (tagScanInfo as UhfScanResultInfo);
                         if (uhfScan != null)
                         {
                             if (uhfScan.TagInfoList.Count > 0)
                             {
                                 m_LastTagID = uhfScan.TagInfoList[0].UII.UII;
                             }
                         }
                     }
                 }
                 else
                 {
                     //Update result in UI
                     Console.WriteLine(string.Format("Result: FAIL. Duration: {0}", processSpan));
                 }
             }
             catch
             {
                 Console.WriteLine("Exception");
             }
         }
         else
         {
             Console.WriteLine("DocInterfaceControl not initialized!");
         }
     }
 }
Beispiel #2
0
        private void Button_Identify_Click(object sender, RoutedEventArgs e)
        {
            //Identify --> Search for transponders
            comboBox_TagID.IsEnabled = false;
            comboBox_TagID.Items.Clear();

            if (m_DocInterface != null)
            {
                if (m_DocInterface.IsInitialized)
                {
                    DateTime startTime = DateTime.UtcNow;
                    //This function blocks & searches for a default time of 1 second (optional parameter)
                    try
                    {
                        textBox_ThreadLog.Text += "\n = Identify =\n";
                        var      identifyResult = m_DocInterface.Identify();
                        TimeSpan processSpan    = DateTime.UtcNow - startTime;
                        if (identifyResult != null)
                        {
                            if (identifyResult is HfScanResultInfo)
                            {
                                HfScanResultInfo hfResult = identifyResult as HfScanResultInfo;

                                //Update result in UI
                                comboBox_TagID.Items.Add(BitConverter.ToString(hfResult.TagID));
                                //Select first ID to be used in ReadBytes/WriteBytes
                                comboBox_TagID.SelectedIndex = 0;

                                string toLog = string.Format("Result: OK. Duration: {0}", processSpan);
                                toLog += "- HF ScanResult -\n";
                                toLog += string.Format("\t{0}", BitConverter.ToString(hfResult.TagID));
                                toLog += "\n";
                                textBox_ThreadLog.Text += toLog;
                                textBox_ThreadLog.ScrollToEnd();
                            }
                            if (identifyResult is UhfScanResultInfo)
                            {
                                UhfScanResultInfo uhfResult = identifyResult as UhfScanResultInfo;

                                //Update result in UI
                                foreach (var tsi in uhfResult.TagInfoList)
                                {
                                    comboBox_TagID.Items.Add(BitConverter.ToString(tsi.UII.UII));
                                }
                                //Select first UII to be used in ReadBytes/WriteBytes
                                comboBox_TagID.SelectedIndex = 0;
                                if (comboBox_TagID.Items.Count > 1)
                                {
                                    comboBox_TagID.IsEnabled = true;
                                }

                                string toLog = string.Format("Result: OK. Duration: {0}", processSpan);
                                toLog += "- UHF ScanResult -\n";
                                toLog += "  Ant\tUII-Bytes\n";
                                foreach (var tsi in uhfResult.TagInfoList)
                                {
                                    toLog += string.Format("  {0}\t{1}\n", tsi.AntennaNumber, BitConverter.ToString(tsi.UII.UII));
                                }
                                textBox_ThreadLog.Text += toLog;
                                textBox_ThreadLog.ScrollToEnd();
                            }
                        }
                        else
                        {
                            //Update result in UI
                            textBox_ThreadLog.Text += string.Format("Result: FAIL. Duration: {0}\n", processSpan);
                            textBox_ThreadLog.ScrollToEnd();
                        }
                    }
                    catch (Exception ex)
                    {
                        TimeSpan processSpan = DateTime.UtcNow - startTime;
                        textBox_ThreadLog.Text += string.Format("Result: Exception. Duration: {0}\n", processSpan);
                        textBox_ThreadLog.ScrollToEnd();
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                    }
                }
            }
        }