Exemplo n.º 1
0
        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
            }
        }
Exemplo n.º 2
0
        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
            }
        }
Exemplo n.º 3
0
Arquivo: EasForm.cs Projeto: renyh/dp2
        // 设置 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);
        }