private void btnAddRecipe_Click(object sender, EventArgs e)
        {
            if (tbNewRecipe.Text == "")
            {
                AppUtility.ShowKryptonMessageBox("No Recipe Name", "Please input recipe name", "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Error, this);
                return;
            }

            if (_allRecipe.ChildExists(tbNewRecipe.Text))
            {
                AppUtility.ShowKryptonMessageBox("Recipe Name Exist", String.Format("Recipe name \"{0}\" already exist.", tbNewRecipe.Text), "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Error, this);
                return;
            }

            try
            {
                AppProductRecipe newRecipe = new AppProductRecipe(tbNewRecipe.Text);
                newRecipe.PropertyValChanged += new PropertyChangedEventHandler(AppMachine.Comp.AppMachine.This.RecipePropValue_OnChange);
                _allRecipe.Add(newRecipe);
                componentBrowser.Rebuild(_allRecipe);
                AppUtility.ShowKryptonMessageBox("Add New Product Completed", String.Format("Add New Product \"{0}\" Completed", tbNewRecipe.Text), "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Information, this);
                tbNewRecipe.Clear();
            }
            finally
            {
            }
        }
 private void CreateComponent(CompBase compParent)
 {
     // Parent will exist
     foreach (ComponentDefinition compChildDef in _children)
     {
         CompBase child = null;
         if (compChildDef._comp != null)
         {
             child = compParent.FindChild(c => string.Equals(c.Name, compChildDef._comp.Name));
             if (child == null)
             {
                 child = compChildDef._comp;
                 compParent.Add(child);
                 //U.LogInfo("Added child {0}", child.Name);
             }
             else
             {
                 child.Name = compChildDef._comp.Name;
             }
         }
         else
         {
             // Does the child exist?
             child = compParent.FindChild(c => c.Name == compChildDef.Name);
             if (child == null)
             {
                 // Need to add it
                 if (compChildDef.CompType == null)
                 {
                     throw new MCoreExceptionPopup("Missing Type for {0}", compChildDef.Name);
                 }
                 if (compChildDef._initParms == null || compChildDef._initParms.Length == 0)
                 {
                     throw new MCoreExceptionPopup("Missing name or initilaizer {0}", compChildDef.Name);
                 }
                 try
                 {
                     // Create it
                     child = Activator.CreateInstance(compChildDef.CompType, compChildDef._initParms) as CompBase;
                     compParent.Add(child);
                 }
                 catch (Exception ex)
                 {
                     throw new MCoreExceptionPopup(ex, "Problem loading dll for {0}", compChildDef.CompType.Name);
                 }
             }
             else
             {
                 child.Name = compChildDef.Name;
             }
         }
         compChildDef.CreateComponent(child);
     }
 }
        private void btnAddOR_Click(object sender, EventArgs e)
        {
            CompBase selComp = null;

            if (treeComponents.SelectedNode == null)
            {
                selComp = _transitionItem;
            }
            else
            {
                selComp = treeComponents.SelectedNode.Tag as CompBase;
            }

            //Prevent incorrect added
            if ((selComp == _transitionItem && (_transitionItem.ChildArray != null && _transitionItem.ChildArray.Length != 0)) ||
                selComp is SMSubCond)
            {
                return;
            }



            selComp.Add(new SMOrCond());

            Rebuild();
        }
Exemplo n.º 4
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            if (tbNewUser.Text == "")
            {
                AppUtility.ShowKryptonMessageBox("No User Name", "Please input user name", "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Error, this);
                return;
            }

            if (_allUsers.ChildExists(tbNewUser.Text))
            {
                AppUtility.ShowKryptonMessageBox("Duplicate User Name", String.Format("User name \"{0}\" already exist.", tbNewUser.Text), "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Error, this);
                return;
            }

            try
            {
                DefaultLogger logger = U.GetComponent(AppConstStaticName.DEFAULT_LOGGER) as DefaultLogger;
                logger.Abort();
                AppUserInfo newUser = new AppUserInfo(tbNewUser.Text);
                newUser.Initialize();
                _allUsers.Add(newUser);
                newUser.InitializeIDReferences();
                logger.Abort();
                componentBrowser.Rebuild(_allUsers);
                AppUtility.ShowKryptonMessageBox("Add New User Completed", String.Format("Add New User \"{0}\" Completed", tbNewUser.Text), "", ComponentFactory.Krypton.Toolkit.TaskDialogButtons.OK, MessageBoxIcon.Information, this);
                tbNewUser.Clear();
            }
            finally
            {
            }
        }
Exemplo n.º 5
0
 private void RecurseConstructChild(CompBase child, CompBase readComp)
 {
     if (child.ChildArray != null)
     {
         foreach (CompBase subChild in child.ChildArray)
         {
             CompBase foundChild = readComp.FindChild(subChild.Name);
             if (foundChild != null)
             {
                 if (subChild.ChildArray != null)
                 {
                     RecurseConstructChild(subChild, foundChild);
                 }
             }
             else
             {
                 readComp.Add(subChild);
             }
         }
     }
 }
        private void btnAddAND_Click(object sender, EventArgs e)
        {
            CompBase selComp = null;

            if (treeComponents.SelectedNode == null)
            {
                selComp = null;
            }
            else
            {
                selComp = treeComponents.SelectedNode.Tag as CompBase;
                if (selComp is SMTransition)
                {
                    _currentTransitionItem = selComp as SMTransition;
                }
                else
                {
                    _currentTransitionItem = GetTransitionParent(selComp);
                }
            }

            if (selComp == null)
            {
                return;
            }

            //Prevent incorrect added
            if (((selComp is SMTransition) && ((selComp as SMTransition).ChildArray != null && (selComp as SMTransition).ChildArray.Length != 0)) ||
                selComp is SMSubCond)
            {
                return;
            }


            selComp.Add(new SMAndCond());
            treeComponents.Nodes.Clear();
            Rebuild();
        }
Exemplo n.º 7
0
        private void InitializeApplication()
        {
            try
            {
                #region  Machine Standard Pattern
                // Essential
                U.RootComp.Add(new DefaultLogger(AppConstStaticName.DEFAULT_LOGGER));
                // Force load of certain references
                Type ty = typeof(SMFlowChartCtlBasic);
                //Machine
                ComponentDefinition machineDef = new ComponentDefinition(typeof(AppMachine.Comp.AppMachine), AppConstStaticName.APP_MACHINE);
                //Essential add Machine to Root

                #endregion

                #region Standard Machine Common Param Pattern
                U.RootComp.Add(new AppCommonParam(AppConstStaticName.COMMON_PARAMETER));
                #endregion

                #region Station Standard Pattern
                //Station
                CompBase stations = new CompBase(AppConstStaticName.ALL_STATIONS);
                #endregion

                //Station Define

                /*Add New Station Here (Example in Below)
                 * stations.Add(new AppFeederStation(AppConstStaticName.FEEDSTATION));
                 * stations.Add(new AppVisionStation(AppConstStaticName.VISIONSTATION));
                 */

                stations.Add(new AppStationBase("Sample Station"));

                #region Station Standard Pattern
                U.RootComp.Add(stations, CompRoot.eCleanUpMode.AllLayer);
                #endregion


                //IO System Define
                //Add IO Component Here (Example in Below)
                //ComponentDefinition ioSystem = new ComponentDefinition(IOSystemBase.PlugIns.ModbusTcpIO, AppConstStaticName.ALL_IO);
                ComponentDefinition ioSystem = new ComponentDefinition(typeof(IOSystemBase), "ModbusTcpIO", AppConstStaticName.ALL_IO);
                Inputs inputsIO            = new Inputs(AppConstStaticName.INPUTS);
                ComponentDefinition inputs = ioSystem.Add(inputsIO);


                //Inputs List Define

                /* Add IO Component Here (Example in Below)
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.STARTPB) { Channel = 0 });//X1
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.STOPPB) { Channel = 1 });//X2
                 * inputs.Add(new AppSafetyInput(AppConstStaticName.RESETPB) { Channel = 2 });//X3
                 */


                Outputs             outputsIO = new Outputs(AppConstStaticName.OUTPUTS);
                ComponentDefinition outputs   = ioSystem.Add(outputsIO);

                //Outputs List Define

                /*
                 * outputs.Add(new BoolOutput(AppConstStaticName.REDLIGHT) { Channel = 0 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.AMBERLIGHT) { Channel = 1 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.GREENLIGHT) { Channel = 2 });
                 * outputs.Add(new BoolOutput(AppConstStaticName.BUZZER) { Channel = 3 });
                 */

                try
                {
                    U.RootComp.Add(ioSystem, CompRoot.eCleanUpMode.AllLayer);
                }
                catch (Exception ex)
                {
                    U.LogPopup(ex, "IO System Initialize Unsuccessful in loading of application");
                }



                //Vision System Define

                /* Add Vision Conponent Here (Example in Below)
                 * //Vision
                 * ComponentDefinition visionSys = machineDef.Add(VisionSystemBase.PlugIns.Cognex9, AppConstStaticName.VISIONSYSTEM);
                 * ComponentDefinition camAOI = visionSys.Add(CameraBase.PlugIns.CognexCamera9, AppConstStaticName.VISIONCAMERA);
                 * ComponentDefinition aoiJob = camAOI.Add(VisionJobBase.PlugIns.CognexJob9, AppConstStaticName.VISIONJOB);
                 * aoiJob.Add(new AppVisionAOIResult(AppConstStaticName.VISIONJOBRESULT));
                 */



                //Motion System Define

                /* Add Motion Conponent Here (Example in Below)
                 *
                 * //Feed Motion
                 * ComponentDefinition feedMotionSys = machineDef.Add(MotionSystemBase.PlugIns.YamahaTrServo, AppConstStaticName.FEEDMOTIONSYSTEM);
                 * ComponentDefinition feedMotionAxes = feedMotionSys.Add(new AppRealAxes(AppConstStaticName.FEEDMOTIONAXES));
                 * ComponentDefinition feedYAxis = feedMotionAxes.Add(new AppRealAxis(AppConstStaticName.FEEDYAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 100.0 });
                 *
                 * //Lift1 Motion
                 * ComponentDefinition lift1MotionSys = machineDef.Add(MotionSystemBase.PlugIns.IAIScon, AppConstStaticName.LIFT1MOTIONSYSTEM);
                 * ComponentDefinition lift1MotionAxes = lift1MotionSys.Add(new AppRealAxes(AppConstStaticName.LIFT1MOTIONAXES));
                 * ComponentDefinition lift1ZAxis = lift1MotionAxes.Add(new AppRealAxis(AppConstStaticName.LIFT1ZAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 0.1  });
                 *
                 * //Lift2 Motion
                 * ComponentDefinition lift2MotionSys = machineDef.Add(MotionSystemBase.PlugIns.IAIScon, AppConstStaticName.LIFT2MOTIONSYSTEM);
                 * ComponentDefinition lift2MotionAxes = lift2MotionSys.Add(new AppRealAxes(AppConstStaticName.LIFT2MOTIONAXES));
                 * ComponentDefinition lift2ZAxis = lift2MotionAxes.Add(new AppRealAxis(AppConstStaticName.LIFT2ZAXIS) { AxisNo = 0, MaxLimit = 75, MinLimit = 0, DefaultSpeed = 70.0, AccelDecel = 0.1 });
                 */


                #region State Machine Standard Pattern
                //Define Stae Machine Component
                ComponentDefinition smDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_STATE_MACHINE);

                smDef.Add(new SMStateMachine(AppConstStaticName.SM_RESET));
                smDef.Add(new SMStateMachine(AppConstStaticName.SM_MAIN));
                #endregion

                //State Machine Define

                /* Add New State Machine Here (Example in Below)
                 * smDef.Add(new SMStateMachine(AppConstStaticName.SM_FEED));
                 * smDef.Add(new SMStateMachine(AppConstStaticName.SM_VISION));
                 */


                #region State Semi-Auto Machine Standard Pattern
                //Define Stae Machine Component
                ComponentDefinition smSemiAutoDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_SEMI_AUTO_STATE_MACHINE);
                smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_RESET));
                smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_MAIN));
                #endregion

                //Semi State Machine Define

                /* Add New State Machine Here (Example in Below)
                 * smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_FEED));
                 * smSemiAutoDef.Add(new SMStateMachine(AppConstStaticName.SM_SEMI_VISION));
                 */


                #region State Machine Standard Pattern
                U.RootComp.Add(smDef, CompRoot.eCleanUpMode.FirstLayer);
                #endregion

                #region Semi Auto State Machine Standard Pattern
                U.RootComp.Add(smSemiAutoDef, CompRoot.eCleanUpMode.FirstLayer);
                #endregion

                #region Recipe Standard Pattern
                ComponentDefinition recipeDef = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_RECIPES);
                recipeDef.Add(new AppProductRecipe(AppConstStaticName.REF_CURRENT_RECIPE));
                recipeDef.Add(new AppProductRecipe(AppConstStaticName.SAMPLE_RECIPE));
                U.RootComp.Add(recipeDef);
                #endregion

                #region User Standard Pattern
                ComponentDefinition users     = new ComponentDefinition(typeof(CompBase), AppConstStaticName.ALL_USER);
                AppUserInfo         adminUser = new AppUserInfo(AppConstStaticName.ADMIN_USER)
                {
                    UserEN = "00000", UserCode = "00000", UserLevel = Comp.AppEnums.eAccessLevel.Supervisor
                };
                users.Add(adminUser);
                AppUserInfo guestUser = new AppUserInfo(AppConstStaticName.GUEST_USER)
                {
                    UserEN = "00001", UserCode = "00001", UserLevel = Comp.AppEnums.eAccessLevel.Operator
                };
                users.Add(adminUser);
                users.Add(guestUser);

                U.RootComp.Add(users);
                #endregion

                #region Standard Pattern

                try
                {
                    //Add machine to root comp after add all components belong to the machine.
                    U.RootComp.Add(machineDef);
                    AppMachine.Comp.AppMachine.This.IOList.Initialize();
                }
                catch (Exception ex)
                {
                    U.LogPopup(ex, "Machine Initialize Unsuccessful in loading of application");
                }


                // Essential call after all component definitions
                U.RootComp.InitializeIDReferences();

                this.BeginInvoke((MethodInvoker) delegate
                {
                    _mainPanel.RebuildCompBrowser();


                    // //State Machine Instance with bind to control
                    GetSMInstanceWithBindControl();


                    // //Semi Auto State Machine Instance with bind to control
                    GetSMSemiAutoInstanceWithBindControl();


                    //Initiate User
                    if (AppMachine.Comp.AppMachine.This.CurrentUser == null)
                    {
                        AppMachine.Comp.AppMachine.This.CurrentUser = U.GetComponent(AppConstStaticName.ADMIN_USER) as AppUserInfo;
                    }

                    //Prepare Stop When Finish
                    mcbStopWhenFinished.DataBindings.Add("Checked", AppMachine.Comp.AppMachine.This, "StopWhenFinished");

                    //Prepare All Panel
                    _mainPanel.PrepareAllPanel();


                    //Update Operation Button
                    UpdateControlButtons();

                    //Set User Access for Current User
                    SetUserAccess(AppMachine.Comp.AppMachine.This.CurrentUser);
                });


                U.RegisterOnChanged(() => AppMachine.Comp.AppMachine.This.CurrentUser, CurrentUserOnChange);

                AppMachine.Comp.AppMachine.This.LoadStartupRecipe();
                VerifyCriticalSimulateComponent();
                _mainPanel.RegisterMachineStatusEvent();
                #endregion
            }

            #region Standard Pattern
            catch (Exception ex)
            {
                U.LogPopup(ex + " " + ex.StackTrace, "Unsuccessful in loading of application");
            }
            finally
            {
                this.BeginInvoke((MethodInvoker) delegate
                {
                    _splashThread.Abort();
                });
            }
            #endregion


            #region Auto Lockout Standard Pattern
            _autoLockoutTimer.Interval = 500;
            _autoLockoutTimer.Elapsed += new System.Timers.ElapsedEventHandler(AutoLockoutTimer_OnElapse);
            _autoLockoutTimer.Enabled  = true;
            #endregion
        }