Beispiel #1
0
        public static IntelHexFile Create(Byte[] data, int ByteCount)
        {
            IntelHexFile file = new IntelHexFile();
            IntelHexFileLine current;

            for (int i = 0; ; )
            {
                current = new IntelHexFileLine();
                if (i == data.Length)
                {
                    goto EndOfFile;
                }
                else if ((data.Length - i) < ByteCount) /* Last Record */
                {
                    current.ByteCount = (Byte)(data.Length - i);
                    current.Address = (UInt16)i;

                    current.Data = new Byte[data.Length - i];
                    Buffer.BlockCopy(data, i, current.Data, 0, data.Length - i);

                    current.CheckSum = (Byte)TwosCompliment(current);

                    file.AddLine(current);

                    goto EndOfFile;
                }
                else
                {
                    current.ByteCount = (Byte)ByteCount;
                    current.Address = (UInt16)i;

                    current.Data = new Byte[ByteCount];
                    Buffer.BlockCopy(data, i, current.Data, 0, ByteCount);

                    current.CheckSum = (Byte)TwosCompliment(current);

                    file.AddLine(current);
                }

                i += ByteCount;
            }

            EndOfFile: /* End of hex file */
            current = new IntelHexFileLine();
            current.ByteCount = 0;
            current.Address = 0;
            current.RecordType = RecordType.EndOfFile;
            current.Data = new Byte[0];
            current.CheckSum = (Byte)TwosCompliment(current);
            file.AddLine(current);

            return file;
        }
Beispiel #2
0
        private static IntelHexFile Open(MemoryStream fp)
        {
            IntelHexFile file = new IntelHexFile();
            IntelHexFileLine current;

            current = file.ParseLine(fp);
            while (current.RecordType != RecordType.EndOfFile)
            {
                file.AddLine(current);
                current = file.ParseLine(fp);
            }

            fp.Close();

            return file;
        }