void Timer2Tick(object sender, EventArgs e)
        {
            if (!BarcodeScanner2Running)
            {
                return;
            }

            Lib.BarcodeReader reader = new BarcodeReader();
            reader.Number  = Barcode2Counter;
            reader.Barcode = "";
            ReadStatus readStatus = ReadStatus.Blank;

            PLCInt plcInt1     = new PLCInt(Statics.Counter2DB);
            int    realCounter = plcInt1.Value;

            if (Math.Abs(realCounter - CorrectBarcodeScanCounter2) > 1)
            {
                readStatus     = ReadStatus.Blank;
                reader.Status  = readStatus;
                reader.Barcode = "";
                reader.Date    = DateTime.Now;
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    StopMachine2Motor();
                    StopBarcodeReader2();

                    BarcodeReader2Collection.Insert(0, reader);
                }));
            }
        }
Exemple #2
0
        private static void resetPLCCounter()
        {
            PLCBool counterReset = new PLCBool(ResetCounter);

            counterReset.Value = true;

            Thread.Sleep(200);

            counterReset.Value = false;

            Thread.Sleep(200);

            PLCInt plcInt1    = new PLCInt(CounterDB);
            int    plcCounter = plcInt1.Value;

            barcodeCounter = plcCounter;
        }
        void Timer1Tick(object sender, EventArgs e)
        {
            if (!BarcodeScanner1Running)
            {
                return;
            }

            PLCInt plcInt1     = new PLCInt(Statics.Counter1DB);
            int    realCounter = plcInt1.Value;

            if (realCounter > LastRealCounter1)
            {
                Thread thread = new Thread(() => InspectBarcode1(realCounter));
                thread.Start();

                // prepare for next cycle
                LastRealCounter1 = realCounter;
            }
        }
        private void StartBarcodeReader2()
        {
            if (!BarcodeScanner2TemplateRunning)
            {
                if (string.IsNullOrEmpty(BarcodeScanner2Template))
                {
                    //ShowMsgOnStatusBar("You have to set a Template first");
                    return;
                }

                BarcodeScanner2Running       = true;
                RibbonButtonStart2.IsEnabled = false;
                RibbonButtonStop2.IsEnabled  = true;

                PLCInt plcInt1 = new PLCInt(Statics.Counter2DB);
                CorrectBarcodeScanCounter2 = plcInt1.Value;

                //Timer2.Start();
                Timer2.IsEnabled = true;

                StartMachine2Motor();
            }
        }
Exemple #5
0
        static void DoWork()
        {
            if (MachineIsRunning)
            {
                Thread.Sleep(Interval);

                PLCInt plcInt1    = new PLCInt(CounterDB);
                int    plcCounter = plcInt1.Value;

                if (barcodeCounter == plcCounter)
                {
                    if (barcodeValue == Template)
                    {
                        //Console.Write($"{DateTime.Now} : ");
                        Console.Write(string.Format("{0} : ", DateTime.Now));
                        Console.WriteLine("OK", Color.Green);
                        Console.WriteLine("-----------------------------------------");
                        writeToCSV(barcodeValue, ReadType.OK);
                    }
                    else
                    {
                        stop();
                        Console.Write(string.Format("{0} : ", DateTime.Now));
                        Console.WriteLine("Mismatch", Color.PaleVioletRed);
                        Console.WriteLine("-----------------------------------------");
                        writeToCSV(barcodeValue, ReadType.Mismatch);
                    }
                }
                else
                {
                    if (plcCounter > barcodeCounter)
                    {
                        stop();
                        Console.Write(string.Format("{0} : ", DateTime.Now));
                        Console.WriteLine("Blank", Color.Yellow);
                        Console.WriteLine("-----------------------------------------");
                        writeToCSV(barcodeValue, ReadType.Blank);
                    }
                    else if (plcCounter < barcodeCounter)
                    {
                        stop();
                        Console.Write(string.Format("{0} : ", DateTime.Now));
                        Console.WriteLine("Counter Error", Color.Purple);
                        Console.WriteLine("-----------------------------------------");
                        //writeToCSV(LastBarcode, ReadType.Blank);
                    }
                }

                //#if DEBUG

                //                Console.WriteLine("Barcode : " + barcodeCounter);
                //                Console.WriteLine("Counter : " + plcCounter);

                //#endif

                if (!MachineIsRunning)
                {
                    if (ResetDelay == -1)
                    {
                        Console.WriteLine("Continue? (Y/N)");
                        var answer = Console.ReadLine();
                        if (answer == "y" || answer == "Y")
                        {
                            start();
                        }
                    }
                    else
                    {
                        string msg = string.Format("Auto start in {0}ms", ResetDelay);
                        Console.WriteLine(msg);
                        Console.WriteLine();
                        Thread.Sleep(ResetDelay);
                        start();
                    }
                }
            }
        }