// 从缓存中获取标签信息 GetTagInfoResult GetTagInfo(RfidChannel channel, string uid) { TagInfo info = (TagInfo)_tagTable[uid]; if (info == null) { var result = channel.Object.GetTagInfo("*", uid); if (result.Value == -1) { return(result); } info = result.TagInfo; if (info != null) { if (_tagTable.Count > 1000) { _tagTable.Clear(); } _tagTable[uid] = info; } } return(new GetTagInfoResult { TagInfo = info }); }
// return: // -2 remoting服务器连接失败。驱动程序尚未启动 // -1 出错 // 0 成功 public static NormalResult SetEAS( RfidChannel channel, string reader_name, string tag_name, bool enable, out string strError) { strError = ""; try { return(channel.Object.SetEAS(reader_name, tag_name, enable)); } // [System.Runtime.Remoting.RemotingException] = {"连接到 IPC 端口失败: 系统找不到指定的文件。\r\n "} catch (System.Runtime.Remoting.RemotingException ex) { strError = "针对 " + App.RfidUrl + " 的 SetEAS() 操作失败: " + ex.Message; return(new NormalResult { Value = -2, ErrorInfo = strError }); } catch (Exception ex) { strError = "针对 " + App.RfidUrl + " 的 SetEAS() 操作失败: " + ex.Message; return(new NormalResult { Value = -1, ErrorInfo = strError }); } }
public static void EndRfidChannel(RfidChannel channel) { if (channel != null && channel.Channel != null) { ChannelServices.UnregisterChannel(channel.Channel); channel.Channel = null; } }
private void PageBorrow_Unloaded(object sender, RoutedEventArgs e) { if (_fingerprintChannel != null) { FingerPrint.EndFingerprintChannel(_fingerprintChannel); _fingerprintChannel = null; } if (_rfidChannel != null) { RFID.EndRfidChannel(_rfidChannel); _rfidChannel = null; } if (_timer != null) { _timer.Dispose(); } }
public static RfidChannel StartRfidChannel( string strUrl, out string strError) { strError = ""; RfidChannel result = new RfidChannel(); result.Channel = new IpcClientChannel(Guid.NewGuid().ToString(), // 随机的名字,令多个 Channel 对象可以并存 new BinaryClientFormatterSinkProvider()); ChannelServices.RegisterChannel(result.Channel, true); bool bDone = false; try { result.Object = (IRfid)Activator.GetObject(typeof(IRfid), strUrl); if (result.Object == null) { strError = "无法连接到服务器 " + strUrl; return(null); } bDone = true; return(result); } catch (Exception ex) { strError = "StartRfidChannel() 出现异常: " + ex.Message; return(null); } finally { if (bDone == false) { EndRfidChannel(result); } } }
// 第二阶段:填充图书信息的 PII 和 Title 字段 void FillBookFields() { #if NO RfidChannel channel = RFID.StartRfidChannel(App.RfidUrl, out string strError); if (channel == null) { throw new Exception(strError); } #endif try { foreach (Entity entity in _entities) { if (_cancelRefresh == null || _cancelRefresh.IsCancellationRequested) { return; } if (entity.FillFinished == true) { continue; } //if (string.IsNullOrEmpty(entity.Error) == false) // continue; // 获得 PII // 注:如果 PII 为空,文字重要填入 "(空)" if (string.IsNullOrEmpty(entity.PII)) { // var result = channel.Object.GetTagInfo("*", entity.UID); var result = GetTagInfo(_rfidChannel, entity.UID); if (result.Value == -1) { entity.SetError(result.ErrorInfo); continue; } Debug.Assert(result.TagInfo != null); entity.TagInfo = result.TagInfo; LogicChip chip = LogicChip.From(result.TagInfo.Bytes, (int)result.TagInfo.BlockSize, "" // tag.TagInfo.LockStatus ); string pii = chip.FindElement(ElementOID.PII)?.Text; entity.PII = GetCaption(pii); } // 获得 Title // 注:如果 Title 为空,文字中要填入 "(空)" if (string.IsNullOrEmpty(entity.Title) && string.IsNullOrEmpty(entity.PII) == false && entity.PII != "(空)") { var result = GetEntityData(entity.PII, out string title, out string item_xml, out string item_recpath); if (result.Value == -1) { entity.SetError(result.ErrorInfo); continue; } entity.Title = GetCaption(title); // entity.ItemXml = item_xml; entity.SetData(item_recpath, item_xml); } entity.SetError(null); entity.FillFinished = true; } booksControl.SetBorrowable(); } catch (Exception ex) { #if NO this.error.Text = ex.Message; this.error.Visibility = Visibility.Visible; #endif this.Error = ex.Message; } finally { #if NO RFID.EndRfidChannel(channel); #endif } }
// EventProxy eventProxy; private void PageBorrow_Loaded(object sender, RoutedEventArgs e) { // throw new Exception("test"); _layer = AdornerLayer.GetAdornerLayer(this.mainGrid); _adorner = new LayoutAdorner(this); // 准备指纹通道 List <string> errors = new List <string>(); if (string.IsNullOrEmpty(App.FingerprintUrl) == false) { #if NO eventProxy = new EventProxy(); eventProxy.MessageArrived += new MessageArrivedEvent(eventProxy_MessageArrived); #endif _fingerprintChannel = FingerPrint.StartFingerprintChannel( App.FingerprintUrl, out string strError); if (_fingerprintChannel == null) { errors.Add($"启动指纹通道时出错: {strError}"); } // https://stackoverflow.com/questions/7608826/how-to-remote-events-in-net-remoting #if NO _fingerprintChannel.Object.MessageArrived += new MessageArrivedEvent(eventProxy.LocallyHandleMessageArrived); #endif try { _fingerprintChannel.Object.GetMessage("clear"); _fingerprintChannel.Started = true; } catch (Exception ex) { if (ex is RemotingException && (uint)ex.HResult == 0x8013150b) { errors.Add($"启动指纹通道时出错: “指纹中心”({App.FingerprintUrl})没有响应"); } else { errors.Add($"启动指纹通道时出错(2): {ex.Message}"); } } } // 准备 RFID 通道 if (string.IsNullOrEmpty(App.RfidUrl) == false) { _rfidChannel = RFID.StartRfidChannel( App.RfidUrl, out string strError); if (_rfidChannel == null) { errors.Add($"启动 RFID 通道时出错: {strError}"); } try { var result = _rfidChannel.Object.ListReaders(); // TODO: 某处界面可以显示当前连接的读卡器名字 // 看看是否有至少一个读卡器 if (result.Readers.Length == 0) { errors.Add("当前指纹中心没有任何连接的读卡器。请检查读卡器是否正确连接"); } else { _rfidChannel.Started = true; } } catch (Exception ex) { if (ex is RemotingException && (uint)ex.HResult == 0x8013150b) { errors.Add($"启动 RFID 通道时出错: “RFID-中心”({App.RfidUrl})没有响应"); } else { errors.Add($"启动 RFID 通道时出错: {ex.Message}"); } } } else { errors.Add($"尚未配置 RFID 接口 URL"); } if (errors.Count > 0) { this.Error = StringUtil.MakePathList(errors, "; "); } // https://stackoverflow.com/questions/13396582/wpf-user-control-throws-design-time-exception if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { _timer = new System.Threading.Timer( new System.Threading.TimerCallback(timerCallback), null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)); } }