void StartRfidManager(string url) { _cancelRfidManager?.Cancel(); _cancelRfidManager = new CancellationTokenSource(); RfidManager.Base.Name = "RFID 中心"; RfidManager.Url = url; // RfidManager.AntennaList = "1|2|3|4"; // testing // RfidManager.SetError += RfidManager_SetError; RfidManager.ListTags += RfidManager_ListTags; RfidManager.Start(_cancelRfidManager.Token); }
int LoadChipByUID( string reader_name, string uid, uint antenna_id, out TagInfo tag_info, out string strError) { strError = ""; tag_info = null; #if OLD_CODE RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } #endif try { #if OLD_CODE var result = channel.Object.GetTagInfo( reader_name, uid); #else var result = RfidManager.GetTagInfo( reader_name, uid, antenna_id); #endif if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } tag_info = result.TagInfo; return(0); } catch (Exception ex) { strError = "GetTagInfo() 出现异常: " + ex.Message; return(-1); } finally { #if OLD_CODE EndRfidChannel(channel); #endif } }
int SaveNewChip(out string strError) { strError = ""; #if OLD_CODE RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } #endif try { TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); #if OLD_CODE NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); #else NormalResult result = RfidManager.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); TagList.ClearTagTable(_tagExisting.UID); #endif if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { #if OLD_CODE EndRfidChannel(channel); #endif } }
public ReadersView() { InitializeComponent(); var mainWindow = (MainWindow)Application.Current.MainWindow; _rfidManager = mainWindow.RfidManager; this.DataContext = _rfidManager; _readers = new ObservableCollection <ReaderProfile>(_readerProfileRepository.GetAll()); readersControl.ItemsSource = _readers; // cbReadSuppressionTime.DataContext = _rfidManager.Settings; }
private void Init() { _context = this; _app = (App)Application; _rfidMgr = _app.RfidMgr; _view = FindViewById(Resource.Id.group); _bTSwitch = (Switch)FindViewById(Resource.Id.bt_switch); _autoConnectSwitch = (Switch)FindViewById(Resource.Id.auto_connect_switch); _bTSeartTv = (TextView)FindViewById(Resource.Id.btn_search); _lvBleScan = (ListView)FindViewById(Resource.Id.bt_list); AccessReadBtn = (Button)FindViewById(Resource.Id.access_read); _bluetoothAdapter = BluetoothAdapter.DefaultAdapter; _bTSeartTv.SetOnClickListener(this); AccessReadBtn.SetOnClickListener(this); _bTSwitch.Checked = _bluetoothAdapter.IsEnabled; _bTSwitch.CheckedChange += _bTSwitch_CheckedChange; var sp = this.GetSharedPreferences(SP_NAME, FileCreationMode.Private); bool autoConnectState = sp.GetBoolean(SP_KEY_AUTO_CONNECT, false); _autoConnectSwitch.Checked = autoConnectState; _autoConnectSwitch.CheckedChange += _autoConnectSwitch_CheckedChange; // _test.Add(new ViewHolder()); BleScanListAdapter = new BluetoothDeviceListAdapter(this, ref _bleScanDevices); _lvBleScan.Adapter = BleScanListAdapter; _lvBleScan.OnItemClickListener = this; _lvBleScan.OnItemLongClickListener = this; _progressDialog = new ProgressDialog(this); _progressDialog.SetMessage(GetString(Resource.String.loading_text)); ConnectionHandler = new BtConnectionHandler(this); _leScanCallback = new BleScanCallBack(ConnectionHandler); SetVisibility(); _btReceiver = new BtReceiver(); _btReceiver.OnBtStateChange += _btReceiver_OnBtStateChange; IntentFilter filter = new IntentFilter(); filter.AddAction("android.bluetooth.adapter.action.STATE_CHANGED"); RegisterReceiver(_btReceiver, filter); }
public ReportView() { InitializeComponent(); var mainWindow = (MainWindow)System.Windows.Application.Current.MainWindow; _rfidManager = mainWindow.RfidManager; _reportManager = mainWindow.ReportManager; this.DataContext = _reportManager; cbRaces.DataContext = _reportManager; cbRaces.ItemsSource = _reportManager.Races; //dgSplits.DataContext = _reportManager; //dgSplits.ItemsSource = _reportManager.Splits; // dgResults.ItemsSource = _reportManager.SplitResults; dgResults.DataContext = _reportManager; worker.DoWork += worker_DoWork; worker.RunWorkerCompleted += worker_RunWorkerCompleted; }
public override void OnCreate() { base.OnCreate(); _instance = this; _rfidMgr = RfidManager.GetInstance(this); Coname = Resources.GetStringArray(Resource.Array.coname_texts); tagListTitles = Resources.GetStringArray(Resource.Array.coname_texts); // LogUtils.e("App onCreate"); // setListTitle(); // LogUtils.e(BuildConfig.UI_STYLE + ":" + BuildConfig.FLAVOR); // mSharedPrefManager = SharedPrefManager.getInstance(this); /*new Handler().post(new Runnable() { * @Override * public void run() * { * mSharedPrefManager.loadDefaultSettings(); * boolean debug = mSharedPrefManager.getBoolean(getString(R.string.debug_mode), false); * setDebugMode(debug); * } * });*/ }
public AthletesView() { InitializeComponent(); var mainWindow = (MainWindow)Application.Current.MainWindow; _rfidManager = mainWindow.RfidManager; _athleteManager = mainWindow.AthleteManager; btnStopAssign.IsEnabled = false; this.DataContext = _athleteManager; btnAssign.DataContext = _rfidManager; _athleteRepository = new AthleteRepository(); _athleteRepository.Save(); dgAthletes.ItemsSource = _athleteManager.Athletes; _athleteManager.NextBib = _athleteRepository.GetMaxBib() + 1; // _athleteManager. }
int SaveNewChip(out string strError) { strError = ""; #if OLD_CODE RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } #endif try { #if NO TagInfo new_tag_info = _tagExisting.TagInfo.Clone(); new_tag_info.Bytes = this.chipEditor_editing.LogicChipItem.GetBytes( (int)(new_tag_info.MaxBlockCount * new_tag_info.BlockSize), (int)new_tag_info.BlockSize, LogicChip.GetBytesStyle.None, out string block_map); new_tag_info.LockStatus = block_map; #endif Debug.Assert(_tagExisting != null, ""); Debug.WriteLine("333 " + (_tagExisting.TagInfo != null ? "!=null" : "==null")); Debug.Assert(_tagExisting.TagInfo != null, ""); TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); #if OLD_CODE NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); #else Debug.Assert(_tagExisting != null, ""); Debug.WriteLine("111 " + (_tagExisting.TagInfo != null ? "!=null" : "==null")); Debug.Assert(_tagExisting.TagInfo != null, ""); // 2019/9/30 Debug.Assert(_tagExisting.AntennaID == _tagExisting.TagInfo.AntennaID, $"2 _tagExisting.AntennaID({_tagExisting.AntennaID}) 应该 == _tagExisting.TagInfo.AntennaID({_tagExisting.TagInfo.AntennaID})"); NormalResult result = RfidManager.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); TagList.ClearTagTable(_tagExisting.UID); #endif if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { #if OLD_CODE EndRfidChannel(channel); #endif } }
/* * private const int WS_EX_TOPMOST = 0x00000008; * protected override CreateParams CreateParams * { * get * { * CreateParams createParams = base.CreateParams; * createParams.ExStyle |= WS_EX_TOPMOST; * return createParams; * } * } */ // 从 TagList.Books 中获得一个标签的 EAS 状态 // result.Value: // -1 出错 // 0 Off // 1 On NormalResult GetEasStateByUID(string uid) { foreach (var data in TagList.Books) { if (data.OneTag.UID != uid) { continue; } if (data.OneTag.TagInfo == null) { return new NormalResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签暂时 TagInfo == null,无法获得 EAS 状态" } } ; return(new NormalResult { Value = data.OneTag.TagInfo.EAS ? 1 : 0 }); } // TODO: 此时可否发起一次 GetTagInfo 请求? return(new NormalResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签不在读卡器上,无法获得其 EAS 状态" }); } // 从 TagList.Books 中获得一个标签的 EAS 状态 // result.Value: // -1 出错 // 0 Off // 1 On NormalResult GetEasStateByPII(string pii) { foreach (var data in TagList.Books) { TagInfo tag_info = null; if (data.OneTag.TagInfo == null) { // TODO: 出错了考虑重试一下 // result.Value // -1 // 0 var result = RfidManager.GetTagInfo("*", data.OneTag.UID); if (result.Value == -1) { continue; } tag_info = result.TagInfo; } else { tag_info = data.OneTag.TagInfo; } string current_pii = QuickChargingForm.GetPII(tag_info); if (current_pii == pii) { return(new NormalResult { Value = tag_info.EAS ? 1 : 0 }); } } return(new NormalResult { Value = -1, ErrorInfo = $"PII 为 '{pii}' 的标签不在读卡器上,无法获得其 EAS 状态" }); }
// 尝试自动修正 EAS // result.Value // -1 出错 // 0 ListsView 中没有找到事项 // 1 发生了修改 public NormalResult _tryCorrectEas(string uid, string pii) { // 先检查 uid 和 pii 是否在列表中? ListViewItem item = (ListViewItem)this.Invoke((Func <ListViewItem>)(() => { return(FindLine(uid, pii)); })); if (item == null) { return new NormalResult { Value = 0 } } ; // 获得册记录 XML var result = GetItemXml(pii); if (result.Value == -1) { return(result); } // 获得册记录的外借状态。 // return: // -2 册记录为空,无法判断状态 // -1 出错 // 0 没有被外借 // 1 在外借状态 int nRet = RfidToolForm.GetCirculationState(result.ItemXml, out string strError); if (nRet == -1 || nRet == -2) { return(new NormalResult { Value = -1, ErrorInfo = strError }); } var gettag_result = RfidManager.GetTagInfo("*", uid); if (gettag_result.Value == -1) { return(gettag_result); } var tag_info = gettag_result.TagInfo; // 检查册记录外借状态和 EAS 状态是否符合 // 检测 EAS 是否正确 NormalResult seteas_result = new NormalResult { Value = 1 }; if (nRet == 1 && tag_info.EAS == true) { seteas_result = RfidManager.SetEAS("*", "uid:" + tag_info.UID, false); TagList.SetEasData(tag_info.UID, false); } else if (nRet == 0 && tag_info.EAS == false) { seteas_result = RfidManager.SetEAS("*", "uid:" + tag_info.UID, true); TagList.SetEasData(tag_info.UID, true); } else { // 没有发生修改 } // set_result // return result.Value: // -1 出错 // 0 没有找到指定的标签 // 1 找到,并成功修改 EAS if (seteas_result.Value != 1) { return(new NormalResult { Value = -1, ErrorInfo = seteas_result.ErrorInfo }); } ItemInfo info = (ItemInfo)item.Tag; // 触发事件 this.EasChanged?.Invoke(this, new EasChangedEventArgs { PII = pii, UID = uid, Param = info.Param }); // 从 ListView 中删除这一行 this.Invoke((Action)(() => { this.listView1.Items.Remove(item); OnItemChanged(); })); return(seteas_result); }
// 设置 EAS 状态。如果失败,会在 ListView 里面自动添加一行,以备后面用户在读卡器上放标签时候自动修正 internal NormalResult SetEAS( object task, string reader_name, string tag_name, bool enable) { // 解析 tag_name 里面的 UID 或者 PII string uid = ""; string pii = ""; List <string> parts = StringUtil.ParseTwoPart(tag_name, ":"); if (parts[0] == "pii") { pii = parts[1]; } else if (parts[0] == "uid" || string.IsNullOrEmpty(parts[0])) { uid = parts[1]; } else { return new NormalResult { Value = -1, ErrorInfo = $"未知的 tag_name 前缀 '{parts[0]}'", ErrorCode = "unknownPrefix" } }; // 尝试改变 tag_name 形态,优化后面请求 EAS 写入的速度 { tag_name = ConvertTagNameString(tag_name); if (string.IsNullOrEmpty(uid)) { Parse(tag_name, out string temp_uid, out string temp_pii); uid = temp_uid; } } NormalResult result = null; for (int i = 0; i < 2; i++) { result = RfidManager.SetEAS(reader_name, tag_name, enable); if (result.Value == 1) { break; } } TagList.ClearTagTable(uid); if (result.Value != 1) { this.Invoke((Action)(() => { // 加入一个新行 AddLine(uid, pii, task); })); } else { /* * EasChanged?.Invoke(this, * new EasChangedEventArgs * { * UID = uid, * PII = pii, * Param = task * }); */ } return(result); } // TODO: 注意查重。避免插入重复的行 ListViewItem AddLine(string uid, string pii, object o) { ListViewItem item = new ListViewItem(); item.Tag = new ItemInfo { Param = o }; ListViewUtil.ChangeItemText(item, 0, uid); ListViewUtil.ChangeItemText(item, 1, pii); this.listView1.Items.Add(item); OnItemChanged(); // 自动填充书目摘要列 Task.Run(() => { FillBiblioSummary(new List <ListViewItem>() { item }); }); return(item); }
/* * private const int WS_EX_TOPMOST = 0x00000008; * protected override CreateParams CreateParams * { * get * { * CreateParams createParams = base.CreateParams; * createParams.ExStyle |= WS_EX_TOPMOST; * return createParams; * } * } */ // result.Value: // -1 没有找到 // 其他 天线编号 NormalResult GetAntennaByUID(string uid) { foreach (var data in TagList.Books) { if (data.OneTag.UID != uid) { continue; } if (data.OneTag.TagInfo == null) { return new NormalResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签暂时 TagInfo == null,无法获得天线编号" } } ; return(new NormalResult { Value = (int)data.OneTag.AntennaID }); } // TODO: 此时可否发起一次 GetTagInfo 请求? return(new NormalResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签不在读卡器上,无法获得其天线编号" }); } // 从 TagList.Books 中获得一个标签的 EAS 状态 // result.Value: // -1 出错 // 0 Off // 1 On GetEasStateResult GetEasStateByUID(string uid) { foreach (var data in TagList.Books) { if (data.OneTag.UID != uid) { continue; } if (data.OneTag.TagInfo == null) { return new GetEasStateResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签暂时 TagInfo == null,无法获得 EAS 状态" } } ; return(new GetEasStateResult { Value = data.OneTag.TagInfo.EAS ? 1 : 0, AntennaID = data.OneTag.AntennaID, ReaderName = data.OneTag.ReaderName }); } // TODO: 此时可否发起一次 GetTagInfo 请求? return(new GetEasStateResult { Value = -1, ErrorInfo = $"UID 为 '{uid}' 的标签不在读卡器上,无法获得其 EAS 状态" }); } // 从 TagList.Books 中获得一个标签的 EAS 状态 // result.Value: // -1 出错 // 0 Off // 1 On GetEasStateResult GetEasStateByPII(string pii) { foreach (var data in TagList.Books) { TagInfo tag_info = null; if (data.OneTag.TagInfo == null) { // TODO: 出错了考虑重试一下 // result.Value // -1 // 0 var result = RfidManager.GetTagInfo("*", data.OneTag.UID, data.OneTag.AntennaID); if (result.Value == -1) { continue; } tag_info = result.TagInfo; } else { tag_info = data.OneTag.TagInfo; } string current_pii = QuickChargingForm.GetPII(tag_info); if (current_pii == pii) { return(new GetEasStateResult { Value = tag_info.EAS ? 1 : 0, AntennaID = tag_info.AntennaID, ReaderName = tag_info.ReaderName }); } } return(new GetEasStateResult { Value = -1, ErrorInfo = $"PII 为 '{pii}' 的标签不在读卡器上,无法获得其 EAS 状态" }); } // result.Value: // -1 出错 // 0 Off // 1 On internal GetEasStateResult GetEAS(string reader_name, string tag_name) { Parse(tag_name, out string uid, out string pii); if (string.IsNullOrEmpty(uid) == false) { return(GetEasStateByUID(uid)); } if (string.IsNullOrEmpty(pii) == false) { return(GetEasStateByPII(pii)); } return(new GetEasStateResult { Value = -1, ErrorInfo = $"tag_name '{tag_name}' 不合法" }); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { RfidManager.CloseAll(); }