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
        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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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);
                }
            }
        }