public override byte[] GetBytes() { byte[] packData = new byte[NeedLen()]; int offset = FillBytes(packData); Buffer.BlockCopy(MyBitConverter.GetBytes(desDir.Angle), 0, packData, offset, 2); packData[NeedLen() - 1] = CaculateCheckSum(packData); this.CheckSum = packData[NeedLen() - 1]; return(packData); }
/// <summary> /// 把父类的成员数据转换成字节填充到数组中 /// </summary> /// <param name="needFill">需要填充的数组</param> /// <returns>下标偏移的位置</returns> protected int FillBytes(byte[] needFill) { int offset = 0; Buffer.BlockCopy(MyBitConverter.GetBytes(this.Header), 0, needFill, offset, 2); offset += 2; needFill[offset++] = this.Len; needFill[offset++] = this.SerialNum; needFill[offset++] = this.Type; Buffer.BlockCopy(MyBitConverter.GetBytes(this.AgvId), 0, needFill, offset, 2); offset += 2; return(offset); }
public override byte[] GetBytes() { byte[] packData = new byte[Len]; int offset = FillBytes(packData); Buffer.BlockCopy(MyBitConverter.GetBytes(desPoint.X), 0, packData, offset, 4); offset += 4; Buffer.BlockCopy(MyBitConverter.GetBytes(desPoint.Y), 0, packData, offset, 4); offset += 4; packData[NeedLen() - 1] = CaculateCheckSum(packData); this.CheckSum = packData[NeedLen() - 1]; return(packData); }
public override byte[] GetBytes() { byte[] packData = new byte[Len]; int offset = FillBytes(packData); packData[offset++] = (byte)this.direction; Buffer.BlockCopy(MyBitConverter.GetBytes(speed), 0, packData, offset, 2); offset += 2; Buffer.BlockCopy(locations.GetBytes(), 0, packData, offset, 19); packData[NeedLen() - 1] = CaculateCheckSum(packData); this.CheckSum = packData[NeedLen() - 1]; return(packData); }