Ejemplo n.º 1
0
        private void InitializeStations()// Cargamos estaciones de BD.
        {
            try
            {
                if (AppGlobal.ComunicationProtocol == ComunicationProtocol.Snap7)
                {
                    AppGlobal.Stations    = StationController.GetAll();
                    AppGlobal.Snap7Server = new S7Server("192.168.0.1", 0, 0);

                    foreach (var station in AppGlobal.Stations)
                    {
                        station.StatusChangeS7    = new S7Item(station.StatusDataChangeAddress);
                        station.StatusChangeS7Ack = new S7Item(station.StatusDataChangeAddressAck);
                        station.DataAddressS7     = new S7Item(station.DataAddress);
                    }

                    TimerS7ComunicationStatus.Start();
                    // TimerStateStations.Start();
                }
                else
                {
                    AppGlobal.FillStation1 = StationController.GetByCode(1);
                    AppGlobal.FillStation2 = StationController.GetByCode(2);

                    AppGlobal.OvenStation1  = StationController.GetByCode(3);
                    AppGlobal.OvenStation2  = StationController.GetByCode(4);
                    AppGlobal.OvenStation3  = StationController.GetByCode(5);
                    AppGlobal.OvenStation4  = StationController.GetByCode(6);
                    AppGlobal.OvenStation5  = StationController.GetByCode(7);
                    AppGlobal.OvenStation6  = StationController.GetByCode(8);
                    AppGlobal.OvenStation7  = StationController.GetByCode(9);
                    AppGlobal.OvenStation8  = StationController.GetByCode(10);
                    AppGlobal.OvenStation9  = StationController.GetByCode(11);
                    AppGlobal.OvenStation10 = StationController.GetByCode(12);

                    AppGlobal.UnmoldStation1 = StationController.GetByCode(13);
                    AppGlobal.UnmoldStation2 = StationController.GetByCode(14);

                    AppGlobal.TransferStation = StationController.GetByCode(15);

                    AppGlobal.Stations.Add(AppGlobal.FillStation1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error en InitializeStations()");
            }
        }
Ejemplo n.º 2
0
        //Motor de la aplicación Estaciones, Bandejas, Moldes, Operaciones, Ordenes de fabricación y piezas
        private void TimerComunicationStatus_Tick(object sender, EventArgs e)
        {
            TimerS7ComunicationStatus.Stop();

            foreach (var station in AppGlobal.Stations)
            {
                if (station.Bussy)
                {
                    continue;
                }

                if (!S7.GetBitAt(AppGlobal.Snap7Server.Read(station.StatusChangeS7), 0, 0))
                {
                    continue;
                }

                var data = AppGlobal.Snap7Server.Read(station.DataAddressS7);
                station.DataContent = Common.GetDataContent(data);

                var pallet    = PalletController.GetByCode(station.DataContent.PalletCode);
                var operation = OperationController.GetByCode(station.DataContent.OperationCode);
                var mold      = MoldRepository.GetByCode(station.DataContent.MoldCode);

                station.ActiveOperation = operation;

                if (operation.InitPart || operation.EndPart)
                {
                    station.Bussy = true;
                    Thread AskForReferencePartThread = new Thread(new ThreadStart(() => AskForReferencePart(station, pallet, operation, mold)));
                    AskForReferencePartThread.Start();
                }
                else
                {
                    OperationRegisterController.Register(station, pallet, operation, mold, "Pieza 1");
                    AppGlobal.Snap7Server.WriteWord(station.StatusChangeS7Ack, (ushort)operation.Code);
                }
            }

            TimerS7ComunicationStatus.Start();
        }