예제 #1
0
 public void EncodeInternal()
 {
     while (RunEncodeThread)
     {
         if (Encode)
         {
             List <MotorBaseRequest> list = txMsgQueue.PopAll();
             if (list != null && list.Count > 0)
             {
                 foreach (var mr in list)
                 {
                     CIIBasePackage bp = mr.Encode();
                     OriginalBytes  ob = new OriginalBytes();
                     ob.Data = motorProtocol.EnPackage(bp);
                     txQueue.Push(ob);
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
예제 #2
0
 public byte[] EnPackage(CIIBasePackage bp)
 {
     if (bp.AppData == null)
     {
         LogHelper.GetLogger <MotorProtocol>().Error("通信层待编码数据为空,丢弃。");
         return(null);
     }
     byte[] enData = new byte[bp.AppData.Length + 10];
     Array.Copy(bp.MarkHead, 0, enData, 0, 2);
     enData[2] = bp.DestLength;
     enData[3] = bp.DestRegion;
     enData[4] = bp.SourceLength;
     enData[5] = bp.SourceRegion;
     Array.Copy(bp.AppData, 0, enData, 6, bp.AppData.Length);
     byte[] temp = new byte[enData.Length - 6];
     Array.Copy(enData, 2, temp, 0, temp.Length);
     byte[] crc16 = BitConverter.GetBytes(CRC16.Compute(temp));
     Array.Copy(crc16, 0, enData, enData.Length - 4, 2);
     Array.Copy(bp.MarkTail, 0, enData, enData.Length - 2, 2);
     return(enData);
 }