private void displayMethod(IRP1.GB_ReadTag msg) { lock (lockobj) { bool isAdd = true; string data = Core.Util.ConvertByteArrayToHexString(msg.ReceivedMessage.Data); foreach (DataRow dr in myDt.Rows) { if (dr["Data"] != null && dr["Data"].ToString() != "" && dr["Data"].ToString() == data) { isAdd = false; dr["Count"] = int.Parse(dr["Count"].ToString()) + 1; } } if (isAdd) { DataRow mydr = myDt.NewRow(); mydr["Data"] = data; mydr["Count"] = 1; myDt.Rows.Add(mydr); } } }
/// <summary> /// 接收到读写器消息触发事件 /// </summary> /// <param name="reader">读写器类</param> /// <param name="msg">消息内容</param> void reader_OnMessageNotificationReceived(Invengo.NetAPI.Core.BaseReader reader, Invengo.NetAPI.Core.IMessageNotification msg) { if (msg.StatusCode != 0) { //显示错误信息 showMsg(msg.ErrInfo); return; } String msgType = msg.GetMessageType(); msgType = msgType.Substring(msgType.LastIndexOf('.') + 1); switch (msgType) { #region GB_ReadTag case "GB_ReadTag": { IRP1.GB_ReadTag m = (IRP1.GB_ReadTag)msg; //string tagType = m.ReceivedMessage.TagType; display(m); } break; #endregion #region RXD_IOTriggerSignal_800 case "RXD_IOTriggerSignal_800": { IRP1.RXD_IOTriggerSignal_800 m = (IRP1.RXD_IOTriggerSignal_800)msg; if (m.ReceivedMessage.IsStart) { changeCtrlEnable("scan"); showMsg(" I/O 触发,正在读卡..."); } else { changeCtrlEnable("conn"); showMsg(" I/O 触发,停止读卡"); } } break; #endregion } }
// 扫描标签 private void btnScan_Click(object sender, EventArgs e) { if (!a1.Checked && !a2.Checked && !a3.Checked && !a4.Checked) { MessageBox.Show("请选择一个天线!"); return; } byte ant = 0x80; if (a1.Checked) { ant += 0x01; } if (a2.Checked) { ant += 0x02; } if (a3.Checked) { ant += 0x04; } if (a4.Checked) { ant += 0x08; } btnClean_Click(sender, e); byte[] pwd = Util.ConvertHexStringToByteArray(accessPwd); readmemoryBank = (GBMemoryBank)Enum.GetValues(typeof(GBMemoryBank)).GetValue(this.comboBox1.SelectedIndex); GB_ReadTag scanMsg = new IRP1.GB_ReadTag(ant, type, pwd, readmemoryBank, ptr, (byte)length);//扫描消息 if (reader != null && reader.IsConnected) { if (reader.Send(scanMsg)) { changeCtrlEnable("scan"); lblMsg.Text = "正在读卡..."; } } }