示例#1
0
        /// <summary>
        /// Generates data notification message.
        /// </summary>
        /// <param name="time">Date time. Set To Min or Max if not added</param>
        /// <param name="objects">List of objects and attribute indexes to notify.</param>
        /// <returns>Generated data notification message(s).</returns>
        public byte[][] GenerateDataNotificationMessages(DateTime time, List <KeyValuePair <GXDLMSObject, int> > objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }
            GXByteBuffer buff = new GXByteBuffer();

            buff.SetUInt8(DataType.Structure);
            GXCommon.SetObjectCount(objects.Count, buff);
            foreach (KeyValuePair <GXDLMSObject, int> it in objects)
            {
                AddData(it.Key, it.Value, buff);
            }
            byte[][] reply;
            if (UseLogicalNameReferencing)
            {
                GXDLMSLNParameters p = new GXDLMSLNParameters(Settings, 0, Command.DataNotification, 0, null, buff, 0xff);
                p.time = time;
                reply  = GXDLMS.GetLnMessages(p);
            }
            else
            {
                GXDLMSSNParameters p = new GXDLMSSNParameters(Settings, Command.DataNotification, 1, 0, buff, null);
                reply = GXDLMS.GetSnMessages(p);
            }
            return(reply);
        }
示例#2
0
        /// <summary>
        /// Sends Event Notification or Information Report Request.
        /// </summary>
        /// <param name="time">Send time.</param>
        /// <param name="list">List of COSEM object and attribute index to report.</param>
        /// <returns>Report request as byte array.</returns>
        public byte[][] GenerateReport(DateTime time, List <KeyValuePair <GXDLMSObject, int> > list)
        {
            if (list == null || list.Count == 0)
            {
                throw new ArgumentNullException("list");
            }
            if (UseLogicalNameReferencing && list.Count != 1)
            {
                throw new ArgumentException("Only one object can send with Event Notification request.");
            }

            GXByteBuffer buff = new GXByteBuffer();

            byte[][] reply;
            if (UseLogicalNameReferencing)
            {
                foreach (KeyValuePair <GXDLMSObject, int> it in list)
                {
                    buff.SetUInt16((ushort)it.Key.ObjectType);
                    buff.Set(GXCommon.LogicalNameToBytes(it.Key.LogicalName));
                    buff.SetUInt8((byte)it.Value);
                    AddData(it.Key, it.Value, buff);
                }
                GXDLMSLNParameters p = new GXDLMSLNParameters(Settings, 0, Command.EventNotification, 0, null, buff, 0xff);
                p.time = time;
                reply  = GXDLMS.GetLnMessages(p);
            }
            else
            {
                GXDLMSSNParameters p = new GXDLMSSNParameters(Settings, Command.InformationReport, list.Count, 0xFF, null, buff);
                foreach (KeyValuePair <GXDLMSObject, int> it in list)
                {
                    // Add variable type.
                    buff.SetUInt8(VariableAccessSpecification.VariableName);
                    int sn = it.Key.ShortName;
                    sn += (it.Value - 1) * 8;
                    buff.SetUInt16((UInt16)sn);
                }
                GXCommon.SetObjectCount(list.Count, buff);
                foreach (KeyValuePair <GXDLMSObject, int> it in list)
                {
                    AddData(it.Key, it.Value, buff);
                }
                reply = GXDLMS.GetSnMessages(p);
            }
            return(reply);
        }
示例#3
0
 /// <summary>
 /// Generates data notification message(s).
 /// </summary>
 /// <param name="time">Date time. Set To Min or Max if not added</param>
 /// <param name="data">Notification body.</param>
 /// <returns>Generated data notification message(s).</returns>
 public byte[][] GenerateDataNotificationMessages(DateTime time, GXByteBuffer data)
 {
     byte[][] reply;
     if (UseLogicalNameReferencing)
     {
         GXDLMSLNParameters p = new GXDLMSLNParameters(Settings, 0, Command.DataNotification, 0, null, data, 0xff);
         p.time       = time;
         p.time.Skip |= DateTimeSkips.Ms;
         reply        = GXDLMS.GetLnMessages(p);
     }
     else
     {
         GXDLMSSNParameters p = new GXDLMSSNParameters(Settings, Command.DataNotification, 1, 0, data, null);
         reply = GXDLMS.GetSnMessages(p);
     }
     return(reply);
 }
示例#4
0
 /// <summary>
 /// Generates data notification message(s).
 /// </summary>
 /// <param name="time">Date time. Set To Min or Max if not added</param>
 /// <param name="data">Notification body.</param>
 /// <returns>Generated data notification message(s).</returns>
 public byte[][] GenerateDataNotificationMessages(DateTime time, byte[] data)
 {
     byte[][] reply;
     if (UseLogicalNameReferencing)
     {
         GXDLMSLNParameters p = new GXDLMSLNParameters(Settings, 0, Command.DataNotification, 0, null, new GXByteBuffer(data), 0xff);
         p.time = time;
         reply  = GXDLMS.GetLnMessages(p);
     }
     else
     {
         GXDLMSSNParameters p = new GXDLMSSNParameters(Settings, Command.DataNotification, 1, 0, new GXByteBuffer(data), null);
         reply = GXDLMS.GetSnMessages(p);
     }
     if ((Settings.ProposedConformance & Conformance.GeneralBlockTransfer) == 0 && reply.Length != 1)
     {
         throw new ArgumentException("Data is not fit to one PDU. Use general block transfer.");
     }
     return(reply);
 }
        /// <summary>
        /// Sends Event Notification Request.
        /// </summary>
        /// <param name="time">Send time.</param>
        /// <param name="item">COSEM object and attribute index to report.</param>
        /// <returns>Report request as byte array.</returns>
        public byte[][] GenerateEventNotification(DateTime time, KeyValuePair <GXDLMSObject, int> item)
        {
            GXByteBuffer buff = new GXByteBuffer();

            byte[][] reply;
            if (UseLogicalNameReferencing)
            {
                buff.SetUInt16((ushort)item.Key.ObjectType);
                buff.Set(GXCommon.LogicalNameToBytes(item.Key.LogicalName));
                buff.SetUInt8((byte)item.Value);
                AddData(item.Key, item.Value, buff);
                GXDLMSLNParameters p = new GXDLMSLNParameters(null, Settings, 0, Command.EventNotification, 0, null, buff, 0xff, Command.None);
                p.time = time;
                reply  = GXDLMS.GetLnMessages(p);
            }
            else
            {
                throw new Exception("Use GenerateInformationReport when Short Name referencing is used.");
            }
            return(reply);
        }