Exemple #1
0
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <code>A</code> with
 /// a specified number of length bytes. This form of the constructor is not
 /// needed much nowadays.  In the past there were situations where the equipment
 /// required that messages contained SECSItems that had a specified number of
 /// length bytes. This form of the constructor is here to handle these problem child cases.
 /// Note: It will be created with the number of length bytes set
 /// to the greater of the number of length bytes specified or
 /// the number required based on the length of the <c>value</c> parameter.
 /// </summary>
 /// <param name="value">The value to be assigned to this SECSItem.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this SECSItem.</param>
 public ASCIISECSItem(string value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.A, value == null ? 0 : value.Length, desiredNumberOfLengthBytes)
 {
     if (value != null)
     {
         this.value = value;
     }
 }
 /// <summary>
 /// This constructor creates a <c>SECSItem</c> that has a type of <c>L</c>
 /// with the specified value and specified number of length bytes.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 /// Note: It will be created with the greater of the specified number of length bytes
 /// or the number of length bytes required to
 /// accommodate the size of the provided list of <c>SECSItem</c>s.
 /// </summary>
 /// <param name="value">The value to be assigned to this <code>SECSItem</code>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public ListSECSItem(LinkedList <SECSItem> value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.L, value == null ? 0 : value.Count, desiredNumberOfLengthBytes)
 {
     if (value == null)
     {
         this.value = new LinkedList <SECSItem>();
     }
     else
     {
         this.value = value;
     }
 }
        /// <summary>
        /// This is a base class constructor for a <c>SECSItem</c>.  When using this constructor, the
        /// outbound number of length bytes will be set to the minimum number required to
        /// handle an item with the length that is specified by the value of the
        /// <c>length</c> parameter.
        ///
        /// This constructor sets the following base class attributes from the provided data:
        /// <c>formatCode</c>, <c>lengthInBytes</c>, and <c>outboundNumberOfLengthBytes</c>.
        /// </summary>
        /// <param name="formatCode">The Format Code of the created <c>SECSItem</c>.</param>
        /// <param name="lengthInBytes">The length in bytes of the item, or in the case of a
        /// <c>ListSECSItem</c> the number of items it contains.It must be between 0
        /// and 16777215 inclusive..</param>
        protected SECSItem(SECSItemFormatCode formatCode, int lengthInBytes)
        {
            if (lengthInBytes < 0 || lengthInBytes > (int)0x00FFFFFF)
            {
                throw new ArgumentException(
                          "The value for the length argument must be between 0 and 16777215 inclusive.");
            }

            this.formatCode             = formatCode;
            this.lengthInBytes          = lengthInBytes;
            outboundNumberOfLengthBytes = CalculateMinimumNumberOfLengthBytes(lengthInBytes);
        }
        /// <summary>
        /// This method is used to change the number of length bytes used when this
        /// <c>SECSItem</c> is converted to its &quot;wire/transmission&quot; format. The
        /// value the number of length bytes will actually set to the greater of
        /// the minimum required or the number desired.
        /// </summary>
        /// <param name="length">The length length in bytes of the <c>SECSItem</c>.</param>
        /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used
        /// for this <c>SECSItem</c>. The value for the number of length bytes must
        /// be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
        public void SetOutboundNumberOfLengthBytes(int length, SECSItemNumLengthBytes desiredNumberOfLengthBytes)
        {
            if (length < 0 || length > (int)0x00FFFFFF)
            {
                throw new ArgumentException(
                          "The value for the length argument must be between 0 and 16777215 inclusive.");
            }

            outboundNumberOfLengthBytes = CalculateMinimumNumberOfLengthBytes(length);
            if (outboundNumberOfLengthBytes.CompareTo(desiredNumberOfLengthBytes) < 0)
            {
                outboundNumberOfLengthBytes = desiredNumberOfLengthBytes;
            }
        }
        /// <summary>
        /// Return the minimum number of length bytes required based on the
        /// specified length.  The result should be SECSItemNumLengthBytes.ONE,
        /// SECSItemNumLengthBytes.TWO, or SECSItemNumLengthBytes.THREE.
        /// The maximum length of a <c>SECSItem</c> in its &quot; wire/transmission format&quot;
        /// is 16777215 (stored in 24 bits).
        /// </summary>
        /// <returns>The minimum number of length bytes required.</returns>
        /// <param name="lengthOfData">The length of the data in bytes.</param>
        private SECSItemNumLengthBytes CalculateMinimumNumberOfLengthBytes(int lengthOfData)
        {
            SECSItemNumLengthBytes result = SECSItemNumLengthBytes.ONE;

            if (lengthOfData > 255)
            {
                if (lengthOfData < 65536)
                {
                    result = SECSItemNumLengthBytes.TWO;
                }
                else
                {
                    result = SECSItemNumLengthBytes.THREE;
                }
            }

            return(result);
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:com.CIMthetics.CSharpSECSTools.SECSItems.F8SECSItem"/> class.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public F8SECSItem(double value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.F8, 8, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>I4</c>
 /// with the specified value.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 ///
 /// Note: It will be created with the number of length bytes set to greater of,
 /// the specified number of length bytes or the number required based on the
 /// length (in elements) of the<code>int []</code> provided.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I4ArraySECSItem(Int32[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I4, value.Length * 4, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:com.CIMthetics.CSharpSECSTools.SECSItems.U8ArraySECSItem"/> class.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public U8ArraySECSItem(UInt64[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.U8, value.Length * 8, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #9
0
 /// <summary>
 /// This constructor creates a <c>SECSItem</c> that has a type of <c>F4</c>
 /// with the specified value. This form of the constructor is not needed
 /// much nowadays.  In the past there were situations where the equipment
 /// required that messages contained SECSItems that had a specified number
 /// of length bytes. This form of the constructor is here to handle these
 /// problem child cases. Note: It will be created with the specified number
 /// of length bytes.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <code>SECSItem</code>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public F4SECSItem(float value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.F4, 4, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// This constructor creates a <c>SECSItem</c> that has a type of <c>U8</c>
 /// with the specified value.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 /// Note: It will be created with the specified number of length bytes.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public U8SECSItem(UInt64 value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.U8, 8, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:com.CIMthetics.CSharpSECSTools.SECSItems.I1ArraySECSItem"/> class.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <code>SECSItem</code>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I1ArraySECSItem(sbyte[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I1, value.Length, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
        /// <summary>
        ///  This is a base class constructor for a SECSItem.  This form of the constructor
        /// is used when parsing wire/transmission format data and converting it into
        /// its "C# form".
        ///
        /// This constructor sets the following base class attributes from the provided data:
        /// <c>formatCode</c>,
        /// <c>inboundNumberOfLengthBytes</c>,
        /// <c>outboundNumberOfLengthBytes</c>
        /// <c>lengthInBytes</c> or if the <c>formatCode</c> is of type <c>L</c>(List) <c>lengthInBytes</c>
        /// will be the number of items in the list.
        ///
        /// The exception <c>ArgumentException</c> will be thrown in the following circumstances:
        /// the <c>data</c> argument is <c>null</c>, the <c>data</c> argument has a length of zero, or
        /// the number of length bytes parsed out is zero.
        ///
        /// In normal use the only time the <c>ArgumentException</c>
        /// exception should be caught is if you are reading data from a piece of
        /// equipment that does not properly speak SECS and you want to be able to
        /// recover from the error gracefully.Typically the ACM process will have
        /// detected this equipment and it will not be allowed into the factory in
        /// the first place.
        /// </summary>
        protected SECSItem(byte[] data, int itemOffset)
        {
            if (data == null)
            {
                throw new ArgumentNullException("\"data\" argument must not be null.");
            }

            if (data.Length < 2)
            {
                throw new ArgumentException("\"data\" argument must have a length >= 2.");
            }

            /*
             * if (data.Length == 0)
             * {
             *  throw new ArgumentException ("The number of length bytes is not allowed to be ZERO.");
             * }
             */

            formatCode = SECSItemFormatCodeFunctions.GetSECSItemFormatCodeFromNumber((byte)((data[itemOffset] >> 2) & 0x0000003F));

            byte[] temp1 = new byte[4];
            switch (data [itemOffset] & 0x03)
            {
            case 0:
            {
                throw new ArgumentException("The number of length bytes is not allowed to be ZERO.");
            }

            case 1:
            {
                inboundNumberOfLengthBytes  = SECSItemNumLengthBytes.ONE;
                outboundNumberOfLengthBytes = inboundNumberOfLengthBytes;
                temp1[0] = 0;
                temp1[1] = 0;
                temp1[2] = 0;
                temp1[3] = data[itemOffset + 1];

                break;
            }

            case 2:
            {
                inboundNumberOfLengthBytes  = SECSItemNumLengthBytes.TWO;
                outboundNumberOfLengthBytes = inboundNumberOfLengthBytes;
                if (data.Length < 3)
                {
                    throw new ArgumentException("With two length bytes the minimum length for the \"data\" argument is 3.");
                }

                temp1[0] = 0;
                temp1[1] = 0;
                temp1[2] = data[itemOffset + 1];
                temp1[3] = data[itemOffset + 2];
                break;
            }

            case 3:
            {
                inboundNumberOfLengthBytes  = SECSItemNumLengthBytes.THREE;
                outboundNumberOfLengthBytes = inboundNumberOfLengthBytes;
                if (data.Length < 4)
                {
                    throw new ArgumentException("With three length bytes the minimum length for the \"data\" argument is 4.");
                }

                temp1[0] = 0;
                temp1[1] = data[itemOffset + 1];
                temp1[2] = data[itemOffset + 2];
                temp1[3] = data[itemOffset + 3];
                break;
            }
            }

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(temp1);
            }

            lengthInBytes = BitConverter.ToInt32(temp1, 0);

            /*
             * if (formatCode == SECSItemFormatCode.L)
             *  numberOfElements = incomingDataLength;
             * else
             *  lengthInBytes = incomingDataLength;
             */
        }
 /// <summary>
 /// This is a base class constructor for a SECSItem.  When using this constructor, the
 /// number of length bytes will be set to the greater of, the specified number of
 /// length bytes, or the minimum number required to
 /// handle an item with the length that is specified by the value of the
 /// <c>lengthInBytes</c> parameter.
 /// This constructor sets the following base class attributes from the provided data:
 /// <c>formatCode</c>,
 /// <c>lengthInBytes</c>, and
 /// <c>outboundNumberOfLengthBytes</c>.
 /// Note: An <c>ArgumentException</c> will be thrown if the value of the
 /// <c>lengthInBytes</c> parameter is outside the range of 0 - 16777215
 /// inclusive.
 /// </summary>
 /// <param name="formatCode">The SECS Item Format code for this SECSItem.</param>
 /// <param name="lengthInBytes">The length in bytes that this SECSItem will take up in
 /// its wire/transmission format.</param>
 /// <param name="desiredNumberOfLengthBytes">This parameter expresses the desired
 /// number or length bytes to be used for this SECSItem when it is converted
 /// to its wire/transmission format.</param>
 protected SECSItem(SECSItemFormatCode formatCode, int lengthInBytes, SECSItemNumLengthBytes desiredNumberOfLengthBytes)
 {
     this.formatCode    = formatCode;
     this.lengthInBytes = lengthInBytes;
     SetOutboundNumberOfLengthBytes(lengthInBytes, desiredNumberOfLengthBytes);
 }
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>F4</c> with the specified value.
 /// This form of the constructor is not needed much nowadays.  In the past there were situations
 /// where the equipment required that messages contained SECSItems that had a specified number
 /// of length bytes. This form of the constructor is here to handle these problem child cases.
 /// Note: It will be created with the number of length bytes set to greater of, the specified
 /// number of length bytes or the number required based on the length (in elements) of the
 /// <c>float []</c> provided.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>..</param>
 public F4ArraySECSItem(float[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.F4, value.Length * 4, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>F8</c>
 /// with the specified value. This form of the constructor is not
 /// needed much nowadays.  In the past there were situations where
 /// the equipment required that messages contained SECSItems that
 /// had a specified number of length bytes. This form of the constructor
 /// is here to handle these problem child cases.
 ///
 /// Note: It will be created with the number of length bytes set to greater of,
 /// the specified number of length bytes or the number required based on the
 /// length (in elements) of the<code>double []</code> provided.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for
 /// this <c>SECSItem</c>. The value for the number of length bytes must be
 /// <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public F8ArraySECSItem(double[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.F8, value.Length * 8, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:com.CIMthetics.CSharpSECSTools.SECSItems.I2SECSItem"/> class.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I2SECSItem(Int16 value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I2, 2, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #17
0
 /// <summary>
 /// This constructor creates a <c>SECSItem</c> that has a type of <c>BO</c> with the specified value.
 /// This form of the constructor is not needed much nowadays.  In the past there were situations
 /// where the equipment required that messages contained <c>SECSItem</c>s that had a specified number
 /// of length bytes. This form of the constructor is here to handle these problem child cases.
 ///
 /// Note: It will be created with the number of length bytes set to greater of,
 /// the specified number of length bytes or the number required based on the
 /// length (in elements) of the <c>bool []</c> provided.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be<c> ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public BooleanArraySECSItem(bool[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.BO, value.Length, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #18
0
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>I1</c>
 /// with the specified value.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 ///
 /// Note: It will be created with the specified number of length bytes.
 /// </summary>
 /// <param name="value">The value to be assigned to this <code>SECSItem</code>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I1SECSItem(sbyte value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I1, 1, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
Exemple #19
0
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>I2</c> with the specified value.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 ///
 /// Note: It will be created with the number of length bytes set to greater of,
 /// the specified number of length bytes or the number required based on the
 /// length (in elements) of the<code>short []</code> provided.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I2ArraySECSItem(Int16[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I2, value.Length * 2, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:com.CIMthetics.CSharpSECSTools.SECSItems.I4SECSItem"/> class.
 /// </summary>
 /// <param name="value">The value to be assigned to this <c>SECSItem</c>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <c>SECSItem</c>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public I4SECSItem(Int32 value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.I4, 4, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>B</c> with
 /// a specified number of length bytes.
 ///
 /// This form of the constructor is not needed much nowadays.  In the past
 /// there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes.
 /// This form of the constructor is here to handle these problem child cases.
 ///
 /// Note: It will be created with the number of length bytes set
 /// to the greater of the number of length bytes specified or
 /// the number required based on the length of the <c>value</c>
 /// parameter.
 /// </summary>
 /// <param name="value">The value to be assigned to this SECSItem.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this SECSItem.
 /// The value for the number of length bytes must be ONE, TWO, or THREE..</param>
 public BinarySECSItem(byte[] value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.B, value.Length, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }
 /// <summary>
 /// This constructor creates a SECSItem that has a type of <c>BO</c>
 /// with the specified value. This form of the constructor is not needed much nowadays.
 /// In the past there were situations where the equipment required that messages
 /// contained SECSItems that had a specified number of length bytes. This form of the
 /// constructor is here to handle these problem child cases.
 /// Note: It will be created with the specified number of length bytes.
 /// </summary>
 /// <param name="value">The value to be assigned to this <code>SECSItem</code>.</param>
 /// <param name="desiredNumberOfLengthBytes">The number of length bytes to be used for this <code>SECSItem</code>.
 /// The value for the number of length bytes must be <c>ONE</c>, <c>TWO</c>, or <c>THREE</c>.</param>
 public BooleanSECSItem(bool value, SECSItemNumLengthBytes desiredNumberOfLengthBytes) : base(SECSItemFormatCode.BO, 1, desiredNumberOfLengthBytes)
 {
     this.value = value;
 }