Esempio n. 1
0
        //Move this to a helper class?
        internal static List<AdsNotification> GetNotifications(byte[] adsresponseInclAmsHeader)
        {
            var notifications = new List<AdsNotification>();

            int pos = 32;
            uint stamps = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 4);
            pos += 8;

            for (int i = 0; i < stamps; i++)
            {
                uint samples = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 8);
                pos += 12;

                for (int j = 0; j < samples; j++)
                {
                    var notification = new AdsNotification();
                    notification.NotificationHandle = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos);
                    uint length = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 4);
                    pos += 8;
                    notification.ByteValue = new byte[length];
                    Array.Copy(adsresponseInclAmsHeader, pos, notification.ByteValue, 0, (int)length);
                    notifications.Add(notification);
                    pos += (int)length;
                }
            }

            return notifications;
        }
Esempio n. 2
0
        //Move this to a helper class?
        internal static List <AdsNotification> GetNotifications(byte[] adsresponseInclAmsHeader)
        {
            var notifications = new List <AdsNotification>();

            int  pos    = 32;
            uint stamps = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 4);

            pos += 8;

            for (int i = 0; i < stamps; i++)
            {
                uint samples = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 8);
                pos += 12;

                for (int j = 0; j < samples; j++)
                {
                    var notification = new AdsNotification();
                    notification.NotificationHandle = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos);
                    uint length = BitConverter.ToUInt32(adsresponseInclAmsHeader, pos + 4);
                    pos += 8;
                    notification.ByteValue = new byte[length];
                    Array.Copy(adsresponseInclAmsHeader, pos, notification.ByteValue, 0, (int)length);
                    notifications.Add(notification);
                    pos += (int)length;
                }
            }

            return(notifications);
        }
 public AdsAddDeviceNotificationCommand(uint indexGroup, uint indexOffset, uint readLength, AdsTransmissionMode transmissionMode)
     : base(AdsCommandId.AddDeviceNotification)
 {
     this.readLength = readLength;
     this.indexGroup = indexGroup;
     this.indexOffset = indexOffset;
     this.transmissionMode = transmissionMode;
     this.notification = new AdsNotification();
 }
 public AdsNotificationArgs(AdsNotification notification)
 {
     this.Notification = notification;
 }
Esempio n. 5
0
        /// <summary>
        /// Add a noticiation when a variable changes or cyclic after a defined time in ms
        /// </summary>
        /// <param name="varHandle">The handle returned by GetSymhandleByName</param>
        /// <param name="length">The length of the data that must be send by the notification</param>
        /// <param name="transmissionMode">On change or cyclic</param>
        /// <param name="cycleTime">The cyclic time in ms. If used with OnChange, then the value is send once after this time in ms</param>
        /// <param name="userData">A custom object that can be used in the callback</param>
        /// <param name="TypeOfValue">The type of the returned notification value</param>
        /// <returns>The notification handle</returns>
        public override uint AddNotification(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type TypeOfValue)
        {
            AdsNotification note = new AdsNotification();
            note.Symhandle = varHandle;
            note.UserData = userData;
            note.TypeOfValue = TypeOfValue;
            note.ByteValue = new byte[length];
            NotificationRequests.Add(note);

            string varName = GetNameBySymhandle(varHandle);
            byte[] buffer = new byte[length];
            adsStream = Activator.CreateInstance(t_AdsStream, new object[] { buffer });

            if (transmissionMode == AdsTransmissionMode.Cyclic)
                adsTransMode = AdsTransMode_Cyclic;
            else
                adsTransMode = AdsTransMode_OnChange;

            note.NotificationHandle = 
                (uint)client.AddDeviceNotification(
                    varName,
                    adsStream, (int)0, (int)length,
                    adsTransMode, (int)cycleTime, (int)0,
                    userData);

            return note.NotificationHandle;
        }
Esempio n. 6
0
 public AdsNotificationArgs(AdsNotification notification)
 {
     this.Notification = notification;
 }