예제 #1
0
        static void Main(string[] args)
        {
            bool error = false;

            var plc = new PLC();


            var lines = File.ReadAllLines("script.txt");

            foreach (var line in lines)
            {
                if (!Parser.Parse(line)(plc))
                {
                    Console.WriteLine("ERROR: " + line);
                    error = true;
                    break;
                }
            }

            plc.Dispose();
            if (!error)
            {
                Console.WriteLine("SUCESSO");
            }

            Console.ReadLine();
        }
예제 #2
0
        public void init(PLC plc, PLC plcAsp, FileLog log)
        {
            this.plcRulliera    = plc;
            this.plcAspirazione = plcAsp;
            this.log            = log;

            this.d1.pollActions.Add(() =>
            {
                this.d1.doWithPLC(c =>
                {
                    var status = c.readBool("M0");
                    var speed  = c.readInt16("D420");

                    this.plcRulliera.doWithPLC((r) =>
                    {
                        r.writeBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Run", status);
                        r.writeInt16("RULLI_CENTRO_TAGLI.RD_Levigatrice_Act_Speed", speed);

                        if (this.dataSent)
                        {
                            r.writeBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Ready", true);
                        }
                    });
                });
            }

                                    );

            this.d1.pollActions.Add(() =>
            {
                this.d1.doWithPLC(c =>
                {
                    run = c.readBool("M0");
                    m2  = c.readBool("M513");
                    m3  = m4 = c.readBool("M514");
                });
            }

                                    );


            this.d2.pollActions.Add(() =>
            {
                this.d2.doWithPLC(c =>
                {
                    m7 = m8 = c.readBool("M515");
                    m5 = m6 = c.readBool("M513");
                });
            }

                                    );



            this.d3.pollActions.Add(() =>
            {
                this.d3.doWithPLC(c =>
                {
                    m9  = c.readBool("M513");
                    m10 = m11 = c.readBool("M514");
                });
            }

                                    );



            this.d4.pollActions.Add(() =>
            {
                this.d4.doWithPLC(c =>
                {
                    m12 = c.readBool("M513");
                    m13 = c.readBool("M514");
                    m14 = m15 = c.readBool("M515");
                });
            }

                                    );


            this.d5.pollActions.Add(() =>
            {
                this.d5.doWithPLC(c =>
                {
                    m16 = m17 = c.readBool("M513");
                    m18 = c.readBool("M515");
                    m19 = c.readBool("M516");
                });
            }

                                    );

            this.plcAspirazione.pollActions.Add(() =>
            {
                this.plcAspirazione.doWithPLC(c =>
                {
                    try
                    {
                        if (!run)
                        {
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_1", false);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_2", false);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_3", false);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_4", false);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_5", false);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_6", false);
                        }
                        else
                        {
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_1", m2 || m3 || m4);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_2", m6 || m5 || m9);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_3", m7 || m8 || m12);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_4", m11 || m10 || m13);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_5", m15 || m14 || m18);
                            c.writeBool("MAIN.RD_Levigatrice_Serranda_6", m16 || m17 || m18);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.log("scrittura dati serrande " + ex.Message);
                    }
                });
            });

            this.plcRulliera.pollActions.Add(
                () => {
                this.plcRulliera.doWithPLC(c =>
                {
                    bool presenza    = c.readBool(".Buffer_R3[1].Busy");
                    var ricetta      = c.readInt16(".Buffer_R3[1].Nr_Ricetta");
                    bool ready       = c.readBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Ready");
                    double altezza   = c.readDouble(".Buffer_R3[1].Altezza");
                    double larghezza = c.readDouble(".Buffer_R3[1].Larghezza");
                    bool richiesta   = c.readBool("RULLI_CENTRO_TAGLI.WR_Levigatrice_Pos_Req");

                    if (!presenza)
                    {
                        c.writeBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Ready", false);
                        dataSent = false;
                    }

                    if (!richiesta)
                    {
                        c.writeBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Ready", false);
                        dataSent = false;
                    }



                    if (ricetta != 0 && ricetta != 9999)
                    {
                        if (richiesta && presenza && !ready && !dataSent)
                        {
                            log.log("VALMEC AVVIO INVIO DATI");

                            this.d1.doWithPLC((p) =>
                            {
                                try
                                {
                                    d2.tryConnect();
                                    d3.tryConnect();
                                    d4.tryConnect();
                                    d5.tryConnect();

                                    stopCycle();
                                    sendReceipe(ricetta, altezza, larghezza);
                                    //startCycle();


                                    d2.Dispose();
                                    d3.Dispose();
                                    d4.Dispose();
                                    d5.Dispose();

                                    dataSent = true;

                                    /*
                                     * this.plcRulliera.doWithPLC(r =>
                                     * {
                                     *  r.writeBool("RULLI_CENTRO_TAGLI.RD_Levigatrice_Ready", true);
                                     * });
                                     */
                                } catch (Exception ex)
                                {
                                    log.log("VALMEC ERRORE :" + ex.Message);
                                }
                            });
                        }
                    }
                });
            }
                );
        }