示例#1
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);
        }
示例#2
0
        public uint AddNotification <T>(string varName, AdsTransmissionMode transmissionMode, uint cycleTime, object userData = null)
        {
            var  varHandle = GetSymhandleByName(varName);
            uint length    = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength);

            return(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeof(T)));
        }
示例#3
0
        public async Task <uint> AddNotificationAsync <T>(string varName, AdsTransmissionMode transmissionMode, uint cycleTime, uint arraylength = 1, object userData = null)
        {
            uint varHandle = await GetSymhandleByNameAsync(varName);

            var length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength, arraylength);
            var result = await AddNotificationAsync(varHandle, length, transmissionMode, cycleTime, userData, typeof(T));

            return(result);
        }
 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();
 }
示例#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 uint AddNotification(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type TypeOfValue)
 {
     var adsCommand = new AdsAddDeviceNotificationCommand(0x0000F005, varHandle, length, transmissionMode);
     adsCommand.CycleTime = cycleTime;
     adsCommand.UserData = userData;
     adsCommand.TypeOfValue = TypeOfValue;
     var result = adsCommand.Run(this.ams);
     adsCommand.Notification.NotificationHandle = result.NotificationHandle;
     return result.NotificationHandle;
 }
示例#6
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 GetSymhandleByNameAsync</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 async Task <uint> AddNotificationAsync(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type typeOfValue)
        {
            var adsCommand = new AdsAddDeviceNotificationCommand(0x0000F005, varHandle, length, transmissionMode);

            adsCommand.CycleTime   = cycleTime;
            adsCommand.UserData    = userData;
            adsCommand.TypeOfValue = typeOfValue;
            var result = await adsCommand.RunAsync(this.ams);

            adsCommand.Notification.NotificationHandle = result.NotificationHandle;
            return(result.NotificationHandle);;
        }
示例#7
0
 public uint AddNotification <T>(IAdsSymhandle adsSymhandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
 {
     return(AddNotification <T>(adsSymhandle.Symhandle, transmissionMode, cycleTime, userData));
 }
 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();
 }
示例#9
0
 public uint AddNotification(IAdsSymhandle adsSymhandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type TypeOfValue)
 {
     return(AddNotification(adsSymhandle.Symhandle, adsSymhandle.ByteLength, transmissionMode, cycleTime, userData, TypeOfValue));
 }
示例#10
0
        /// <summary>
        /// Add a noticiation when a variable changes or cyclic after a defined time in ms
        /// </summary>
        /// <typeparam name="T">Type for defining the length of the data that must be send by the notification</typeparam>
        /// <param name="varHandle">The handle returned by GetSymhandleByNameAsync</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>
        /// <returns></returns>
        public uint AddNotification <T>(uint varHandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
        {
            uint length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength);

            return(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeof(T)));
        }
示例#11
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>
 /// <returns>The notification handle</returns>
 public uint AddNotification(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
 {
     return(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeof(byte[])));
 }
示例#12
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;
        }
示例#13
0
 public Task <uint> AddNotificationAsync(IAdsSymhandle adsSymhandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
 {
     return(AddNotificationAsync(adsSymhandle.Symhandle, adsSymhandle.ByteLength, transmissionMode, cycleTime, userData));
 }
示例#14
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 GetSymhandleByNameAsync</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>
 /// <returns>The notification handle</returns>
 public Task<uint> AddNotificationAsync(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
 {
     return AddNotificationAsync(varHandle, length, transmissionMode, cycleTime, userData, typeof(byte[]));
 }
示例#15
0
 public override async Task<uint> AddNotificationAsync(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type typeOfValue)
 {
     return await Task.FromResult( AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeOfValue) );
 }
示例#16
0
 public Task<uint> AddNotificationAsync<T>(IAdsSymhandle adsSymhandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData)
 {
     return AddNotificationAsync<T>(adsSymhandle.Symhandle, transmissionMode, cycleTime, userData);
 }
示例#17
0
 public override async Task <uint> AddNotificationAsync(uint varHandle, uint length, AdsTransmissionMode transmissionMode, uint cycleTime, object userData, Type typeOfValue)
 {
     return(await Task.FromResult(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeOfValue)));
 }