public string LeePLC(Pokayoke.TipoDato dato, string Variable) { string str = ""; switch (dato) { case Pokayoke.TipoDato.Entero: str = Pokayoke.ReadResultRender <int>(this.keyence_net.ReadInt32(Variable)); break; case Pokayoke.TipoDato.Texto: str = Pokayoke.ReadResultRender <string>(this.keyence_net.ReadString(Variable, (ushort)2)); break; case Pokayoke.TipoDato.Flotante: str = Pokayoke.ReadResultRender <float>(this.keyence_net.ReadFloat(Variable)); break; } return(str); }
public void ProcesoMain() { this.PrimaryLog("Inicio", "Proceso Principal", EventLogEntryType.Information, true); int num = 0; string QRCode = ""; while (this.Running) { Thread.Sleep(500); switch (num) { case 20: this.PrimaryLog("QR", "Lectura de QR", EventLogEntryType.Information, false); QRCode = Pokayoke.LeerBulkPLC((IReadWriteNet)this.keyence_net, "D299", (ushort)11); if (QRCode != "" && QRCode.Length == 20 && QRCode.StartsWith("4")) { num = 30; this.Errors = 0; break; } else { QRCode = ""; this.Errors = this.Errors + 1; if (this.Errors > 10) { this.DesconectaPLC(); this.Errors = 0; num = 0; this.PrimaryLog("Lectura QR", "Desconexión", EventLogEntryType.Error, true); } break; } case 30: this.PrimaryLog("Database", "Consultamos QR en DB", EventLogEntryType.Information, false); DataTable dataTable = this.spSearchQROnStations(QRCode); if (dataTable != null) { if (dataTable.Rows.Count > 0) { this.PrimaryLog("Database", "Codigo " + QRCode + " Resultado " + dataTable.Rows[0][0].ToString(), EventLogEntryType.Information, false); if (dataTable.Rows[0][0].ToString() == "0") { this.EscribePLC(Pokayoke.TipoDato.Entero, "D20026", "1"); } else { this.PrimaryLog("Database", "Codigo " + QRCode + " Resultado " + dataTable.Rows[0][0].ToString(), EventLogEntryType.Warning, true); this.EscribePLC(Pokayoke.TipoDato.Entero, "D20026", "2"); Thread.Sleep(500); this.EscribePLC(Pokayoke.TipoDato.Entero, "D20028", dataTable.Rows[0][0].ToString()); } } else { this.EscribePLC(Pokayoke.TipoDato.Entero, "D20026", "3"); } } else { this.EscribePLC(Pokayoke.TipoDato.Entero, "D20026", "4"); } num = 10; break; case 0: this.PrimaryLog("Inicio", "Conexion a PLC", EventLogEntryType.Warning, true); if (this.ConectaPLC()) { this.PrimaryLog("Trigger", "Escaneo de trigger", EventLogEntryType.Information, false); num = 10; break; } else { break; } case 10: string str = this.LeePLC(Pokayoke.TipoDato.Entero, "D20024"); if (str == "1") { this.EscribePLC(Pokayoke.TipoDato.Entero, "D20024", "0"); num = 20; } if (str == "") { this.Errors = this.Errors + 1; } if (this.Errors > 5) { this.DesconectaPLC(); this.Errors = 0; num = 0; this.PrimaryLog("Escaneo", "Desconexión", EventLogEntryType.Error, true); break; } else { break; } } } }