CPUCardLib.ApduMsgHelper.GetApduMsg C# (CSharp) Method

GetApduMsg() public static method

public static GetApduMsg ( Array data ) : CPUCardLib.ApduMsg
data Array
return CPUCardLib.ApduMsg
        public static ApduMsg GetApduMsg(byte[] data)
        {
            ApduMsg reslut = new ApduMsg ();
            reslut.ResponseData = data;

            if (data.Length < 2)
            {
                //reslut.Msg = "返回信息长度错误";
                return reslut;
            }

            //赋值data最后两个字节,作为状态码
            byte[] code = new byte[2];
            Array.Copy(data, data.Length - 2, code, 0, 2);

            string codeStr = BitConverter.ToString(code);
            if (AllMsgDic.TryGetValue(codeStr, out reslut))
            {
                reslut = (ApduMsg)reslut.Clone();
            }
            else
            {
                reslut = new ApduMsg();

                reslut.Msg = "未找到已定义到状态信息";

                if (codeStr.StartsWith("6C"))
                {
                    reslut.Msg = "Le长度错误,实际长度是xx";
                }
                
                
            }

            reslut.ResponseData = data;


            return reslut;
        }
    }

Usage Example

Example #1
0
        public byte[] CardSendCommand(byte[] cmd)
        {
            if (ShowLog != null)
            {
                ShowLog("------------------------------\r\n");
                ApduCommand msg = new ApduCommand(cmd);

                if (msg.CmdNote.Trim().StartsWith("建立文件"))
                {
                    CPUFileType cpy = (CPUFileType)(msg.Data[0]);
                    msg.CmdNote += "类型" + cpy.ToString() + "    ";
                }
                string log = $"发送原始命令:{BitConverter.ToString(cmd)} \r\n" + msg.ToString() + "\r\n";



                ShowLog(log);
            }

            byte[] result = this.carder.SendCommand(cmd);

            if (ShowLog != null)
            {
                ApduMsg apduMsg = ApduMsgHelper.GetApduMsg(result);

                string msg = "状态:{0}  信息:{1} 结果:{2} \r\n";

                msg = string.Format(msg, apduMsg.Status, apduMsg.Msg, BitConverter.ToString(apduMsg.ResponseData));

                string log = "接收: " + msg;
                ShowLog(log);
            }
            return(result);
        }
All Usage Examples Of CPUCardLib.ApduMsgHelper::GetApduMsg