Esempio n. 1
0
        public OpcRequest Remove()
        {
            mtx.WaitOne();
            OpcRequest req = (OpcRequest)reqQueue.Dequeue();

            mtx.ReleaseMutex();
            return(req);
        }
Esempio n. 2
0
 //---------------------------------------------------------------
 // Queue OPC server access request
 public void Request(OpcRequest req)
 {
     if (SioGrp == null)
     {
         return;
     }
     Requests.Add(req);
 }
Esempio n. 3
0
        //-----------------------------------------------------
        // Thread that dequeues the requests and makes the OPC server access
        private void OpcAccessThread()
        {
            for (;;)    // Thread loop
            {
                if (Requests.Count() > 0)
                {
                    OpcRequest req = Requests.Remove();

                    // An item value is read and displayed in the defined TextBox.
                    if (req.Cmd == Command.Read)
                    {
                        OPCItemState val;
                        int          rtc = SioGrp.Read(OPCDATASOURCE.OPC_DS_CACHE, req.ItemID, out val);
                        if (!HRESULTS.Failed(rtc) && !HRESULTS.Failed(val.Error))
                        {
                            req.res = true;
                            req.Val = val.DataValue.ToString();
                        }
                    }

                    // A value is written to the OPC server item
                    else if (req.Cmd == Command.Write)
                    {
                        int rtc = SioGrp.Write(req.ItemID, req.Val);
                        if (!HRESULTS.Failed(rtc))
                        {
                            req.res = true;
                        }
                    }
                }

                Thread.Sleep(100);      // ms

                if (StopThread != null) // Thread kill request
                {
                    StopThread.Set();
                    return;          // terminate the thread
                }
            }
        }
Esempio n. 4
0
 public void Add(OpcRequest req)
 {
     mtx.WaitOne();
     reqQueue.Enqueue(req);
     mtx.ReleaseMutex();
 }