Exemplo n.º 1
0
        private void switchOffset_CheckedChanged(object sender, Bunifu.UI.WinForms.BunifuToggleSwitch.CheckedChangedEventArgs e)
        {
            try
            {
                if (switchOffset.Checked)
                {
                    CSerialDeserial.ReadFile(ref this.db1);
                    S7.SetDIntAt(this.db1Buffer, 212, Convert.ToByte(nudDelayTime.Value));

                    this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                    Alert($"Offset impostato a {nudDelayTime.Value}s", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    CSerialDeserial.ReadFile(ref this.db1);
                    S7.SetDIntAt(this.db1Buffer, 212, 0);

                    this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                    Alert("Offset rimosso", AlertDLL.Alert.enmType.Success);
                }
            }
            catch (Exception)
            {
                Alert("Errore non gestito", AlertDLL.Alert.enmType.Error);
            }
        }
Exemplo n.º 2
0
        private void tmrWatchDog_Tick(object sender, EventArgs e)
        {
            try
            {
                this.result = this.Client.DBRead(1, 0, this.db1Buffer.Length, this.db1Buffer);
                int watchDog = S7.GetUSIntAt(this.db1Buffer, 216);  //1 se scrivo da pc, 0 se scrivo da plc

                if (watchDog == 0)
                {
                    CSerialDeserial.ReadFile(ref this.db1);
                    S7.SetUSIntAt(this.db1Buffer, 216, 1);

                    this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);
                }
                else
                {
                    disconnettiPLC();
                    Alert("PLC disconnesso", AlertDLL.Alert.enmType.Error);
                }
            }
            catch (Exception)
            {
                disconnettiPLC();
                Alert("PLC disconnesso", AlertDLL.Alert.enmType.Error);
            }
        }
Exemplo n.º 3
0
        //lettura della control word del plc, controlla se la macchina è abilitata e in start e setta i pulsanti di conseguenza
        private void leggiControlWordSettaPulsanti()
        {
            //lettura dei dati dal PLC
            this.result = this.Client.DBRead(1, 0, this.db1Buffer.Length, this.db1Buffer);

            int controlWord = S7.GetUSIntAt(this.db1Buffer, 108);

            CSerialDeserial.WriteFile(this.db1);


            if (controlWord == 0)   //macchina diabilitata
            {
                btnAbilitaPLC.Text  = "ABILITA";
                btnStartPLC.Enabled = false;
                btnStartPLC.Text    = "AVVIA";
            }
            else
            {
                if (controlWord == 1)    //macchina abilitata
                {
                    btnAbilitaPLC.Text  = "DISABILITA";
                    btnStartPLC.Enabled = true;
                    btnStartPLC.Text    = "AVVIA";
                }
                else
                {
                    if (controlWord == 3)    //macchina abilitata e in start
                    {
                        btnAbilitaPLC.Text  = "DISABILITA";
                        btnStartPLC.Enabled = true;
                        btnStartPLC.Text    = "INTERROMPI";
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void simulaGuasto()
        {
            //se sono presenti guasti da simulare simula quello più recente
            if (listaGuasti.Count > 0)
            {
                string guasto = listaGuasti[listaGuasti.Count - 1];  //ultimo guasto inserito

                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetUSIntAt(this.db1Buffer, 217, Convert.ToByte(codiceGuastoDaNome(guasto)));

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                if (result == 0)
                {
                    Alert($"Guasto simulato correttamente", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    Alert("Errore nella simulazione", AlertDLL.Alert.enmType.Error);
                }
            }
            else
            {
                cancellaSimulazioneGuasto();
            }
        }
Exemplo n.º 5
0
        private void cancellaSimulazioneGuasto()
        {
            //set variabile guasti del plc a 0
            CSerialDeserial.ReadFile(ref this.db1);
            S7.SetUSIntAt(this.db1Buffer, 217, 0);

            this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);
        }
Exemplo n.º 6
0
        //svuotare parzialmente i dati della commessa sul plc
        private bool eliminaEsecuzioneCommessaSulPLC()
        {
            //codice commessa e prodotto vengono settati a stringa vuota e il numero pezzi a 0
            CSerialDeserial.ReadFile(ref this.db1);
            S7.SetStringAt(this.db1Buffer, 0, 50, "");
            S7.SetStringAt(this.db1Buffer, 52, 50, "");
            S7.SetDIntAt(this.db1Buffer, 104, 0);

            this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

            return(result == 0);
        }
Exemplo n.º 7
0
        //scrittura della commmessa sul plc per l'esecuzione
        private bool eseguiCommessaSuPLC(string codiceCommessa, string prodotto, int pezziDaProdurre, DateTime dataConsegna, DateTime dataEsecuzione)
        {
            CSerialDeserial.ReadFile(ref this.db1);
            S7.SetStringAt(this.db1Buffer, 0, 50, codiceCommessa);
            S7.SetStringAt(this.db1Buffer, 52, 50, prodotto);
            S7.SetDIntAt(this.db1Buffer, 104, pezziDaProdurre);
            S7.SetStringAt(this.db1Buffer, 218, 30, dataConsegna.ToString());
            S7.SetStringAt(this.db1Buffer, 250, 30, dataEsecuzione.ToString());

            this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

            return(result == 0);
        }
Exemplo n.º 8
0
        private void btnStartPLC_Click(object sender, EventArgs e)
        {
            if (btnStartPLC.Text == "AVVIA")
            {
                //scrivi start su PLC
                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetUSIntAt(this.db1Buffer, 108, 3);

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                //se avvio OK attiva tutto
                if (result == 0)
                {
                    btnStartPLC.Text = "INTERROMPI";
                    //set di tutto a enable
                    //setGUI(true);

                    Alert("Ciclo avviato", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    Alert("Avvio del ciclo fallito", AlertDLL.Alert.enmType.Error);
                }

                //se ci sono commesse in coda, viene eseguita la prima
                MandaInEsecuzioneCommessaSuccessiva();
                AggiornaDataGridViewCommesse();
            }
            else
            {
                //scrivi stop su PLC
                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetUSIntAt(this.db1Buffer, 108, 1);

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                //se OK cambia stato del bottone
                if (result == 0)
                {
                    btnStartPLC.Text = "AVVIA";
                    Alert("Ciclo interrotto", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    Alert("Interruzione del ciclo fallita", AlertDLL.Alert.enmType.Error);
                }
            }
        }
Exemplo n.º 9
0
        //scrittura del messaggio per l'operatore sul plc
        public bool scriviMessaggioPerOperatore(string messaggio)
        {
            try
            {
                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetStringAt(this.db1Buffer, 110, 100, messaggio);

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                return(result == 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        private void btnAbilitaPLC_Click(object sender, EventArgs e)
        {
            if (btnAbilitaPLC.Text == "ABILITA")
            {
                //scrivi abilitazione su PLC
                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetUSIntAt(this.db1Buffer, 108, 1);

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                //se abilitazione OK attiva btnStartPLC
                if (result == 0)
                {
                    btnAbilitaPLC.Text  = "BLOCCA";
                    btnStartPLC.Enabled = true;

                    Alert("PLC abilitato", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    Alert("Abilitazione del PLC fallita", AlertDLL.Alert.enmType.Error);
                }
            }
            else
            {
                //scrivi abilitazione su PLC
                CSerialDeserial.ReadFile(ref this.db1);
                S7.SetUSIntAt(this.db1Buffer, 108, 0);

                this.result = this.Client.DBWrite(1, 0, this.db1Buffer.Length, this.db1Buffer);

                //se abilitazione OK attiva btnStartPLC
                if (result == 0)
                {
                    btnAbilitaPLC.Text  = "ABILITA";
                    btnStartPLC.Enabled = false;
                    btnStartPLC.Text    = "AVVIA";

                    Alert("PLC disabilitato", AlertDLL.Alert.enmType.Success);
                }
                else
                {
                    Alert("Disabilitazione del PLC fallita", AlertDLL.Alert.enmType.Error);
                }
            }
        }
Exemplo n.º 11
0
        private void tmrLetturaDatiPLC_Tick(object sender, EventArgs e)
        {
            try
            {
                //lettura dei dati dal PLC
                this.result = this.Client.DBRead(2, 0, this.db2Buffer.Length, this.db2Buffer);

                string codiceCommessa = S7.GetStringAt(this.db1Buffer, 0);
                //string prodotto = S7.GetStringAt(this.db1Buffer, 52);
                int    pezziProdotti             = S7.GetDIntAt(this.db2Buffer, 104);
                int    pezziScartatiScaricoPieno = S7.GetDIntAt(this.db2Buffer, 108);
                int    pezziScartatiDifettosi    = S7.GetDIntAt(this.db2Buffer, 112);
                int    pezziScartatiTotali       = pezziScartatiDifettosi + pezziScartatiScaricoPieno;
                int    statoMacchina             = S7.GetUSIntAt(this.db2Buffer, 116);
                int    velocitàMacchina          = S7.GetDIntAt(this.db2Buffer, 118);
                string newMessaggioOperatore     = S7.GetStringAt(this.db2Buffer, 130);
                allarmi = S7.GetUSIntAt(this.db2Buffer, 232);

                CSerialDeserial.WriteFile(this.db2);

                //visualizza gli allarmi
                setVisualizzazioneAllarmi(allarmi);

                //se è presente un allarme e non è mai stata mostrato l'alert, viene mostrato
                if (allarmi != 0 && mostraAlertAllarme)
                {
                    Alert("ALLARME!", AlertDLL.Alert.enmType.Error);
                    mostraAlertAllarme = false;
                }
                //se non ci sono allarmi, resetto la booleana
                if (allarmi == 0)
                {
                    mostraAlertAllarme = true;
                }

                string strStatoMacchina = calcoloStatoMacchina(statoMacchina);
                txtStatoMacchina.Text = strStatoMacchina;

                //se è presente una commessa in esecuzione sul plc, imposto le variabili opportune per la visualizzazione
                if (codiceCommessa != "")
                {
                    if (txtPezziProdotti.Text != ("" + pezziProdotti) || txtPezziScartati.Text != ("" + pezziScartatiTotali))
                    {
                        setTempoRimanenteEProgressBar(velocitàMacchina, pezziProdotti);
                    }

                    txtPezziProdotti.Text = "" + pezziProdotti;
                    txtPezziScartati.Text = "" + pezziScartatiTotali;
                    txtVelocita.Text      = "" + velocitàMacchina;
                }
                else
                {
                    setNullTextBoxes();
                }

                //se il messaggio dell'operatore è diverso da l'ultimo che è arrivatom viene attivata la notifica
                if (newMessaggioOperatore != messaggioOperatore)
                {
                    messaggioOperatore = newMessaggioOperatore;
                    mostrareMessaggio  = true;
                    NotificaMessaggioDaOperatore();
                }

                //set delle immagini per la notifica su pagina Gestione Commesse
                if (mostrareMessaggio)
                {
                    btnDialogoPcPlc.BackgroundImage = PLC_Manager.Properties.Resources.icona_NotficaPresenza;
                }
                else
                {
                    btnDialogoPcPlc.BackgroundImage = PLC_Manager.Properties.Resources.icona_nessunaNotifica;
                }

                //concusione della commessa
                if (strStatoMacchina == "CONCLUSO")
                {
                    DBManager.updateStatoCommessa(codiceCommessa, "completata");
                    commesse.completaCommessa(codiceCommessa);

                    Alert("Commessa conclusa", AlertDLL.Alert.enmType.Info);

                    Thread.Sleep(2000); //il codice viene bloccato per 2 secondi, per lasciare il tempo al servizio di leggere i dati

                    eliminaEsecuzioneCommessaSulPLC();
                    MandaInEsecuzioneCommessaSuccessiva();
                    AggiornaDataGridViewCommesse();
                }
            }
            catch (Exception)
            {
                Alert("Errore non gestito", AlertDLL.Alert.enmType.Error);
            }
        }