Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormMain"/> class.
        /// </summary>
        public FormMain()
        {
            InitializeComponent();

            MainApp mainApp = MainApp.GetDoc();

            // get the TcLM and set to the base class
            tclm = mainApp.GetTCLanguageManager();

            menu           = new TcMenu(this, tclm, mainApp.tcFKey1);
            menu.UserAdmin = mainApp.tcUserAdmin1;
            menu.FormsList.Add("FormMain", this);

            // set the created menu to the base class
            LocalMenu = menu;

            bool autoLogOn = mainApp.tcUserAdmin1.CurrentUser.AutoLogOn;

            if (autoLogOn == false)
            {
                Program.CloseSplashScreen(500);
            }
            else
            {
                Program.CloseSplashScreen(3000);
            }

            mainApp.tcUserAdmin1.LogOnDialog(true, autoLogOn);

            // base settings
            menu.ShowForm("FormMain");
            menu.SetFunctionKeys(mainApp.tcFKey1);

            // This is only needed at the main form, because the delegate from the menu cannot be called
            // because activation is not done.
            SetFKeyText(mainApp.tcFKey1);

            // adds the global objects to the object list
            menu.AddObject(mainApp.AdsPlcServer);
            menu.AddObject(mainApp.AdsNcServer);
            menu.AddObject(MainApp.log);

            // At the end of menu initialization
            // This function calls the forms initialisation which needs the added objects
            menu.InitializationDone();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FormCnc"/> class.
        /// </summary>
        /// <param name="f">The form.</param>
        public FormCnc(Form form)
        {
            parentForm = form;
            InitializeComponent();

            //resolution 800x6000
            if (MainApp.appSettings.applicationHeaderType == 1 ||
                MainApp.appSettings.applicationHeaderType == 2)
            {
                int left = panelCnc.Left;
                tcFKeyLeft.Visible = false;

                int diff = tcFKeyRight.Width - 100;
                tcFKeyRight.Width = 100;

                panelCnc.Left   = 0;
                panelCnc.Width += left + diff;

                panelChannelOverview.Left   = 0;
                panelChannelOverview.Width += left + diff;
            }

            MainApp mainApp     = MainApp.GetDoc();
            int     svrPortNrNc = 0;

            if (MainApp.appSettings.tagetSystem == 0)
            {
                svrPortNrNc = 553;
            }
            else
            {
                svrPortNrNc          = 501;
                blockSearch1.Enabled = false;                   // no block search with NCI
                syntaxCheck1.Enabled = false;                   // no syntax check with NCI
            }

            // the one and only instance of the AdsNcServer and AdsPlcServer
            string amsNetId = MainApp.appSettings.amsNetId;

            adsNcServer  = new TcAdsNcServer(svrPortNrNc, amsNetId);
            adsPlcServer = new TcAdsPlcServer(801, amsNetId);

            // map the adsServer object to the main form
            mainApp.AdsPlcServer = adsPlcServer;
            mainApp.AdsNcServer  = adsNcServer;

            // connect the components to the adsServer
            tcSpeedControl1.AdsNcServer = adsNcServer;
            tcAxesList1.AdsNcServer     = adsNcServer;
            tcOverride1.AdsNcServer     = adsNcServer;
            tcTechnoData1.AdsNcServer   = adsNcServer;
            blockSearch1.AdsPlcServer   = adsPlcServer;
            syntaxCheck1.AdsPlcServer   = adsPlcServer;
            teachIn1.AdsPlcServer       = adsPlcServer;
            teachIn1.AdsNcServer        = adsNcServer;
            opModeManual1.AdsNcServer   = adsNcServer;

            if (svrPortNrNc == 501 && MainApp.appSettings.plcVarNciOverrideChannel1 != "")
            {
                tcPlcConnectNciOvrChannel0 = new TcPlcConnect();
                tcPlcConnectNciOvrChannel0.PlcVariableName = MainApp.appSettings.plcVarNciOverrideChannel1;
                tcPlcConnectNciOvrChannel0.AdsPlcServer    = adsPlcServer;
                tcPlcConnectNciOvrChannel0.ValueChanged   += new TcPlcValueChangedEventHandler(tcPlcConnectNciOvrChannel0_ValueChanged);
            }

            plcFKeyRightStatus = new bool[8];
            plcFKeyLeftStatus  = new bool[8];

            // Language Manager
            tclm = mainApp.GetTCLanguageManager();
            tcAxesList1.LanguageManager     = tclm;
            tcOverride1.LanguageManager     = tclm;
            tcSpeedControl1.LanguageManager = tclm;
            tcTechnoData1.LanguageManager   = tclm;
            blockSearch1.LanguageManager    = tclm;
            syntaxCheck1.LanguageManager    = tclm;
            teachIn1.LanguageManager        = tclm;

            // Operation Mode Keys
            tcFKeyOpMode.Visible = false;

            // color for the right and left keys
            tcFKeyLeft.FKeyBtnBackColor      = mainApp.ColorFKeyLR;
            tcFKeyLeft.FKeyBtnSelectedColor  = mainApp.ColorCaption;
            tcFKeyLeft.BackColor             = mainApp.ColorFKeyLR;
            tcFKeyRight.FKeyBtnBackColor     = mainApp.ColorFKeyLR;
            tcFKeyRight.FKeyBtnSelectedColor = mainApp.ColorCaption;
            tcFKeyRight.BackColor            = mainApp.ColorFKeyLR;

            // Set the program name for the first channel
            opModeAuto1.selectFile1.Arguments = MainApp.appSettings.programName[1];
            opModeAuto1.tcNcProgramSection1.CncProgramName = MainApp.appSettings.programName[1];

            System.Collections.Generic.List <string> listOfSearchPaths = new System.Collections.Generic.List <string>();
            int nMin = MainApp.appSettings.pathSettings.GetLowerBound(0);
            int nMax = MainApp.appSettings.pathSettings.GetUpperBound(0);

            for (int i = nMin; i <= nMax; i++)
            {
                if (!string.IsNullOrEmpty(MainApp.appSettings.pathSettings[i]))
                {
                    listOfSearchPaths.Add(MainApp.appSettings.pathSettings[i]);
                }
            }
            adsNcServer.NcClient.ProgramSectionPathList(listOfSearchPaths);

            opModeMDI1.MdiText = MainApp.appSettings.mdiCommand[1];

            // Delegate instance: Selecting axis in manual mode
            tcAxesList1.AxisSelectEvent += new SingleAxisSelectEventHandler(tcAxesList1_AxisSelectEvent);

            // Delegate instance: Override change
            tcOverride1.OverrideChanged += new OverrideChangedEventHandler(tcOverride1_OverrideChanged);

            // Delegate instance: TwinCAT Cnc is Running
            adsNcServer.TcNcStateChanged += new Beckhoff.Forms.Nc.TcAdsStateChangedEventHandler(adsNcServer_TcNcStateChanged);

            // Delegate instance: TwinCAT Plc is Running
            adsPlcServer.TcPlcStateChanged += new Beckhoff.Forms.TcAdsStateChangedEventHandler(adsPlcServer_TcPlcStateChanged);

            // Delegate instance: Error handling for errors from the AdsServer
            adsNcServer.NcClient.Error   += new Beckhoff.Forms.Nc.TcErrorEventHandler(AdsClient_Error);
            adsPlcServer.PlcClient.Error += new Beckhoff.Forms.TcErrorEventHandler(AdsClient_Error);

            // Delegate instance: Operation mode switch
            adsNcServer.NcClient.OpModeStateChanged += new CncOpModeStateChangedEventHandler(NcClient_OpModeStateChanged);

            // Moves the operation modes key-window
            OpModeWindow = new OperationModeWindow();

            TimerStatusUpdate          = new Timer();
            TimerStatusUpdate.Interval = 2000;
            TimerStatusUpdate.Tick    += new EventHandler(TimerStatusUpdate_Tick);

            //
            tcChannelStatus1.AdsNcServer   = adsNcServer;
            tcChannelStatus2.AdsNcServer   = adsNcServer;
            tcChannelStatus3.AdsNcServer   = adsNcServer;
            tcChannelStatus4.AdsNcServer   = adsNcServer;
            tcChannelStatus1.ChannelNumber = 1;
            tcChannelStatus2.ChannelNumber = 2;
            tcChannelStatus3.ChannelNumber = 3;
            tcChannelStatus4.ChannelNumber = 4;

            tcAxesList2.AdsNcServer   = adsNcServer;
            tcAxesList3.AdsNcServer   = adsNcServer;
            tcAxesList4.AdsNcServer   = adsNcServer;
            tcAxesList5.AdsNcServer   = adsNcServer;
            tcAxesList2.ChannelNumber = 1;
            tcAxesList3.ChannelNumber = 2;
            tcAxesList4.ChannelNumber = 3;
            tcAxesList5.ChannelNumber = 4;
            panelChannelOverview.BringToFront();

            tcAxesList1.CaptionBackColor     = mainApp.ColorCaption;
            tcChannelStatus1.BackColor       = mainApp.ColorCaption;
            tcChannelStatus2.BackColor       = mainApp.ColorCaption;
            tcChannelStatus3.BackColor       = mainApp.ColorCaption;
            tcChannelStatus4.BackColor       = mainApp.ColorCaption;
            tcSpeedControl1.CaptionBackColor = mainApp.ColorCaption;
            tcTechnoData1.CaptionBackColor   = mainApp.ColorCaption;
            tcOverride1.CaptionBackColor     = mainApp.ColorCaption;
            opModeAuto1.CaptionBackColor     = mainApp.ColorCaption;
            opModeManual1.CaptionBackColor   = mainApp.ColorCaption;
            opModeMDI1.CaptionBackColor      = mainApp.ColorCaption;
            blockSearch1.CaptionBackColor    = mainApp.ColorCaption;
            syntaxCheck1.CaptionBackColor    = mainApp.ColorCaption;
            teachIn1.CaptionBackColor        = mainApp.ColorCaption;

            tcAxesList1.AxisRowHeight = MainApp.appSettings.axesRowHeight;
            if (MainApp.appSettings.overrideStyle == true)              //changeable by screen
            {
                tcOverride1.PlcVarFeedOverride = MainApp.appSettings.plcVarFeedOverride;
            }
            tcOverride1.PlcVarSpindleOverride = MainApp.appSettings.plcVarSpindleOverride;
            tcOverride1.OverrideStyle         = (MainApp.appSettings.overrideStyle == true) ? 2 : 1;

            if (tcOverride1.OverrideStyle == 1 && tcOverride1.PlcVarSpindleOverride.Length != 0)
            {
                SetPLCVar(tcOverride1.PlcVarSpindleOverride, 100);
                tcOverride1.SpindleOverrideValue = 100;
            }

            // Status from the NCI channel
            oldOpState.Mode  = new Int16[8];
            oldOpState.State = new Int16[8];
            if (svrPortNrNc == 501)
            {
                tcPlcConnect1.AdsPlcServer    = adsPlcServer;
                tcPlcConnect2.AdsPlcServer    = adsPlcServer;
                tcPlcConnect1.PlcVariableName = ".PLCNciChannelState.Mode";
                tcPlcConnect2.PlcVariableName = ".PLCNciChannelState.State";
            }
        }