示例#1
0
        /// <summary>
        /// Intel hex file decode
        /// </summary>
        /// <param name="FileName">hex file path</param>
        /// <param name="Data">data for hex format</param>
        /// <param name="FlahRAM">data for RAM format</param>
        /// <returns>decode result</returns>
        public bool IntelHexFormatDecode(string FileName, out FrameFormatStr[] Data, out byte[] FlahRAM)
        {
            string ReadBuff;
            byte   DataLenght = 0;

            char[] Buff = new char[20];
            for (int i = 0; i < FlahRAM.Length; i++)
            {
                FlahRAM[i] = 0xFF;
            }
            if (!File.Exists(FileName))
            {
                return(false);
            }
            StreamReader FileSR = new StreamReader(FileName);

            FileSR.BaseStream.Seek(0, SeekOrigin.Begin);
            FileSR.BaseStream.Position = 0;
            ReadBuff = FileSR.ReadLine();
            if (ReadBuff == null)
            {
                return(false);
            }
            Buff = ReadBuff.ToCharArray(0, 1);
            if (Buff[0] != ':')
            {
                return(false);
            }
            if (!IntelHexFormatCheckSum(ReadBuff))
            {
                return(false);
            }
            //Buff = ReadBuff.ToCharArray(1, 8);
            Data[0].DataLenght = Convert.ToByte(ReadBuff.Substring(1, 2), 16);
        }
示例#2
0
        /// <summary>
        /// Motorola hex file decode
        /// </summary>
        /// <param name="FileName">hex file path</param>
        /// <param name="Data">data for hex format</param>
        /// <param name="FlahRAM">data for RAM format</param>
        /// <returns>decode result</returns>
        public bool MotorolaHexFormatDecode(string FileName, out byte[][] Data, out byte[] FlahRAM)
        {
            string ReadBuff;

            char[] Buff = new char[20];
            for (int i = 0; i < FlahRAM.Length; i++)
            {
                FlahRAM[i] = 0xFF;
            }
            if (!File.Exists(FileName))
            {
                return(false);
            }
            StreamReader FileSR = new StreamReader(FileName);

            FileSR.BaseStream.Seek(0, SeekOrigin.Begin);
            FileSR.BaseStream.Position = 0;
            ReadBuff = FileSR.ReadLine();
            if (ReadBuff == null)
            {
                return(false);
            }
            Buff = ReadBuff.ToCharArray(0, 2);
            if (Buff[0] != 'S')
            {
                return(false);
            }
        }