示例#1
0
        private void ChangeMode(ReaderMode oldRMode, ReaderMode newRMode)
        {
            string oldPath = "Reader." + oldRMode.ToString().ToLower();
            string newPath = "Reader." + newRMode.ToString().ToLower();

            File.Move(oldPath, newPath);
        }
示例#2
0
        private void CreateMode(ReaderMode rMode)
        {
            string modPath = GetFilePath("Reader." + rMode.ToString().ToLower());

            File.Create(modPath).Close();
            Secuirty.AddFileSecurity(modPath, @"Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
        }
        public void ReadInstance(string fileName)
        {
            if (File.Exists(fileName))
            {
                _instance = new StreamReader(fileName);
                var strLine = String.Empty;
                int instanceSize = 0;
                int rowsRead = 0;

                while (strLine != null)
                {
                    strLine = _instance.ReadLine();
                    strLine = strLine.Trim();
                    if (strLine == String.Empty)
                    {
                        continue;
                    }
                    switch (_readerMode)
                    {
                        case ReaderMode.Count:
                            instanceSize = Int32.Parse(strLine);
                            _instanceDistances = new int[instanceSize][];
                            _instanceCosts = new int[instanceSize][];
                            _readerMode = ReaderMode.Distances;

                            break;
                        case ReaderMode.Distances:
                            _instanceDistances[rowsRead] = FillArrayRow(strLine);
                            rowsRead++;
                            if (rowsRead == instanceSize)
                            {
                                _readerMode = ReaderMode.Costs;
                                rowsRead = 0;
                            }
                            break;
                        case ReaderMode.Costs:
                            _instanceCosts[rowsRead] = FillArrayRow(strLine);
                            rowsRead++;
                            if (rowsRead == instanceSize)
                            {
                                strLine = null;
                            }
                            break;
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("File not found, fool");
            }
        }
示例#4
0
        /// <summary>
        /// Verify the first Json property of the batch payload to detect the reader's mode.
        /// </summary>
        private void DetectReaderMode()
        {
            this.batchStream.JsonReader.ReadNext();
            this.batchStream.JsonReader.ReadStartObject();

            string propertyName = this.batchStream.JsonReader.ReadPropertyName();

            if (PropertyNameRequests.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
            {
                this.mode = ReaderMode.Requests;
            }
            else if (PropertyNameResponses.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
            {
                this.mode = ReaderMode.Responses;
            }
            else
            {
                throw new ODataException(Strings.ODataBatchReader_JsonBatchTopLevelPropertyMissing);
            }
        }
示例#5
0
        private void Reader_Mode_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            switch (Reader_Mode.SelectedIndex)
            {
            case 0:
                read = ReaderMode.MaxThroughput; break;

            case 1:
                read = ReaderMode.Hybrid; break;

            case 2:
                read = ReaderMode.DenseReaderM4; break;

            case 3:
                read = ReaderMode.DenseReaderM8; break;

            case 4:
                read = ReaderMode.MaxMiller; break;

            case 5:
                read = ReaderMode.DenseReaderM4Two; break;

            case 6:
                read = ReaderMode.AutoSetDenseReader; break;

            case 7:
                read = ReaderMode.AutoSetDenseReaderDeepScan; break;

            case 8:
                read = ReaderMode.AutoSetStaticFast; break;

            case 9:
                read = ReaderMode.AutoSetStaticDRM; break;

            default:
                break;
            }
        }
        /// <summary>
        /// Asynchronously verify the first JSON property of the batch payload to detect the reader's mode.
        /// </summary>
        /// <returns>A task that represents the asynchronous read operation.</returns>
        private async Task DetectReaderModeAsync()
        {
            await this.batchStream.JsonReader.ReadNextAsync()
            .ConfigureAwait(false);

            await this.batchStream.JsonReader.ReadStartObjectAsync()
            .ConfigureAwait(false);

            string propertyName = await this.batchStream.JsonReader.ReadPropertyNameAsync()
                                  .ConfigureAwait(false);

            if (PropertyNameRequests.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
            {
                this.mode = ReaderMode.Requests;
            }
            else if (PropertyNameResponses.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
            {
                this.mode = ReaderMode.Responses;
            }
            else
            {
                throw new ODataException(Strings.ODataBatchReader_JsonBatchTopLevelPropertyMissing);
            }
        }
示例#7
0
        private bool IsMode(ReaderMode rMode)
        {
            string modPath = GetFilePath("Reader." + rMode.ToString().ToLower());

            return(File.Exists(modPath));
        }
示例#8
0
        public void Read(ReaderMode readerMode, CancellationToken token)
        {
            _readerMode = readerMode;

            int totalBytes = 0;

            if (ReaderMode != ReaderMode.rmRecord)
            {
                var pktFileName = callBack.SelectedFile;

                Stream fIn = new FileStream(pktFileName, FileMode.Open, FileAccess.Read);
                dataStream = fIn;

                while (fIn.Position < fIn.Length && !token.IsCancellationRequested)
                {
                    packetCount++;
                    HandlePacket(fIn, token);
                }
            }
            else
            {
                using (var socket = new UDPSocket())
                {
                    socket.Client(20777);
                    callBack.LogLine("Waiting for packets (port 20777)...");

                    while (!token.IsCancellationRequested)
                    {
                        byte[] data = socket.NextMessage();
                        if (data != null)
                        {
                            packetCount++;
                            totalBytes = totalBytes + data.Length;

                            MemoryStream s = new MemoryStream(data);
                            HandlePacket(s, token);

                            packetList.Add(data);
                        }
                        else
                        {
                            if (!token.IsCancellationRequested)
                            {
                                //callBack.Log($"Restart");
                            }
                        }
                    }
                }
            }
            callBack.LogLine("");
            SpeachSynthesizer.QueueText("Done");
            if (ReaderMode == ReaderMode.rmRecord)
            {
                SaveData();
                callBack.LogLine("Cancelled");
            }
            if (ReaderMode == ReaderMode.rmAnalyze)
            {
                callBack.LogLine("Data loaded");
            }
            if (ReaderMode == ReaderMode.rmReplay)
            {
                callBack.LogLine("Replay finished");
            }
            _readerMode = ReaderMode.rmIdle;
        }
示例#9
0
 public Settings(int splittersWidth, bool splittersUnlocked, ReaderMode readerMode)
 {
     SplittersWidth    = splittersWidth;
     SplittersUnlocked = splittersUnlocked;
     ReaderMode        = readerMode;
 }
示例#10
0
 public Settings()
 {
     SplittersWidth    = 10;
     SplittersUnlocked = true;
     ReaderMode        = ReaderMode.Splitters;
 }
示例#11
0
 public ReaderModeList(string s, ReaderMode rm)
 {
     Name       = s;
     ReaderMode = rm;
 }
示例#12
0
文件: RfidTool.cs 项目: Nydxy/rftool
        /// <summary>
        /// 立即开始阅读,直到wait_for_stop函数返回(同步执行)
        /// </summary>
        /// <param name="reader_address">阅读器IP地址或域名</param>
        /// <param name="wait_for_stop">当wait_for_stop返回时,终止阅读。<code>e.g.等待1秒 () => Thread.Sleep(1000)</code><code>e.g.回车键结束 () => Console.ReadLine()</code></param>
        /// <param name="target_mask">目标标签掩码</param>
        /// <param name="reader_mode">阅读器模式</param>
        /// <param name="tx_power">发送功率(dBm)</param>
        /// <param name="rx_sensitivity">接收灵敏度(dBm)</param>
        /// <param name="report_rssi">是否报告信号强度</param>
        /// <param name="report_phrase">是否报告相位</param>
        /// <param name="report_freq">是否报告频率</param>
        /// <param name="report_antenna_port">是否报告天线号码</param>
        /// <param name="remain_tag_data">是否保留所有的tag数据最终返回</param>
        /// <param name="standard_out">标准输出流重定向</param>
        /// <param name="tags_reported_callback">每次获取到tag数据时调用的处理函数</param>
        /// <returns>阅读结果</returns>
        public static bool Read(
            string reader_address,
            Action wait_for_stop,
            string target_mask           = null,
            ReaderMode reader_mode       = ReaderMode.AutoSetCustom,
            double tx_power              = 25,
            double rx_sensitivity        = -70,
            bool report_rssi             = true,
            bool report_phrase           = true,
            bool report_freq             = true,
            bool report_antenna_port     = true,
            bool remain_tag_data         = false,
            Action <string> standard_out = null,
            ImpinjReader.TagsReportedHandler tags_reported_callback = null)
        {
            try
            {
                var reader = new ImpinjReader();
                if (standard_out == null)
                {
                    standard_out = (str) => Console.WriteLine(str);
                }
                if (!reader.IsConnected)
                {
                    standard_out("Connecting to reader...");
                    reader.Connect(reader_address);
                    standard_out("Connection established.");
                }

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

                //设置报告模式
                settings.Report.Mode = ReportMode.Individual;

                //设置掩码
                if (!string.IsNullOrEmpty(target_mask))
                {
                    settings.Filters.TagFilter1.MemoryBank = MemoryBank.Epc;
                    settings.Filters.TagFilter1.BitPointer = BitPointers.Epc;
                    settings.Filters.TagFilter1.TagMask    = target_mask;
                    settings.Filters.TagFilter1.BitCount   = target_mask.Length * 4;
                    settings.Filters.Mode = TagFilterMode.OnlyFilter1;
                }

                //报告天线号码
                settings.Report.IncludeAntennaPortNumber = report_antenna_port;
                //报告信号强度
                settings.Report.IncludePeakRssi = report_rssi;
                //报告相位
                settings.Report.IncludePhaseAngle = report_phrase;
                //报告频率
                settings.Report.IncludeChannel = report_freq;

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

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

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

                //记录读取结果
                RfidReadResult readResult = new RfidReadResult();

                if (remain_tag_data)
                {
                    readResult.TagReports = new System.Collections.Generic.List <Tag>();
                }

                // 指定事件处理函数
                if (tags_reported_callback != null)
                {
                    reader.TagsReported += tags_reported_callback;
                }

                //默认事件处理函数
                reader.TagsReported += (r, report) =>
                {
                    foreach (Tag tag in report)
                    {
                        //将当前tag数据加到列表中返回
                        if (remain_tag_data)
                        {
                            readResult.TagReports.Add(tag);
                        }

                        //TODO: 应该现在统计还是事后统计?
                        //统计阅读到的不同的tags或其出现次数
                        string epc = tag.Epc.ToString();

                        if (!readResult.DictinctTags.ContainsKey(epc))
                        {
                            readResult.DictinctTags.Add(epc, 0);
                        }
                        else
                        {
                            readResult.DictinctTags[epc]++;
                        }

                        //记录总阅读次数
                        readResult.ReportedCount++;

                        standard_out($"Antenna: {tag.AntennaPortNumber}, EPC: {tag.Epc}, RSSI: {tag.PeakRssiInDbm}, Phase: {tag.PhaseAngleInRadians}, Freq: {tag.ChannelInMhz}");
                    }
                };


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

                // 开始阅读  (此方法为同步执行)
                standard_out("Start reading!");
                standard_out("----------------------------");
                reader.Start();
                wait_for_stop();
                reader.Stop();
                standard_out("Stop reading!");

                // 断开与阅读器的连接
                reader.Disconnect();
                standard_out("Connection end.");
                return(true);
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                standard_out("Octane SDK exception: " + e.Message);
                return(false);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                standard_out("Exception : " + e.Message);
                return(false);
            }
        }