コード例 #1
0
ファイル: RfidTool.cs プロジェクト: Nydxy/rftool
        /// <summary>
        /// 停止阅读
        /// </summary>
        public void EndRead()
        {
            if (!IsReading)
            {
                return;
            }
            try
            {
                reader.Stop();
                RedirectStandardOut.Invoke("Stop reading!");

                if (!string.IsNullOrEmpty(option.OutputFileName))
                {
                    file.Close();
                    file.Dispose();
                }

                // 断开与阅读器的连接
                reader.Disconnect();
                RedirectStandardOut.Invoke("Connection end.");
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                RedirectStandardOut.Invoke("Octane SDK exception: " + e.Message);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                RedirectStandardOut.Invoke("Exception : " + e.Message);
            }
        }
コード例 #2
0
ファイル: RfidTool.cs プロジェクト: Nydxy/rftool
        /// <summary>
        /// 开始阅读
        /// </summary>
        /// <returns>是否开始阅读</returns>
        public bool BeginRead()
        {
            try
            {
                if (!reader.IsConnected)
                {
                    RedirectStandardOut.Invoke("Connecting to reader...");
                    reader.Connect(option.HostName);
                    RedirectStandardOut.Invoke("Connection established.");
                }

                //获取该阅读器的默认设置,然后在其基础上修改
                Settings settings = reader.QueryDefaultSettings();

                // Send a tag report for every tag read.
                settings.Report.Mode = ReportMode.Individual;

                if (!string.IsNullOrEmpty(option.TargetMask))
                {
                    settings.Filters.TagFilter1.MemoryBank = MemoryBank.Epc;
                    settings.Filters.TagFilter1.BitPointer = BitPointers.Epc;
                    settings.Filters.TagFilter1.TagMask    = option.TargetMask;
                    settings.Filters.TagFilter1.BitCount   = option.TargetMask.Length * 4;
                    settings.Filters.Mode = TagFilterMode.OnlyFilter1;
                }

                //包含天线号码
                settings.Report.IncludeAntennaPortNumber = option.ReportAntennaPortNumber;
                //报告信号强度
                settings.Report.IncludePeakRssi = option.ReportRssi;
                //报告相位
                settings.Report.IncludePhaseAngle = option.ReportPhase;
                //报告频率
                settings.Report.IncludeChannel = option.ReportFrequency;

                //阅读阅读模式
                settings.ReaderMode = option.ReaderMode;

                // 仅使用1号天线
                settings.Antennas.DisableAll();
                settings.Antennas.GetAntenna(1).IsEnabled = true;

                //设置传输功率和接收灵敏度
                settings.Antennas.GetAntenna(1).TxPowerInDbm       = option.TxPowerInDbm;
                settings.Antennas.GetAntenna(1).RxSensitivityInDbm = option.RxSensitivityInDbm;

                // 应用设置
                reader.ApplySettings(settings);

                // 指定事件处理函数
                reader.TagsReported += (reader, report) =>
                {
                    foreach (Tag tag in report)
                    {
                        RedirectStandardOut.Invoke($"Antenna: {tag.AntennaPortNumber}, EPC: {tag.Epc}, RSSI: {tag.PeakRssiInDbm}, Phase: {tag.PhaseAngleInRadians}, Freq: {tag.ChannelInMhz}");
                        if (file != null)
                        {
                            file.WriteLine(string.Join(",",
                                                       tag.AntennaPortNumber.ToString(),
                                                       tag.Epc.ToString(),
                                                       tag.PeakRssiInDbm.ToString(),
                                                       tag.PhaseAngleInRadians.ToString(),
                                                       tag.ChannelInMhz.ToString()));
                        }
                    }
                };

                reader.TagsReported += TagsReported;

                //如果需要输出到文件,初始化文件流
                if (!string.IsNullOrEmpty(option.OutputFileName))
                {
                    file = new StreamWriter(option.OutputFileName);
                }

                // 开始阅读  (此方法为异步执行)
                RedirectStandardOut.Invoke("Start reading!");
                RedirectStandardOut.Invoke("----------------------------");
                reader.Start();
                IsReading = true;
                return(true);
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                RedirectStandardOut.Invoke("Octane SDK exception: " + e.Message);
                return(false);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                RedirectStandardOut.Invoke("Exception : " + e.Message);
                return(false);
            }
        }
コード例 #3
0
ファイル: RfidTool.cs プロジェクト: Nydxy/rftool
        /// <summary>
        /// 获得阅读器信息
        /// </summary>
        /// <returns></returns>
        public RfidReaderInfo GetReaderInfo()
        {
            try
            {
                if (!reader.IsConnected)
                {
                    RedirectStandardOut.Invoke("Connecting to reader...");
                    reader.Connect(option.HostName);
                    RedirectStandardOut.Invoke("Connection established.");
                    RedirectStandardOut.Invoke("");
                }

                RfidReaderInfo result = new RfidReaderInfo();

                // Query the reader features and print the results.
                RedirectStandardOut.Invoke("Reader Features");
                RedirectStandardOut.Invoke("---------------");
                FeatureSet features = reader.QueryFeatureSet();
                RedirectStandardOut.Invoke($"Model name : {features.ModelName}");
                result.ModelName = features.ModelName;
                RedirectStandardOut.Invoke($"Model number : {features.ModelNumber}");
                result.ModelNumber = features.ModelNumber.ToString();
                RedirectStandardOut.Invoke($"Reader model : {features.ReaderModel.ToString()}");
                result.ReaderModel = features.ReaderModel.ToString();
                RedirectStandardOut.Invoke($"Firmware version : {features.FirmwareVersion}");
                result.FirmwareVersion = features.FirmwareVersion;
                RedirectStandardOut.Invoke($"Antenna count : {features.AntennaCount}\n");
                result.AntennaCount = features.AntennaCount;

                // Query the current reader status.
                RedirectStandardOut.Invoke("Reader Status");
                RedirectStandardOut.Invoke("---------------");
                Status status = reader.QueryStatus();
                RedirectStandardOut.Invoke($"Is connected : {status.IsConnected}");
                result.IsConnected = status.IsConnected;
                RedirectStandardOut.Invoke($"Is singulating : {status.IsSingulating}");
                RedirectStandardOut.Invoke($"Temperature : {status.TemperatureInCelsius}° C\n");

                // Query the current reader settings and print the results.
                RedirectStandardOut.Invoke("Reader Settings");
                RedirectStandardOut.Invoke("---------------");

                Settings settings = reader.QueryDefaultSettings();
                RedirectStandardOut.Invoke($"Reader mode : {settings.ReaderMode}");
                RedirectStandardOut.Invoke($"Search mode : {settings.SearchMode}");
                RedirectStandardOut.Invoke($"Session : {settings.Session}");


                for (ushort i = 1; i <= features.AntennaCount; i++)
                {
                    RedirectStandardOut.Invoke($"[Antenna {i.ToString()}]");
                    if (settings.Antennas.GetAntenna(i).MaxRxSensitivity)
                    {
                        RedirectStandardOut.Invoke("Rx sensitivity : Max");
                    }
                    else
                    {
                        RedirectStandardOut.Invoke($"Rx sensitivity : {settings.Antennas.GetAntenna(i).RxSensitivityInDbm} dBm");
                    }

                    if (settings.Antennas.GetAntenna(i).MaxTxPower)
                    {
                        RedirectStandardOut.Invoke("Tx power : Max");
                    }
                    else
                    {
                        RedirectStandardOut.Invoke($"Tx power : {settings.Antennas.GetAntenna(i).TxPowerInDbm} dBm");
                    }

                    RedirectStandardOut.Invoke("");
                }

                return(result);
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                RedirectStandardOut.Invoke($"Octane SDK exception: {e.Message}");
                return(null);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                RedirectStandardOut.Invoke($"Exception : {e.Message}");
                return(null);
            }
        }