コード例 #1
0
        public byte[] ReadData(string OAD)
        {
            string txString = string.Empty;

            txString = "68" + "L1L2" + "43" + (Addr.Length / 2 - 1).ToString("x2") + Addr + "10";
            string hString = txString.Substring(2);

            txString += "H_CS";
            txString += "05";//读
            if (OAD.Length / 8 > 1)
            {
                txString += "02";                            //多个OAD读
                txString += "01";                            //piid
                txString += (OAD.Length / 8).ToString("X2"); //个数
            }
            else
            {
                txString += "01"; //单个OAD读
                txString += "01"; //piid
            }
            txString += OAD;
            txString += "00";//没有时间标签
            txString += "F_CS";
            txString += "16";

            int frmLen = txString.Length / 2 - 2;

            txString = txString.Replace("L1L2", (frmLen & 0x00ff).ToString("X2") + (frmLen >> 8).ToString("X2"));

            hString  = hString.Replace("L1L2", (frmLen & 0x00ff).ToString("X2") + (frmLen >> 8).ToString("X2"));
            txString = txString.Replace("H_CS", GetCS(hString));

            string fString = txString.Substring(2, txString.Length - 8);

            txString = txString.Replace("F_CS", GetCS(fString));

            byte[] ret = {};
            string res = SendAndRec(txString);

            if (res != null && res.Length > 0)
            {
                Frame698 frm = new Frame698(res);
                if (frm.IsValidFrame)
                {
                    //ret = new byte[frm.Apdu.Length];
                    ret = frm.Apdu;
                }
            }
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// 建立连接
        /// </summary>
        /// <param name="keyVer">密钥版本</param>
        /// <param name="comformance">协商参数信息</param>
        /// <param name="connectType">加密类型</param>
        public void Connect(string keyVer, Consult consult)
        {
            string apdu = "0203";

            apdu += consult.ProtocolVer;
            apdu += consult.ProtocolConformance;
            apdu += consult.FunctionConformance;
            apdu += consult.TxMaxSize;
            apdu += consult.RxMaxSize;
            apdu += consult.MaxSizeFrmNum;
            apdu += consult.MaxApduSize;
            apdu += consult.OverTime;
            apdu += consult.SecurityRule;

            Esam698Service.Esam698ServiceClient ESAMproxy = new Esam698Service.Esam698ServiceClient();

            int    iKeyState = Get_KeyState(keyVer);
            string cDiv      = Get_Div(iKeyState);
            string cASCTR    = _asctr.ToString("X8");

            Esam698Service.InitSessionState initSessionState;
            initSessionState = ESAMproxy.Obj_Meter_Formal_InitSession(iKeyState, cDiv, cASCTR, "01");

            RandonHost  = initSessionState.OutRandHost;
            SessionInit = initSessionState.OutSessionInit;
            Sign        = initSessionState.OutSign;

            apdu += (SessionInit.Length / 2).ToString("X2");
            apdu += SessionInit;
            apdu += (Sign.Length / 2).ToString("X2");
            apdu += Sign;
            apdu += "00";//没有时间标签

            string txString = MakeSendFrm("43", apdu);
            string ret      = string.Empty;
            string res      = SendAndRec(txString);

            if (res != null && res.Length > 0)
            {
                Frame698 frm = new Frame698(res);
                if (frm.IsValidFrame)
                {
                    ret = frm.ApduStr;
                }
            }
        }
コード例 #3
0
        public string ReadAddr()
        {
            string txString = "6817004345AAAAAAAAAAAA11534E0501024001020000BB0B16";
            //返回:68 21 00 C3 45 11 11 11 11 11 11 11 7D E0 85 01 02 40 01 02 00 01 09 06 11 11 11 11 11 11 00 00 7C 3A 16
            string ret = string.Empty;
            string res = SendAndRec(txString);

            if (res != null && res.Length > 0)
            {
                Frame698 frm = new Frame698(res);
                if (frm.IsValidFrame)
                {
                    ret = frm.SaStr;
                }
            }
            return(ret);
        }
コード例 #4
0
 protected override void AnayzeFrm(string frm)
 {
     Frame698 frame698 = new Frame698(frm);
 }
コード例 #5
0
        /// <summary>
        /// 判断是否读完
        /// </summary>
        /// <param name="frm">输入帧</param>
        /// <returns></returns>
        protected override bool ReceiveFinishJudge(byte[] frm)
        {
            Frame698 frame698 = new Frame698(frm);

            return(frame698.IsValidFrame);
        }