Gurux.DLMS.GXByteBuffer.Add C# (CSharp) Method

Add() public method

Add new object to the byte buffer.
public Add ( object value ) : void
value object Value to add.
return void
        public void Add(object value)
        {
            if (value != null)
            {
                if (value is byte[])
                {
                    Set((byte[])value);
                }
                else if (value is byte)
                {
                    SetUInt8((byte)value);
                }
                else if (value is UInt16)
                {
                    SetUInt16((UInt16)value);
                }
                else if (value is UInt32)
                {
                    SetUInt32((UInt32)value);
                }
                else if (value is UInt64)
                {
                    SetUInt64((UInt64)value);
                }
                else if (value is Int16)
                {
                    SetInt16((Int16)value);
                }
                else if (value is Int32)
                {
                    SetInt32((Int32)value);
                }
                else if (value is Int64)
                {
                    SetInt64((Int64)value);
                }
                else if (value is string)
                {
                    Set(ASCIIEncoding.ASCII.GetBytes((string)value));
                }
                else
                {
                    throw new ArgumentException("Invalid object type.");
                }
            }
        }

Usage Example

Exemplo n.º 1
0
        ///<summary>
        /// Handle action request.
        ///</summary>
        ///<param name="Reply">
        /// Received data from the client.
        ///</param>
        ///<returns>
        ///Reply.
        ///</returns>
        private byte[][] HandleMethodRequest()
        {
            GXByteBuffer data = Reply.Data;
            GXByteBuffer bb   = new GXByteBuffer();

            // Get type.
            data.GetUInt8();
            // Get invoke ID and priority.
            data.GetUInt8();
            // CI
            ObjectType ci = (ObjectType)data.GetUInt16();

            byte[] ln = new byte[6];
            data.Get(ln);
            // Attribute Id
            int id = data.GetUInt8();
            // Get parameters.
            object parameters = null;

            if (data.GetUInt8() != 0)
            {
                GXDataInfo info = new GXDataInfo();
                parameters = GXCommon.GetData(data, info);
            }
            GXDLMSObject obj = Settings.Objects.FindByLN(ci, GXDLMSObject.ToLogicalName(ln));

            if (obj == null)
            {
                obj = FindObject(ci, 0, GXDLMSObject.ToLogicalName(ln));
            }
            if (obj == null)
            {
                // Device reports a undefined object.
                addError(ErrorCode.UndefinedObject, bb);
                Debug.WriteLine("Undefined object.");
            }
            else
            {
                ValueEventArgs e = new ValueEventArgs(obj, id, 0, parameters);
                Action(e);
                if (e.Handled)
                {
                    bb.Add((obj as IGXDLMSBase).Invoke(Settings, id, parameters));
                }
                else
                {
                    bb.Add((obj as IGXDLMSBase).Invoke(Settings, id, parameters));
                }
            }
            return(GXDLMS.SplitPdu(Settings, Command.MethodResponse, 1, bb, ErrorCode.Ok, DateTime.MinValue)[0]);
        }
All Usage Examples Of Gurux.DLMS.GXByteBuffer::Add