示例#1
0
 /// <summary>
 /// 以纯数组构造APDU
 /// </summary>
 /// <param name="buffer"></param>
 public APDUClass(byte[] buffer)
 {
     this.SetApci(APCIClass.GetApci(buffer));
     if (buffer.Length > 6)
     {
         byte[] data = new byte[buffer.Length - 6];
         if (data.Length < buffer.Length - 6)
         {
             throw new Exception("初始化数据长度出错");
         }
         try
         {
             Array.Copy(buffer, 6, data, 0, data.Length);
             ASDUClass temp = new ASDUClass();
             _res = temp.UnPack(buffer, 6, buffer.Length - 6);
             this.SetAsdu(temp);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex);
         }
     }
 }
示例#2
0
 /// <summary>
 /// 设置Asdu部分数据
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public bool SetAsdu(ASDUClass data)
 {
     if (data != null)
     {
         if (this.apci.UisType == APCIClass.UISFormat.I)
         {
             byte[] temp = data.ToArray();
             try
             {
                 if (temp.Length > 250)
                 {
                     (this.apci as APCIClassIFormat).APDULenth = 0x00;
                 }
                 else
                 {
                     (this.apci as APCIClassIFormat).APDULenth = Convert.ToByte(temp.Length + 4);
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.ToString() + "   " + temp.Length);
             }
             this._asdu = data;
         }
         return(true);
     }
     else
     {
         _asdu = null;
         if (this.apci.UisType == APCIClass.UISFormat.I)
         {
             (this.apci as APCIClassIFormat).APDULenth = 4;
         }
         return(false);
     }
 }
示例#3
0
 /// <summary>
 /// 以APCI+数据构造APDU
 /// </summary>
 /// <param name="apci"></param>
 /// <param name="data"></param>
 public APDUClass(APCIClass apci, ASDUClass asdu)
 {
     this.SetApci(apci);
     this.SetAsdu(asdu);
 }