private void MainFrame_Navigated(object sender, NavigationEventArgs e)
        {
            if (e.ExtraData is ProductBiz)
            {
                //因为ProductTryingOnControl需要添加动画,所以要预先订阅TryingOnProducts改变事件
                Global.productViewModel.AddProduct(e.ExtraData as ProductBiz);
            }
            else if (e.ExtraData is List <ProductBiz> )
            {
                Global.productViewModel.AddProducts(e.ExtraData as List <ProductBiz>);
            }
            Global.MenuButtonBar.Visibility = Visibility.Visible;

            //界面切换后关闭感应输入
            if (readerControllerImpler != null)
            {
                readerControllerImpler.ReaderTagsHandle -= readerControllerImpler_ReaderTagsHandle;
                readerControllerImpler.StopAndDisconnect();
            }

            if (readerController != null)
            {
                readerController.ReaderTagsHandle -= readerControllerImpler_ReaderTagsHandle;
                readerController.StopAndDisconnect();
            }
            //导航结束后马上解除绑定事件
            Global.MainFrame.Navigated -= MainFrame_Navigated;
        }
예제 #2
0
        private void _readerControllerImpler_ReaderTagsHandle(object sender, RfidReaderEventArgs e)
        {
            string epccode = e.EpcDtos[0].EpcCode;
            //System.Windows.MessageBox.Show(e.EpcDtos[0].EpcCode);
            DataService service = new DataService();

            SkuBiz sku = service.GetProductByEpc(epccode);

            _readerControllerImpler.StopAndDisconnect();
            //WPFMessageBox.Show(e.EpcDtos[0].EpcCode);
            //BackgroundWorker bgw = new BackgroundWorker();
            //bgw.WorkerSupportsCancellation = true;
            //bgw.WorkerReportsProgress = true;
            //bgw.DoWork += new DoWorkEventHandler((s1, e1) =>
            //{
            //    //foreach (var epc in e.EpcDtos)
            //    //{
            //    //    if (EpcList.Count == 0 || !(EpcList.Any(x => x.Epc == epc.EpcCode)))
            //    //    {
            //    //        EPC_READ_STATUS epc_tmp = new EPC_READ_STATUS();
            //    //        epc_tmp.Epc = epc.EpcCode;
            //    //        epc_tmp.isAdd = false;
            //    //        EpcList.Add(epc_tmp);
            //    //    }
            //    //}

            //});
            //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((s2, e2) =>
            //{
            //    //AddDataToGridView();
            //});
            //bgw.RunWorkerAsync();
            ////this.InvokeIfRequired(() =>
            ////{
            ////    //数据显示
            ////    //AddDataToGridView();
            ////});
        }
예제 #3
0
        /// <summary>
        /// 点击查询按钮后开始读取
        /// </summary>
        private void menuButtons_senseReaderOpened()
        {
            if (!System.IO.File.Exists(Global.readerConfigPath))
            {
                throw new Exception("找不到读写器配置文件!");
            }
            var file = System.IO.File.ReadAllText(Global.readerConfigPath);
            var localReaderSettings = JsonConvert.DeserializeObject <ReaderWithAntennaDto>(file);

            if (localReaderSettings == null)
            {
                throw new Exception("请先维护设备!");
            }
            if (localReaderSettings.Reader.Model == "R500")
            {
                readerControllerImpler = new ImpinjR500ReaderControllerImpl();
                readerControllerImpler.ReaderTagsHandle += readerControllerImpler_ReaderTagsHandle;
                try
                {
                    readerControllerImpler.ConnectAndStart();
                }
                catch (Exception ex)
                {
                    WPFMessageBox.Show("连接设备失败!" + ex.Message);
                }
            }
            else
            {
                var reader = new Reader()
                {
                    Code           = localReaderSettings.Reader.Code,
                    IpAddress      = localReaderSettings.Reader.Ip,
                    Port           = localReaderSettings.Reader.Port,
                    MemoryBank     = 0,
                    ReaderAntennas = localReaderSettings.ReaderAntennaList.Select(v => new ReaderAntenna
                    {
                        Enable             = true,
                        MaxRxSensitivity   = v.MaxRxSensitivity,
                        MaxTransmitPower   = v.MaxTransmitPower,
                        PortNumber         = (ushort)v.AntennaIndex,
                        RxSensitivityInDbm = v.RxSensitivityInDbm,
                        TxPowerInDbm       = v.TxPowerInDbm
                    }).ToList()
                };
                readerController = new MotorolaRfidReaderControllerImpl(reader);
                readerController.ReaderTagsHandle += readerControllerImpler_ReaderTagsHandle;
                try
                {
                    readerController.ConnectAndStart();
                }
                catch (Exception ex)
                {
                    WPFMessageBox.Show("连接设备失败!" + ex.Message);
                }
            }
            //超时关闭感应输入
            System.Timers.Timer t = new System.Timers.Timer(3000);
            t.Elapsed += (s, e) =>
            {
                if (readerControllerImpler != null)
                {
                    readerControllerImpler.ReaderTagsHandle -= readerControllerImpler_ReaderTagsHandle;
                    readerControllerImpler.StopAndDisconnect();
                }

                if (readerController != null)
                {
                    readerController.ReaderTagsHandle -= readerControllerImpler_ReaderTagsHandle;
                    readerController.StopAndDisconnect();
                }
            };
            t.AutoReset = false;
            t.Enabled   = true;
        }