Exemplo n.º 1
0
        public virtual NotificationEntry DeleteNotification(int notificationHandle, out AdsErrorCode result)
        {
            result = AdsErrorCode.NoError;
            NotificationEntry entry = null;
            Dictionary <int, NotificationEntry> dictionary = this._notificationTable;

            lock (dictionary)
            {
                if (this._notificationTable.ContainsKey(notificationHandle))
                {
                    entry = this._notificationTable[notificationHandle];
                }
            }
            if (entry == null)
            {
                result = AdsErrorCode.ClientRemoveHash;
                return(null);
            }
            Dictionary <int, NotificationEntry> dictionary2 = this._notificationTable;

            lock (dictionary2)
            {
                this._notificationTable.Remove(notificationHandle);
            }
            return(entry);
        }
Exemplo n.º 2
0
 public void OnSyncNotification(int handle, long timeStamp, int length, NotificationEntry entry, bool bError)
 {
     if (handle == this._symbolVersionHandle)
     {
         if (!bError)
         {
             this.OnSymbolVersionChanged(new AdsSymbolVersionChangedEventArgs(entry.data.GetBuffer()[0]));
         }
     }
     else if (handle != this._adsStateHandle)
     {
         if (bError)
         {
             this._iNoteReceiver.OnNotificationError(handle, timeStamp);
         }
         else
         {
             this._iNoteReceiver.OnNotification(handle, timeStamp, length, entry);
         }
     }
     else if (!bError)
     {
         StateInfo    state  = new StateInfo();
         BinaryReader reader = new BinaryReader(entry.data)
         {
             BaseStream = { Position = 0L }
         };
         state.AdsState    = (AdsState)reader.ReadInt16();
         state.DeviceState = reader.ReadInt16();
         this.OnAdsStateChanged(new AdsStateChangedEventArgs(state));
     }
 }
Exemplo n.º 3
0
 public void OnSyncNotification(int handle, long timeStamp, int length, NotificationEntry entry, bool bError)
 {
     if (this.syncMsgReceiver != null)
     {
         this.syncMsgReceiver.OnSyncNotification(handle, timeStamp, length, entry, bError);
     }
 }
Exemplo n.º 4
0
 public void PostNotification(int handle, long timeStamp, int length, NotificationEntry entry, bool bError)
 {
     if (this.syncNoteReceiver != null)
     {
         object[] objArray1 = new object[] { handle, timeStamp, length, entry, bError };
         base.BeginInvoke(this.notificationDelegate, objArray1);
     }
 }
Exemplo n.º 5
0
        public override int AddNotification(string variableName, AdsStream data, int offset, int length, int transMode, int cycleTime, int maxDelay, object userData, out AdsErrorCode result)
        {
            int clientHandle = 0;

            result = base._symbolTable.TryCreateVariableHandle(variableName, out clientHandle);
            if (result != AdsErrorCode.NoError)
            {
                return(0);
            }
            uint serverHandle = base._symbolTable.GetServerHandle(clientHandle, out result);

            if (result != AdsErrorCode.NoError)
            {
                return(0);
            }
            result = AdsErrorCode.NoError;
            if (!base._bInitialized)
            {
                this.Init();
            }
            cycleTime /= 0x2710;
            if (cycleTime <= 50)
            {
                cycleTime = 50;
            }
            int nextHandle          = this.GetNextHandle();
            NotificationEntry entry = base.AddNotification(nextHandle, nextHandle, clientHandle, data, offset, length, userData);
            ITimer            timer = this._timer;

            lock (timer)
            {
                CycleTableEntry entry2;
                if (!this._cycleTable.TryGetValue(cycleTime, out entry2))
                {
                    entry2 = new CycleTableEntry {
                        lastRead   = NativeMethods.GetTickCount(),
                        timerCount = 0,
                        cycleList  = new List <CycleListEntry>()
                    };
                    this._cycleTable.Add(cycleTime, entry2);
                }
                CycleListEntry item = new CycleListEntry {
                    handle   = nextHandle,
                    variable =
                    {
                        indexGroup  =       0xf005,
                        indexOffset = serverHandle,
                        length      = entry.length
                    },
                    transMode = transMode,
                    data      = new byte[entry.length]
                };
                entry2.cycleList.Add(item);
                this._initialNotes.Add(item);
            }
            return(nextHandle);
        }
Exemplo n.º 6
0
        protected NotificationEntry AddNotification(int notificationHandle, int clientHandle, int variableHandle, AdsStream data, int offset, int length, object userData)
        {
            NotificationEntry entry = new NotificationEntry {
                length         = length,
                offset         = offset,
                data           = data,
                userData       = userData,
                clientHandle   = clientHandle,
                variableHandle = variableHandle
            };
            Dictionary <int, NotificationEntry> dictionary = this._notificationTable;

            lock (dictionary)
            {
                this._notificationTable.Add(notificationHandle, entry);
            }
            return(entry);
        }
        public override NotificationEntry DeleteNotification(int notificationHandle, out AdsErrorCode result)
        {
            if (!this._clientHandleTable.ContainsKey(notificationHandle))
            {
                result = AdsErrorCode.ClientRemoveHash;
                return(null);
            }
            int num = this._clientHandleTable[notificationHandle];
            NotificationEntry entry = base.DeleteNotification(num, out result);

            if (entry != null)
            {
                this._clientHandleTable.Remove(entry.clientHandle);
                result = base._syncPort.DelDeviceNotification(num, false);
                if (entry.variableHandle != 0)
                {
                    AdsErrorCode code = base._symbolTable.TryDeleteVariableHandle(entry.variableHandle);
                }
            }
            return(entry);
        }
Exemplo n.º 8
0
        public void OnSyncNotification(QueueElement element)
        {
            NotificationEntry entry = null;
            Dictionary <int, NotificationEntry> dictionary = this._notificationTable;

            lock (dictionary)
            {
                if (this._notificationTable.ContainsKey(element.handle))
                {
                    entry = this._notificationTable[element.handle];
                }
            }
            try
            {
                if (entry != null)
                {
                    if ((entry.length < element.data.Length) || (element.data.Length == 0))
                    {
                        this._syncPort.OnSyncNotification(entry.clientHandle, element.timeStamp, element.data.Length, entry, true);
                    }
                    else
                    {
                        entry.data.Position = entry.offset;
                        if (entry.data.GetBuffer() != element.data)
                        {
                            entry.data.Write(element.data, 0, element.data.Length);
                            entry.data.Position = entry.offset;
                        }
                        this._syncPort.OnSyncNotification(entry.clientHandle, element.timeStamp, element.data.Length, entry, false);
                    }
                }
            }
            catch (Exception exception)
            {
                this.OnNotificationError(exception);
            }
        }
Exemplo n.º 9
0
        public override NotificationEntry DeleteNotification(int notificationHandle, out AdsErrorCode result)
        {
            result = AdsErrorCode.NoError;
            this._handleTable.Remove(notificationHandle);
            NotificationEntry entry = base.DeleteNotification(notificationHandle, out result);

            if (entry != null)
            {
                ITimer timer = this._timer;
                lock (timer)
                {
                    int index = 0;
                    while (true)
                    {
                        if (index < this._initialNotes.Count)
                        {
                            if (this._initialNotes[index].handle == notificationHandle)
                            {
                                this._initialNotes.RemoveAt(index);
                            }
                            index++;
                            continue;
                        }
                        using (Dictionary <int, CycleTableEntry> .Enumerator enumerator = this._cycleTable.GetEnumerator())
                        {
                            while (true)
                            {
                                if (!enumerator.MoveNext())
                                {
                                    break;
                                }
                                KeyValuePair <int, CycleTableEntry> current = enumerator.Current;
                                CycleTableEntry entry2 = current.Value;
                                int             num2   = 0;
                                while (true)
                                {
                                    if (num2 >= entry2.cycleList.Count)
                                    {
                                        break;
                                    }
                                    if (entry2.cycleList[num2].handle != notificationHandle)
                                    {
                                        num2++;
                                        continue;
                                    }
                                    entry2.cycleList.RemoveAt(num2);
                                    if (entry2.cycleList.Count == 0)
                                    {
                                        this._cycleTable.Remove(current.Key);
                                    }
                                    return(entry);
                                }
                            }
                        }
                        break;
                    }
                }
                if (entry.variableHandle != 0)
                {
                    AdsErrorCode code = base._symbolTable.TryDeleteVariableHandle(entry.variableHandle);
                }
            }
            return(entry);
        }