CanMessage DecodeBuffer()
        {
            var bytes = System.Convert.FromBase64CharArray(this.FIncomingBuffer.ToArray(), 0, this.FIncomingBuffer.Count);

            if (bytes.Length > 4 + 4 + 1 + 8)
            {
                var message = new CanMessage();
                using (MemoryStream stream = new MemoryStream(bytes)) {
                    using (BinaryReader binaryReader = new BinaryReader(stream)) {
                        message.Flags      = binaryReader.ReadUInt32();
                        message.Identifier = binaryReader.ReadUInt32();
                        message.Length     = (byte)binaryReader.Read();
                        for (int i = 0; i < message.Length; i++)
                        {
                            message.Data[i] = binaryReader.ReadByte();
                        }
                    }
                }
                return(message);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        //called when data for any output pin is requested
        public void Evaluate(int spreadMax)
        {
            FOutput.SliceCount = 0;

            for (int i = 0; i < spreadMax; i++)
            {
                var message = new CanMessage();
                message.Flags      = (UInt32)FInFlags[i];
                message.Identifier = (UInt32)FInID[i] << 19;
                message.Length     = 7;

                message.Data[0] = (byte)(FInOperation[i]);

                message.Data[1] = (byte)(FInRegisterType[i] & 255);
                message.Data[2] = (byte)(FInRegisterType[i] >> 8);

                message.Data[3] = (byte)(FInValue[i] & 255);
                message.Data[4] = (byte)((FInValue[i] >> 8) & 255);
                message.Data[5] = (byte)((FInValue[i] >> 16) & 255);
                message.Data[6] = (byte)((FInValue[i] >> 24) & 255);

                FOutput.Add(message);
            }
        }