예제 #1
0
        public void Proceso()
        {
            this.PrimaryLog("Inicio", "Proceso Principal " + this.IP, EventLogEntryType.Information, true);
            int    num1   = 0;
            string QRCode = "";

            while (this.Running)
            {
                Thread.Sleep(500);
                switch (num1)
                {
                case 20:
                    QRCode = PLC.LeerBulkPLC((IReadWriteNet)this.keyence_net, this.DM_QR, (ushort)11);
                    if (QRCode != "" && QRCode.Length == 20)
                    {
                        num1        = 30;
                        this.Errors = 0;
                        break;
                    }
                    else
                    {
                        QRCode      = "";
                        this.Errors = this.Errors + 1;
                        if (this.Errors > 5)
                        {
                            this.DesconectaPLC();
                            this.Errors = 0;
                            num1        = 0;
                            this.PrimaryLog("Lectura QR", "Desconexión", EventLogEntryType.Error, true);
                        }
                        break;
                    }

                case 30:
                    string str1 = this.LeePLC(PLC.TipoDato.Texto, this.DM_Result);
                    if (str1.Length >= 2)
                    {
                        if (!(this.Estacion == "10"))
                        {
                            PLC      plc      = this;
                            string   origen   = "Update";
                            string[] strArray = new string[6];
                            int      index1   = 0;
                            string   str2     = "Estacion ";
                            strArray[index1] = str2;
                            int    index2   = 1;
                            string estacion = this.Estacion;
                            strArray[index2] = estacion;
                            int    index3 = 2;
                            string str3   = " Update QR '";
                            strArray[index3] = str3;
                            int    index4 = 3;
                            string str4   = QRCode;
                            strArray[index4] = str4;
                            int    index5 = 4;
                            string str5   = "' Estatus: ";
                            strArray[index5] = str5;
                            int    index6 = 5;
                            string str6   = str1;
                            strArray[index6] = str6;
                            string evento = string.Concat(strArray);
                            int    num2   = 4;
                            int    num3   = 0;
                            plc.PrimaryLog(origen, evento, (EventLogEntryType)num2, num3 != 0);
                            this.spUpdateQR(QRCode, str1.Substring(1, 1) + str1.Substring(0, 1));
                            num1 = 10;
                        }
                        else
                        {
                            num1 = 10;
                            PLC      plc      = this;
                            string   origen   = "Insert";
                            string[] strArray = new string[6];
                            int      index1   = 0;
                            string   str2     = "Estacion ";
                            strArray[index1] = str2;
                            int    index2   = 1;
                            string estacion = this.Estacion;
                            strArray[index2] = estacion;
                            int    index3 = 2;
                            string str3   = " Insertamos QR '";
                            strArray[index3] = str3;
                            int    index4 = 3;
                            string str4   = QRCode;
                            strArray[index4] = str4;
                            int    index5 = 4;
                            string str5   = "' Estatus: ";
                            strArray[index5] = str5;
                            int    index6 = 5;
                            string str6   = str1;
                            strArray[index6] = str6;
                            string evento = string.Concat(strArray);
                            int    num2   = 4;
                            int    num3   = 0;
                            plc.PrimaryLog(origen, evento, (EventLogEntryType)num2, num3 != 0);
                            this.spInsertQR(QRCode, str1.Substring(1, 1) + str1.Substring(0, 1));
                        }
                        this.Errors = 0;
                    }
                    if (str1 == "")
                    {
                        this.Errors = this.Errors + 1;
                    }
                    if (this.Errors > 5)
                    {
                        this.DesconectaPLC();
                        this.Errors = 0;
                        num1        = 0;
                        this.PrimaryLog("Resultado", "Desconexión", EventLogEntryType.Error, true);
                        break;
                    }
                    else
                    {
                        break;
                    }

                case 0:
                    this.PrimaryLog("Inicio", "Conexion a PLC", EventLogEntryType.Warning, true);
                    if (this.ConectaPLC())
                    {
                        this.PrimaryLog("Trigger", "Escaneo de trigger", EventLogEntryType.Information, false);
                        num1 = 10;
                        break;
                    }
                    else
                    {
                        break;
                    }

                case 10:
                    string str7 = this.LeePLC(PLC.TipoDato.Entero, this.DM_Trigger);
                    if (str7 == "1")
                    {
                        Thread.Sleep(100);
                        this.EscribePLC(PLC.TipoDato.Entero, this.DM_Trigger, "0");
                        num1 = 20;
                    }
                    if (str7 == "")
                    {
                        this.Errors = this.Errors + 1;
                    }
                    if (this.Errors > 5)
                    {
                        this.DesconectaPLC();
                        this.Errors = 0;
                        num1        = 0;
                        this.PrimaryLog("Escaneo", "Desconexión", EventLogEntryType.Error, true);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }