/// <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); }
void _RFIDHelper_evtCardState(RFIDEventType eventType, object o) { string value = ""; switch ((int)eventType) { case (int)RFIDEventType.RMU_Exception: if (null != o) { } value = "设备尚未准备就绪!"; //MessageBox.Show("设备尚未准备就绪!"); UpdateStatus(value); break; case (int)RFIDEventType.RMU_CardIsReady: _RFIDHelper.SendCommand(RFIDHelper.RFIDCommand_RMU_InventoryAnti3, RFIDEventType.RMU_InventoryAnti); break; case (int)RFIDEventType.RMU_InventoryAnti: if (o != null && (string)o != "ok") { value = RFIDHelper.GetEPCFormUII((string)o); _RFIDHelper.StopCallback(); _RFIDHelper.SendCommand(RFIDHelper.RFIDCommand_RMU_StopGet, RFIDEventType.RMU_StopGet); } if (this.textBox1.InvokeRequired) { this.textBox1.Invoke(new deleUpdateContorl(UpdateEPCtxtBox), value); } else { UpdateEPCtxtBox(value); } break; case (int)RFIDEventType.RMU_SingleWriteData: if (nSingleWriteDataState == 0) { if (o == null) { //MessageBox.Show("更改标签EPC失败"); value = "更改标签EPC失败"; } else { value = "更改标签EPC成功"; //MessageBox.Show("更改标签EPC成功"); } } if (nSingleWriteDataState == 1) { if (o == null) { value = "标签锁定失败"; //MessageBox.Show("标签锁定失败"); } else { value = "标签( " + (string)o + " )锁定成功 "; //MessageBox.Show(value); } } UpdateStatus(value); break; case (int)RFIDEventType.RMU_Inventory: if (null == o) { value = "正在检测周围标签..."; } else { _RFIDHelper.SendCommand(RFIDHelper.RFIDCommand_RMU_StopGet, RFIDEventType.RMU_StopGet); tagUII = (string)o; value = "检测到标签:" + tagUII; } UpdateStatus(value); break; case (int)RFIDEventType.RMU_StopGet: _RFIDHelper.RmuLockTagReserverdEpcTid("00000000", tagUII); break; case (int)RFIDEventType.RMU_LockMem: { if (null == o) { value = "标签锁定失败 "; //MessageBox.Show("标签锁定失败 "); } else if ((string)o == "ok") //写入密码 { value = "写入密码..."; Debug.WriteLine(string.Format(" 写入密码->RMU_LockMem {0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.Millisecond.ToString())); string _initialPwd = RFIDHelper.PwdCheck(null); List <string> commands = new List <string>(); string strPwdT = RFIDHelper.PwdCheck(txtSecret.Text); 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); this.nSingleWriteDataState = 1; _RFIDHelper.SendCommand(commands, RFIDEventType.RMU_SingleWriteData, false); } } UpdateStatus(value); break; } }
/// <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); }