Пример #1
0
        /*********************************************************************/
        /// <summary>
        /// Constructor - Blank, for use when creating a brand new S19 line
        /// </summary>
        public S19Line()
        {
            _LineNumber    = 0;
            _Instruction   = S19Instruction.Unknown;
            _Size          = 0;
            _Address       = 0;
            _Data          = "";
            _Checksum      = 0;
            _AddressLength = 0;
            _RawLine       = "";

            ByteSpacingEnabled = false;
        }
Пример #2
0
        /*********************************************************************/
        /// <summary>
        /// Updates the S19 line object given a defined value from an
        /// ObjectListView column
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public void UpdateLine(S19ElementType element, object value)
        {
            switch (element)
            {
            case S19ElementType.Instruction:
                try
                {
                    /* update the instruction and the address length expected for that instruction */
                    _Instruction = (S19Instruction)value;
                    switch (_Instruction)
                    {
                    case S19Instruction.S0:
                    case S19Instruction.S1:
                    case S19Instruction.S5:
                    case S19Instruction.S9:
                    default:
                        _AddressLength = LEN_S0_ADDR;
                        break;

                    case S19Instruction.S2:
                    case S19Instruction.S8:
                        _AddressLength = LEN_S2_ADDR;
                        break;

                    case S19Instruction.S3:
                    case S19Instruction.S7:
                        _AddressLength = LEN_S3_ADDR;
                        break;
                    }
                }
                catch {; }
                break;

            case S19ElementType.Size:
                if (Util.OnlyHexInString((string)value))
                {
                    try { _Size = Byte.Parse((string)value, System.Globalization.NumberStyles.HexNumber); }
                    catch {; }
                }
                break;

            case S19ElementType.Address:
                if (Util.OnlyHexInString((string)value))
                {
                    this.Address = (string)value;     /* (write to the property which will perform the conversion) */
                }
                break;

            case S19ElementType.Data:
                if ((((string)value).Length % 2) != 0)
                {
                    _Data = (string)value;
                }
                else
                {
                    _Data = (string)value;
                }
                if ((!Util.OnlyHexInString((string)value)) && ((string)value != ""))
                {
                    throw new Exception("Non-hex characters found in data!");
                }
                break;

            case S19ElementType.Checksum:
                if (Util.OnlyHexInString((string)value))
                {
                    try { _Checksum = Byte.Parse((string)value, System.Globalization.NumberStyles.HexNumber); }
                    catch {; }
                }
                break;

            case S19ElementType.ASCII:
                /* todo */
                break;

            default:
            {; }
            break;
            }

            /* with the element updated, update the rest of the row, including the new checksum (dont
             * update the checksum if the cell being changed is the checksum as we'll assume the user
             * wants to overrwrite the calculated checksum */
            _RawLine = CreateRawLine();
            if (element != S19ElementType.Checksum)
            {
                CalculateChecksum(true);
            }
        }
Пример #3
0
        /*********************************************************************/
        /// <summary>
        /// Updates the S19 line object given a raw data string
        /// </summary>
        /// <param name="line"></param>
        public void UpdateLine(string line)
        {
            try
            {
                _RawLine = line;
                string strInstr = line.Substring(IDX_INSTRUCTION, LEN_INSTRUCTION);
                _Size     = System.Convert.ToByte(line.Substring(IDX_LINELENGTH, IDX_LINELENGTH), 16);
                _Checksum = System.Convert.ToByte(line.Substring(line.Length - LEN_CSUM, LEN_CSUM), 16);
                switch (strInstr)
                {
                case "S0":
                    this._Instruction   = S19Instruction.S0;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S0_ADDR), 16);
                    this._Data          = line.Substring(IDX_S0_DATA, line.Length - LEN_CSUM - IDX_S0_DATA);
                    this._AddressLength = LEN_S0_ADDR;
                    break;

                case "S1":
                    this._Instruction   = S19Instruction.S1;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S1_ADDR), 16);
                    this._Data          = line.Substring(IDX_S1_DATA, line.Length - LEN_CSUM - IDX_S1_DATA);
                    this._AddressLength = LEN_S1_ADDR;
                    break;

                case "S2":
                    this._Instruction   = S19Instruction.S2;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S2_ADDR), 16);
                    this._Data          = line.Substring(IDX_S2_DATA, line.Length - LEN_CSUM - IDX_S2_DATA);
                    this._AddressLength = LEN_S2_ADDR;
                    break;

                case "S3":
                    this._Instruction   = S19Instruction.S3;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S3_ADDR), 16);
                    this._Data          = line.Substring(IDX_S3_DATA, line.Length - LEN_CSUM - IDX_S3_DATA);
                    this._AddressLength = LEN_S3_ADDR;
                    break;

                case "S5":
                    this._Instruction   = S19Instruction.S5;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S5_ADDR), 16);
                    this._Data          = line.Substring(IDX_S5_DATA, line.Length - LEN_CSUM - IDX_S5_DATA);
                    this._AddressLength = LEN_S5_ADDR;
                    break;

                case "S7":
                    this._Instruction   = S19Instruction.S7;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S7_ADDR), 16);
                    this._Data          = line.Substring(IDX_S7_DATA, line.Length - LEN_CSUM - IDX_S7_DATA);
                    this._AddressLength = LEN_S7_ADDR;
                    break;

                case "S8":
                    this._Instruction   = S19Instruction.S8;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S8_ADDR), 16);
                    this._Data          = line.Substring(IDX_S8_DATA, line.Length - LEN_CSUM - IDX_S8_DATA);
                    this._AddressLength = LEN_S8_ADDR;
                    break;

                case "S9":
                    this._Instruction   = S19Instruction.S9;
                    this._Address       = System.Convert.ToUInt32(line.Substring(IDX_ADDR, LEN_S9_ADDR), 16);
                    this._Data          = line.Substring(IDX_S9_DATA, line.Length - LEN_CSUM - IDX_S9_DATA);
                    this._AddressLength = LEN_S9_ADDR;
                    break;

                default:
                    this._Instruction = S19Instruction.Unknown;
                    break;
                }
            }
            catch
            {
                ExceptionTrap.Trap("Error reading S19 data!");
            }
        }