Пример #1
0
 private void shutdown()
 {
     try
     {
         util.startStopDevice(device, false, false);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
 }
        public void run()
        {
            try {
                ConcurrentQueue <String> queue = new ConcurrentQueue <String>();
                this.util.startStopDevice(device, false, false);
                this.util.setDeviceMode(this.device, "EPCBULK-EAS", true);
                util.startStopDevice(device, true, false);
                tcpReader = new TCPReader(this.util.getAddress(), queue, this.util);
                Thread tcpReaderThread = new Thread(new ThreadStart(tcpReader.run));
                tcpReaderThread.Start();

                while (true)
                {
                    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);
                                string msg = iterator.Current;
                                if (msg.Contains("<deviceEventMessage>") && msg.Contains("TAG_ALARM"))
                                {
                                    XmlDocument xml = new XmlDocument();
                                    xml.LoadXml(msg);
                                    Console.WriteLine(xml.OuterXml);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Console.WriteLine("[ERROR] The function 'parseXML' 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 run(long time)
        {
            try
            {
                this.util.setDeviceMode(this.device, "Alarm mode", false);
                this.util.setReadMode(this.device, "EPC_EAS_ALARM", false);
                util.startStopDevice(device, true, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            ConcurrentQueue <String> queue       = new ConcurrentQueue <String>();
            List <String>            tagDataList = new List <String>();

            Console.WriteLine("Device[" + device.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();

            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.processAlarmMessages(this.device, dTag, this.epcToAlarm);
                    }
                }
            }
            tcpReader.Shutdown();

            try
            {
                util.startStopDevice(device, false, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
        public void run(long inventoryTime)
        {
            try
            {
                this.util.setDeviceMode(device, "Autonomous", false);
                util.startStopDevice(device, true, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            ConcurrentQueue <String> queue       = new ConcurrentQueue <String>();
            List <String>            tagDataList = new List <String>();

            Console.WriteLine("Device[" + device.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();

            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.processTCPdata(dTag, tagDataList);
                        HashSet <String> hashset = new HashSet <String> ();


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

                        tagDataList.Clear();

                        Console.WriteLine("read: " + hashset.ToList().ToString());
                    }
                }
            }
            tcpReader.Shutdown();

            try
            {
                util.startStopDevice(device, false, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }