Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        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;
            }
        }