Пример #1
0
        public bool parse(string line)
        {
            Regex rgx   = new Regex(@"^:(?<byteCount>[A-Fa-f0-9]{2})(?<address>[A-Fa-f0-9]{4})(?<type>[A-Fa-f0-9]{2})(?<data>[A-Fa-f0-9]*)(?<crc>[A-Fa-f0-9]{2})$");
            Match match = rgx.Match(line.Trim());

            if (!match.Success)
            {
                this.errNo = ErrorNum.WrongRecord;
                return(false);
            }
            this.byteCount  = byte.Parse(match.Groups["byteCount"].Value, NumberStyles.HexNumber);
            this.address    = ushort.Parse(match.Groups["address"].Value, NumberStyles.HexNumber);
            this.RecordType = (RecordTypeE)byte.Parse(match.Groups["type"].Value, NumberStyles.HexNumber);
            this.sdata      = match.Groups["data"].Value;
            this.crc        = byte.Parse(match.Groups["crc"].Value, NumberStyles.HexNumber);
            if (sdata.Length != (2 * byteCount))
            {
                this.errNo = ErrorNum.WrongLength;
            }
            this.data = str2bytesAr(sdata);
            calcCrc();
            if (this.crc != crcCal)
            {
                this.errNo = ErrorNum.WrongCRC;
            }
            return(this.errNo == ErrorNum.NoErr);
        }
Пример #2
0
        public bool parse(string line)
        {
            Regex rgx   = new Regex(@"^S(?<recordType>[0-9]{1})(?<byteCount>[A-Fa-f0-9]{2})(?<addressEtdata>[A-Fa-f0-9]*)(?<crc>[A-Fa-f0-9]{2})$");
            Match match = rgx.Match(line.Trim());

            if (!match.Success)
            {
                this.errNo = ErrorNum.WrongRecord;
                return(false);
            }
            this.RecordType = (RecordTypeE)byte.Parse(match.Groups["recordType"].Value, NumberStyles.HexNumber);
            this.byteCount  = byte.Parse(match.Groups["byteCount"].Value, NumberStyles.HexNumber);
            this.addrEtdata = match.Groups["addressEtdata"].Value;
            this.crc        = byte.Parse(match.Groups["crc"].Value, NumberStyles.HexNumber);
            if ((addrEtdata.Length + 2) != (2 * byteCount))
            {
                this.errNo = ErrorNum.WrongLength;
            }
            splitAddrEtData();
            calcCrc();
            if (this.crc != crcCal)
            {
                this.errNo = ErrorNum.WrongCRC;
            }
            this.errNo = ErrorNum.NoErr;
            return(this.errNo == ErrorNum.NoErr);
        }
Пример #3
0
 private byte crcCal;      // calculated crc
 public HexRecord()
 {
     this.errNo     = ErrorNum.NoErr;
     this.startCode = ':';
 }
Пример #4
0
 private byte crcCal;         // calculated crc
 public SRecord()
 {
     this.errNo = ErrorNum.NoErr;
 }