public void NotificationThread()
        {
            bool flag = false;
            Type type = null;

            this._enqueueEvent.WaitOne();
            while (base._bInitialized)
            {
                try
                {
                    QueueElement[]       array = null;
                    Queue <QueueElement> queue = this._queue;
                    lock (queue)
                    {
                        this._enqueueEvent.Reset();
                        int count = this._queue.Count;
                        if (count != 0)
                        {
                            array = new QueueElement[count];
                            this._queue.CopyTo(array, 0);
                            this._queue.Clear();
                            if (count >= 0x2328)
                            {
                                flag = true;
                            }
                        }
                    }
                    if ((array != null) && (array.Length != 0))
                    {
                        if ((base._syncWindow == null) || !base._bSynchronize)
                        {
                            base.OnSyncNotification(array);
                        }
                        else
                        {
                            base._syncWindow.PostNotification(array);
                        }
                    }
                    type = null;
                }
                catch (Exception exception)
                {
                    Type type2 = exception.GetType();
                    if (type2 != type)
                    {
                        base.OnNotificationError(exception);
                        type = type2;
                    }
                }
                if (base._bInitialized)
                {
                    this._enqueueEvent.WaitOne();
                }
            }
        }
 protected void OnNotification(int handle, long timeStamp, byte[] data)
 {
     if (!base._disposed)
     {
         QueueElement item = new QueueElement(handle, timeStamp, data);
         try
         {
             int count;
             Queue <QueueElement> queue = this._queue;
             lock (queue)
             {
                 count = this._queue.Count;
             }
             if (this._bPeak)
             {
                 if (count >= 0x2328)
                 {
                     if ((DateTime.Now.Ticks - this._bPeakStart) > 0x2faf080L)
                     {
                         if (!this._bPeakError)
                         {
                             this._bPeakError = true;
                             TcAdsDllWrapper.ThrowAdsException(AdsErrorCode.ClientQueueFull);
                         }
                         return;
                     }
                 }
                 else
                 {
                     this._bPeak      = false;
                     this._bPeakError = false;
                 }
             }
             else if (count >= 0x2710)
             {
                 this._bPeak      = true;
                 this._bPeakStart = DateTime.Now.Ticks;
             }
             Queue <QueueElement> queue2 = this._queue;
             lock (queue2)
             {
                 this._queue.Enqueue(item);
                 this._enqueueEvent.Set();
             }
         }
         catch (Exception exception)
         {
             base.OnNotificationError(exception);
         }
     }
 }
예제 #3
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);
            }
        }
예제 #4
0
        public void OnReadCycle(object sender, EventArgs e)
        {
            ITimer timer = this._timer;

            lock (timer)
            {
                if (!this._bStopTimer)
                {
                    try
                    {
                        List <CycleListEntry> list = new List <CycleListEntry>();
                        uint tickCount             = NativeMethods.GetTickCount();
                        long timeStamp             = DateTime.Now.ToFileTime();
                        int  num3 = 0;
                        while (true)
                        {
                            if (num3 >= this._initialNotes.Count)
                            {
                                foreach (KeyValuePair <int, CycleTableEntry> pair in this._cycleTable)
                                {
                                    int             key   = pair.Key;
                                    CycleTableEntry entry = pair.Value;
                                    entry.timerCount++;
                                    uint num5 = (tickCount - entry.lastRead) / entry.timerCount;
                                    if ((tickCount - entry.lastRead) >= key)
                                    {
                                        int num6 = 0;
                                        while (true)
                                        {
                                            if (num6 >= entry.cycleList.Count)
                                            {
                                                entry.lastRead   = tickCount;
                                                entry.timerCount = 0;
                                                break;
                                            }
                                            list.Add(entry.cycleList[num6]);
                                            num6++;
                                        }
                                    }
                                }
                                if (list.Count != 0)
                                {
                                    if (this._bSumupRead)
                                    {
                                        int    rdLength = list.Count * 4;
                                        int    wrLength = list.Count * sizeof(VariableInfo);
                                        byte[] wrData   = new byte[wrLength];
                                        int    num10    = 0;
                                        while (true)
                                        {
                                            ref byte pinned numRef;
                                            if (num10 >= list.Count)
                                            {
                                                int    num9;
                                                byte[] rdData = new byte[rdLength];
                                                if (base._syncPort.ReadWrite(0xf080, (uint)list.Count, 0, rdLength, rdData, 0, wrLength, wrData, false, out num9) != AdsErrorCode.NoError)
                                                {
                                                    CycleListEntry entry3       = list[0];
                                                    byte[]         data         = new byte[entry3.variable.length];
                                                    AdsErrorCode   adsErrorCode = base._syncPort.Read(entry3.variable.indexGroup, entry3.variable.indexOffset, 0, entry3.variable.length, data, false, out num9);
                                                    if (adsErrorCode != AdsErrorCode.NoError)
                                                    {
                                                        TcAdsDllWrapper.ThrowAdsException(adsErrorCode);
                                                    }
                                                    this._bSumupRead = false;
                                                }
                                                if (this._bSumupRead)
                                                {
                                                    int num11 = list.Count * 4;
                                                    int num12 = 0;
                                                    while (num12 < list.Count)
                                                    {
                                                        CycleListEntry entry4 = list[num12];
                                                        bool           flag2  = false;
                                                        int            index  = 0;
                                                        while (true)
                                                        {
                                                            if (index < 4)
                                                            {
                                                                if (rdData[index + (num12 * 4)] == 0)
                                                                {
                                                                    index++;
                                                                    continue;
                                                                }
                                                                flag2 = true;
                                                            }
                                                            if (flag2)
                                                            {
                                                                if ((base._syncWindow == null) || !base._bSynchronize)
                                                                {
                                                                    QueueElement[] elements = new QueueElement[] { new QueueElement(entry4.handle, timeStamp, new byte[0]) };
                                                                    base.OnSyncNotification(elements);
                                                                }
                                                                else
                                                                {
                                                                    QueueElement[] elements = new QueueElement[] { new QueueElement(entry4.handle, timeStamp, new byte[0]) };
                                                                    base._syncWindow.PostNotification(elements);
                                                                }
                                                                num11 += entry4.variable.length;
                                                            }
                                                            else
                                                            {
                                                                index = 0;
                                                                if ((num12 >= this._initialNotes.Count) && (entry4.transMode == 4))
                                                                {
                                                                    index = 0;
                                                                    while ((index < entry4.variable.length) && (rdData[num11 + index] == entry4.data[index]))
                                                                    {
                                                                        index++;
                                                                    }
                                                                }
                                                                if (index != entry4.variable.length)
                                                                {
                                                                    while (true)
                                                                    {
                                                                        if (index >= entry4.variable.length)
                                                                        {
                                                                            if ((base._syncWindow == null) || !base._bSynchronize)
                                                                            {
                                                                                QueueElement[] elements = new QueueElement[] { new QueueElement(entry4.handle, timeStamp, entry4.data) };
                                                                                base.OnSyncNotification(elements);
                                                                            }
                                                                            else
                                                                            {
                                                                                QueueElement[] elements = new QueueElement[] { new QueueElement(entry4.handle, timeStamp, entry4.data) };
                                                                                base._syncWindow.PostNotification(elements);
                                                                            }
                                                                            break;
                                                                        }
                                                                        entry4.data[index] = rdData[num11 + index];
                                                                        index++;
                                                                    }
                                                                }
                                                                num11 += entry4.variable.length;
                                                            }
                                                            num12++;
                                                            break;
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                            CycleListEntry entry2 = list[num10];
                                            try
                                            {
                                                byte[] buffer3;
                                                if (((buffer3 = wrData) == null) || (buffer3.Length == 0))
                                                {
                                                    numRef = null;
                                                }
                                                else
                                                {
                                                    numRef = buffer3;
                                                }
                                                numRef[num10 * sizeof(VariableInfo)] = (byte)entry2.variable;
                                            }
                                            finally
                                            {
                                                numRef = null;
                                            }
                                            rdLength += entry2.variable.length;
                                            num10++;
                                        }
                                    }
                                    if (!this._bSumupRead)
                                    {
                                        for (int i = 0; i < list.Count; i++)
                                        {
                                            int            num15;
                                            CycleListEntry entry5       = list[i];
                                            byte[]         data         = new byte[entry5.variable.length];
                                            AdsErrorCode   adsErrorCode = base._syncPort.Read(entry5.variable.indexGroup, entry5.variable.indexOffset, 0, entry5.variable.length, data, false, out num15);
                                            if (adsErrorCode != AdsErrorCode.NoError)
                                            {
                                                if (adsErrorCode != AdsErrorCode.DeviceInvalidOffset)
                                                {
                                                    TcAdsDllWrapper.ThrowAdsException(adsErrorCode);
                                                }
                                                else if ((base._syncWindow == null) || !base._bSynchronize)
                                                {
                                                    QueueElement[] elements = new QueueElement[] { new QueueElement(entry5.handle, timeStamp, new byte[0]) };
                                                    base.OnSyncNotification(elements);
                                                }
                                                else
                                                {
                                                    QueueElement[] elements = new QueueElement[] { new QueueElement(entry5.handle, timeStamp, new byte[0]) };
                                                    base._syncWindow.PostNotification(elements);
                                                }
                                            }
                                            int index = 0;
                                            if ((i >= this._initialNotes.Count) && (entry5.transMode == 4))
                                            {
                                                index = 0;
                                                while ((index < entry5.variable.length) && (data[index] == entry5.data[index]))
                                                {
                                                    index++;
                                                }
                                            }
                                            if (index != entry5.variable.length)
                                            {
                                                while (true)
                                                {
                                                    if (index >= entry5.variable.length)
                                                    {
                                                        if ((base._syncWindow == null) || !base._bSynchronize)
                                                        {
                                                            QueueElement[] elements = new QueueElement[] { new QueueElement(entry5.handle, timeStamp, entry5.data) };
                                                            base.OnSyncNotification(elements);
                                                        }
                                                        else
                                                        {
                                                            QueueElement[] elements = new QueueElement[] { new QueueElement(entry5.handle, timeStamp, entry5.data) };
                                                            base._syncWindow.PostNotification(elements);
                                                        }
                                                        break;
                                                    }
                                                    entry5.data[index] = data[index];
                                                    index++;
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                            list.Add(this._initialNotes[num3]);
                            num3++;
                        }
                    }