예제 #1
0
        public void parseXML(Device d)
        {
            try {
                ConcurrentQueue <String> queue = new ConcurrentQueue <String>();
                this.util.startStopDevice(d, false, false);
                this.util.setDeviceMode(d, "Autonomous", false);
                this.util.startStopDevice(d, true, false);
                TCPReader tcpReader       = new TCPReader(this.util.getAddress(), queue, this.util);
                Thread    tcpReaderThread = new Thread(new ThreadStart(tcpReader.run));
                tcpReaderThread.Start();

                Stopwatch stopwatch2 = new Stopwatch();
                stopwatch2.Start();

                long inventoryTime = 1000;                 //Milliseconds

                /*
                 * This loop will wait until the queue of events has something,
                 * it will deque the elements, parse them, and print only the
                 * gpi events
                 */
                while (stopwatch2.ElapsedMilliseconds < inventoryTime)
                {
                    while (queue.IsEmpty)
                    {
                        try
                        {
                            Thread.Sleep(20);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine("Thread sleeping failure: " + exc.Source);
                        }
                    }

                    if (!queue.IsEmpty)
                    {
                        string tag;
                        while (queue.TryDequeue(out tag))
                        {
                            string         dTag        = tag;
                            Queue <string> parsedQueue = new Queue <string>();
                            this.util.parseXML(dTag, parsedQueue);
                            var iterator = parsedQueue.GetEnumerator();
                            while (iterator.MoveNext())
                            {
                                Console.WriteLine("Dequeued item " + iterator.Current);
                            }
                        }
                    }
                }

                this.util.startStopDevice(d, false, false);
                tcpReader.Shutdown();
                Console.WriteLine("[INFO] The function 'parseXML' was successful");
            } catch (Exception e) {
                Console.WriteLine("[ERROR] The function 'parseXML' has failed");
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #2
0
        public void processAlarmMessages(Device d)
        {
            try {
                ConcurrentQueue <String> queue = new ConcurrentQueue <String>();
                this.util.setDeviceMode(d, "Autonomous", false);
                this.util.startStopDevice(d, true, false);
                TCPReader tcpReader       = new TCPReader(this.util.getAddress(), queue, this.util);
                Thread    tcpReaderThread = new Thread(new ThreadStart(tcpReader.run));
                tcpReaderThread.Start();
                String epcToAlarm = "6666fbbbdc2b0862b81191c1";

                Stopwatch stopwatch2 = new Stopwatch();
                stopwatch2.Start();

                long inventoryTime = 1000;                 //Milliseconds

                /*
                 * This loop will wait until the queue of events has something,
                 * it will deque the elements, parse them, and print only the
                 * gpi events
                 */
                while (stopwatch2.ElapsedMilliseconds < inventoryTime)
                {
                    while (queue.IsEmpty)
                    {
                        try
                        {
                            Thread.Sleep(20);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine("Thread sleeping failure: " + exc.Source);
                        }
                    }

                    if (!queue.IsEmpty)
                    {
                        string tag;
                        while (queue.TryDequeue(out tag))
                        {
                            string dTag = tag;
                            this.util.processAlarmMessages(d, dTag, epcToAlarm);
                        }
                    }
                }

                this.util.startStopDevice(d, false, false);
                tcpReader.Shutdown();
                Console.WriteLine("[INFO] The function 'processAlarmMessages' was successful");
            } catch (Exception e) {
                Console.WriteLine("[ERROR] The function 'processAlarmMessages' has failed");
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #3
0
        public void processTCPData(Device d)
        {
            try
            {
                this.util.setDeviceMode(d, "Autonomous", false);
                util.startStopDevice(d, true, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            ConcurrentQueue <String> queue       = new ConcurrentQueue <String>();
            List <String>            tagDataList = new List <String>();

            Console.WriteLine("Device[" + d.id + "] Reading the 3177 port... ");
            TCPReader tcpReader       = new TCPReader(this.address, queue, this.util);
            Thread    tcpReaderThread = new Thread(new ThreadStart(tcpReader.run));

            tcpReaderThread.Start();
            Console.WriteLine("Done.");

            Stopwatch stopwatch2 = new Stopwatch();

            stopwatch2.Start();

            long time = 10000;

            /*
             * This loop will wait until the queue of events has something,
             * it will deque the elements, parse them, and print only the
             * gpi events
             */
            while (stopwatch2.ElapsedMilliseconds < time)
            {
                while (queue.IsEmpty)
                {
                    try
                    {
                        Thread.Sleep(20);
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine("Thread sleeping failure: " + exc.Source);
                    }
                }

                if (!queue.IsEmpty)
                {
                    string tag;
                    while (queue.TryDequeue(out tag))
                    {
                        string dTag = tag;
                        this.util.processTCPdata(dTag, tagDataList);

                        foreach (String tagData in tagDataList)
                        {
                            Console.WriteLine("epc: " + tagData);
                        }

                        tagDataList.Clear();
                    }
                }
            }
            tcpReader.Shutdown();

            try
            {
                util.startStopDevice(d, false, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            tcpReader.Shutdown();
        }
예제 #4
0
        public void processGPIdata(Device d)
        {
            try {
                ConcurrentQueue <String> queue = new ConcurrentQueue <String>();
                Console.WriteLine("Device[" + d.id + "] Reading the 3177 port... ");
                TCPReader tcpReader       = new TCPReader(this.util.getAddress(), queue, this.util);
                Thread    tcpReaderThread = new Thread(new ThreadStart(tcpReader.run));
                tcpReaderThread.Start();
                GPIevent readerGPIevent = new GPIevent();
                Console.WriteLine("Done.");

                Stopwatch stopwatch2 = new Stopwatch();
                stopwatch2.Start();

                long inventoryTime = 1000;                 //Milliseconds

                /*
                 * This loop will wait until the queue of events has something,
                 * it will deque the elements, parse them, and print only the
                 * gpi events
                 */
                while (stopwatch2.ElapsedMilliseconds < inventoryTime)
                {
                    while (queue.IsEmpty)
                    {
                        try
                        {
                            Thread.Sleep(20);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine("Thread sleeping failure: " + exc.Source);
                        }
                    }

                    if (!queue.IsEmpty)
                    {
                        string tag;
                        while (queue.TryDequeue(out tag))
                        {
                            string dTag = tag;
                            if (!dTag.Contains("<type>GPI</type>"))
                            {
                                continue;
                            }

                            readerGPIevent = this.util.processGPIdata(dTag);

                            if (readerGPIevent == null)
                            {
                                continue;
                            }
                            Console.WriteLine(readerGPIevent.ToString());
                        }
                    }
                }

                this.util.startStopDevice(d, false, false);
                tcpReader.Shutdown();
                Console.WriteLine("[INFO] The function 'processGPIdata' was successful");
            } catch (Exception e) {
                Console.WriteLine("[ERROR] The function 'processGPIdata' has failed");
                Console.WriteLine(e.StackTrace);
            }
        }