/// <summary> /// 锁定保留内存、epc存储器和tid存储器 /// </summary> public void RmuLockTagReserverdEpcTid(string pwd, string uii) { if (null == pwd || uii == null) { return; } string lockCommand = null; lockCommand = RFIDHelper.RmuLockCommandComposer(RMU_CommandType.RMU_LockMem, pwd, "0ffeac", uii); if (null != lockCommand) { SendCommand(lockCommand, RFIDEventType.RMU_LockMem); } }
public static string RmuLockCommandComposer(RMU_CommandType type, string pwd, string lockData, string uii) { string strCommand = ""; if (type != RMU_CommandType.RMU_LockMem || lockData == null || uii == null) { return(null); } pwd = RFIDHelper.PwdCheck(pwd); int nLen = 1 + 1 + 4 + 3 + 14; strCommand = "aa" + nLen.ToString("X2") + "16" + pwd + lockData + uii + "55"; return(strCommand); }
/// <summary> /// /// </summary> /// <param name="commandtype"></param> /// <param name="strPwd_in">4位</param> /// <param name="strBank_in"></param> /// <param name="nAddress"></param> /// <param name="strUii"></param> /// <returns></returns> public static string RmuReadDataCommandComposer(RMU_CommandType commandtype , string strPwd_in, int Bank_in, int nAddress, int nCount, string strUii) { string commandR = null; if (!Enum.IsDefined(typeof(RMU_CommandType), commandtype.ToString())) { return(commandR); } if (Bank_in < 0 || nAddress < 0 || nCount <= 0) { return(commandR); } strPwd_in = RFIDHelper.PwdCheck(strPwd_in); switch ((int)commandtype) { case (int)RMU_CommandType.RMU_SingleReadData: commandR = "aa0920" + strPwd_in + Bank_in.ToString("X2") + nAddress.ToString("X2") + nCount.ToString("X2") + "55"; break; case (int)RMU_CommandType.RMU_ReadData: if (null == strUii || !Regex.IsMatch(strUii, "[0-9a-zA-Z]{14}")) { return(commandR); } int nLength = 1 + 1 + 4 + 1 + 1 + 1 + 14; commandR = "aa" + nLength.ToString("X2") + "13" + strPwd_in + Bank_in.ToString("X2") + nAddress.ToString("X2") + nCount.ToString("X2") + strUii + "55"; break; } return(commandR); }
/// <summary> /// 将传入的参数组合成命令字符串 /// </summary> /// <param name="strRmuCmd_in"></param> /// <param name="strPwd_in"></param> /// <param name="strBank_in"></param> /// <param name="nAddress"></param> /// <param name="strData_in"></param> /// <param name="strUii"></param> /// <returns>返回的命令可能有0或者多个,调用者应对返回值做检查</returns> public static List <string> RmuWriteDataCommandCompose(RMU_CommandType commandType , string strPwd_in , int Bank_in , int nAddress , string strData_in , string strUii) { List <string> commandList = new List <string>(); if (!Enum.IsDefined(typeof(RMU_CommandType), commandType.ToString())) { return(commandList); } if (Bank_in < 0 || nAddress < 0) { return(commandList); } strPwd_in = RFIDHelper.PwdCheck(strPwd_in); for (int i = 0; i < strData_in.Length; i += 4, nAddress++) { string strAddress_in = nAddress.ToString("X2"); string strData2Send = strData_in.Substring(i, 4); string strCmd = "aa"; int nLength = 0; // 命令长度,以byte计算 nLength = 1 + 1 + 4 + 1 + 1 + 1 + 2; // length +cmd +pwd + bank + address + cnt + data len switch ((int)commandType) { case (int)RMU_CommandType.RMU_SingleWriteData: strCmd += "21"; break; case (int)RMU_CommandType.RMU_WriteData: { if (null == strUii) { return(commandList); } nLength += 14; // strUii.Length / 2;// 加上uii的长度 strCmd += "14"; } break; } strCmd = strCmd.Insert(2, nLength.ToString("X2")); //strCmd += nLength.ToString("X2"); //strCmd += commandType; strCmd += strPwd_in; strCmd += Bank_in.ToString("X2"); strCmd += strAddress_in; strCmd += "01"; //目前硬件只支持 1 strCmd += strData2Send; if (commandType == RMU_CommandType.RMU_WriteData) //指定UII { strCmd += strUii; } strCmd += "55"; commandList.Add(strCmd); } return(commandList); }
void _helper_evtCardState(RFIDEventType eventType, object o) { switch ((int)eventType) { case (int)RFIDEventType.RMU_Exception: WriterClear("写入数据失败"); break; case (int)RFIDEventType.RMU_CardIsReady: //设备准备就绪,查找周围是否有标签存在 _helper.SendCommand(RFIDHelper.RFIDCommand_RMU_InventoryAnti3, RFIDEventType.RMU_InventoryAnti); break; case (int)RFIDEventType.RMU_InventoryAnti: if (null == o) { WriterClear("请将标签防止读卡器作用范围内!"); } else if ((string)o != "ok") { Debug.WriteLine(string.Format("_helper_evtCardState ->RMU_InventoryAnti {0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.Millisecond.ToString())); _uii = (string)o; _helper.SendCommand(RFIDHelper.RFIDCommand_RMU_StopGet, RFIDEventType.RMU_StopGet); } break; case (int)RFIDEventType.RMU_StopGet: { Debug.WriteLine(string.Format("_helper_evtCardState ->RMU_StopGet {0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.Millisecond.ToString())); //首先进行锁定 if (OperationType == 0) { _helper.RmuLockTagReserverdEpcTid(_initialPwd, _uii); } else if (OperationType == 1) { _helper.RmuLockTagReserverdEpcTid(_strPwd, _uii); } } break; case (int)RFIDEventType.RMU_LockMem: { if (null == o) { WriterClear("标签锁定失败 "); } else if ((string)o == "ok") { Debug.WriteLine(string.Format("_helper_evtCardState ->RMU_LockMem {0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.Millisecond.ToString())); List <string> commands = null; if (OperationType == 0) // initial tag { //周围有标签存在,可以写入数据 commands = RFIDHelper.RmuWriteDataCommandCompose(RMU_CommandType.RMU_SingleWriteData, _initialPwd, 1, 2, GetWriteCommand(), null); string strPwdT = RFIDHelper.PwdCheck(_strPwd); string pwdTH4 = strPwdT.Substring(0, 4); //前四位 string pwdTT4 = strPwdT.Substring(4, 4); //后四位 List <string> commandSetSecret1 = RFIDHelper.RmuWriteDataCommandCompose(RMU_CommandType.RMU_SingleWriteData, _initialPwd, 0, 2, pwdTH4, null); List <string> commandSetSecret2 = RFIDHelper.RmuWriteDataCommandCompose(RMU_CommandType.RMU_SingleWriteData, pwdTH4 + _initialPwd, 0, 3, pwdTT4, null); commands.AddRange(commandSetSecret1); commands.AddRange(commandSetSecret2); } if (OperationType == 1) { commands = RFIDHelper.RmuWriteDataCommandCompose(RMU_CommandType.RMU_SingleWriteData, RFIDHelper.PwdCheck(_strPwd), 1, 2, GetWriteCommand(), null); } _helper.SendCommand(commands, RFIDEventType.RMU_SingleWriteData, false); } } break; case (int)RFIDEventType.RMU_SingleWriteData: if (null != o) { WriterClear("标签成功 "); } else { WriterClear("标签写入数据失败,请检查设备并将标签放在读卡器范围内!"); } break; } }
public RFID_EPCWriter(RFIDHelper helper) { _helper = helper; //_helper.evtCardState += new deleVoid_RFIDEventType_Object_Func(_helper_evtCardState); }
void _RFIDHelper_evtCardState(RFIDEventType eventType, object o) { string value = ""; switch ((int)eventType) { case (int)RFIDEventType.RMU_Exception: if (null != o) { } MessageBox.Show("设备尚未准备就绪!"); break; case (int)RFIDEventType.RMU_CardIsReady: _RFIDHelper.SendCommand(RFIDHelper.RFIDCommand_RMU_InventoryAnti3, RFIDEventType.RMU_InventoryAnti); break; case (int)RFIDEventType.RMU_InventoryAnti: this.bRfidCheckClosed = false; if (this.btnReadRfid.InvokeRequired) { this.btnReadRfid.Invoke(new deleUpdateContorl(this.UpdateStartRfidCheckButton), false.ToString()); } else { this.btnReadRfid.Enabled = false; } if (this.btnStopRfidCheck.InvokeRequired) { this.btnStopRfidCheck.Invoke(new deleUpdateContorl(this.UpdateStopRfidCheckButton), true.ToString()); } else { this.btnStopRfidCheck.Enabled = true; } if (null == o) { value = "正在检测标签..."; //this.btnReadRfid.Enabled = false; //this.btnStopRfidCheck.Enabled = true; } else if ((string)o != "ok") { value = "读取到标签:" + (string)o; //string id = ((string)o).Substring(4, 6); string epc = RFIDHelper.GetEPCFormUII((string)o); AddNewIDToCheckRecordList_Temp(epc); UpdateCheckListControl(null); } if (this.labelStatus.InvokeRequired) { this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value); } else { //this.statusLabel.Text = value; UpdateStatusLable(value); } break; case (int)RFIDEventType.RMU_StopGet: _RFIDHelper.StopCallback(); this.bRfidCheckClosed = true; value = "本地考勤服务停止"; //this.btnReadRfid.Enabled = true; //this.btnStopRfidCheck.Enabled = false; if (this.btnReadRfid.InvokeRequired) { this.btnReadRfid.Invoke(new deleUpdateContorl(this.UpdateStartRfidCheckButton), true.ToString()); } else { this.btnReadRfid.Enabled = true; } if (this.btnStopRfidCheck.InvokeRequired) { this.btnStopRfidCheck.Invoke(new deleUpdateContorl(this.UpdateStopRfidCheckButton), false.ToString()); } else { this.btnStopRfidCheck.Enabled = false; } if (this.labelStatus.InvokeRequired) { this.labelStatus.Invoke(new deleUpdateContorl(UpdateStatusLable), value); } else { //this.statusLabel.Text = value; UpdateStatusLable(value); } break; } }