Example #1
0
        public EpcReader()
        {
            EpcList = new HashSet <string>();

            if (!File.Exists(readerConfigPath))
            {
                throw new Exception("找不到读写器配置文件!");
            }
            var file = File.ReadAllText(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 += readerController_ReaderTagsHandle;
            //    try
            //    {
            //        _readerController.ConnectAndStart();
            //    }
            //    catch (Exception ex)
            //    {
            //        WPFMessageBox.Show("连接设备失败!" + ex.Message);
            //    }
            //}
        }
        private void ProductSlideGallery_Loaded(object sender, RoutedEventArgs e)
        {
            //只有试衣间才支持加载初始屏时启动感应输入
            if (Global.UserInterface == UserInterface.ShoppingAssistant)
            {
                return;
            }
            if (!System.IO.File.Exists(readerConfigPath))
            {
                throw new Exception("找不到读写器配置文件!");
            }
            var file = System.IO.File.ReadAllText(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.StopAndDisconnect();
                    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);
                }
            }
        }
Example #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;
        }