Beispiel #1
0
        public override CanFrame GetCanFrame(int WithDescriptor)
        {
            Byte[] buff = new Byte[8];

            buff[0] = (byte)(((byte)FrameType & 0x0f) << 4 | Data.Length & 0x0f);
            Buffer.BlockCopy(Data, 0, buff, 1, Data.Length);

            return(CanFrame.NewWithDescriptor(WithDescriptor, buff));
        }
Beispiel #2
0
        public override CanFrame GetCanFrame(int WithDescriptor)
        {
            var buff = new Byte[8];

            buff[0] = (byte)(((byte)FrameType & 0x0f) << 4 | (byte)Flag & 0x0f);
            buff[1] = BlockSize;
            buff[2] = SeparationCodeFromTime(SeparationTime);

            return(CanFrame.NewWithDescriptor(WithDescriptor, buff));
        }
Beispiel #3
0
 /// <summary>
 /// Создаёт CAN-фрейм, содержащий данное сообщение
 /// </summary>
 /// <returns>CAN-фрейм, содержащий данное сообщение</returns>
 public CanFrame GetCanFrame()
 {
     try
     {
         var data = this.Encode();
         return(CanFrame.NewWithDescriptor(this.Descriptors[this.FrameHalfset], data));
     }
     catch (Exception e)
     {
         throw new BlokFrameProtocolException(e);
     }
 }
Beispiel #4
0
        public override CanFrame DecodeNext(Stream DataStream)
        {
            var headerBuffer = new Byte[8 + 2];

            if (DataStream.Read(headerBuffer, 0, headerBuffer.Length) < headerBuffer.Length)
            {
                return(null);
            }
            var    dt         = DateTime.FromBinary(BitConverter.ToInt64(headerBuffer, 0));
            UInt16 descriptor = BitConverter.ToUInt16(headerBuffer, 8);

            var frame = CanFrame.NewWithDescriptor(descriptor);

            DataStream.Read(frame.Data, 0, frame.Data.Length);
            frame.Time = dt;
            return(frame);
        }
Beispiel #5
0
        protected override CanFrame ReadNextFrame()
        {
            var l = Reader.ReadLine();

            if (l == null)
            {
                return(null);
            }

            var   regex = new Regex(Pattern);
            Match match = regex.Match(l);

            if (!match.Success)
            {
                return(null);
            }

            var desc = Convert.ToUInt16(match.Groups["descriptor"].Value, 16);
            var data = match.Groups["databyte"].Captures.OfType <Capture>().Select(c => Convert.ToByte(c.Value, 16)).ToArray();

            return(CanFrame.NewWithDescriptor(desc, data));
        }