コード例 #1
0
 private void dispatcherTimer_Tick(object sender, EventArgs e)
 {
     if (TwincatConnector.IsConnected && TwincatConnector.Count > 0)
     {
         TwincatConnector.tcReadAll();
         for (int i = 0; i < DigitalOutputs.Count; i++)
         {
             if ((bool)TwincatConnector.tcGetData(DigitalOutputs[i].Index))
             {
                 DigitalOutputs[i].State = 1;
             }
             else
             {
                 DigitalOutputs[i].State = 0;
             }
         }
         for (int i = 0; i < DigitalInputs.Count; i++)
         {
             if ((bool)TwincatConnector.tcGetData(DigitalInputs[i].Index))
             {
                 DigitalInputs[i].State = 1;
             }
             else
             {
                 DigitalInputs[i].State = 0;
             }
         }
     }
     if (_AXIS_VIEW >= 0)
     {
         ((AxisDiagnostic)((TabItem)MainContent.SelectedItem).Content).AxisStatus = TwincatConnector.tcGetAxsPlcToHmi(_AXIS_VIEW);
     }
 }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();
            ADS_Sample.UI_Config.SetupManager.Load_DiagConfig();
            switch (TwincatConnector.tcConnect())
            {
            case tcFunctionResult.TC_SUCCESS:
                if (TwincatConnector.tcCreateHandle() == tcFunctionResult.TC_SUCCESS)
                {
                }
                else
                {
                }
                break;

            case tcFunctionResult.TC_FAIL_TO_LOAD_PLC_CONFIG:
                break;

            case tcFunctionResult.TC_FAIL_TO_CONNECT_DEVICE:
                break;
            }
        }
コード例 #3
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            XDocument PageConfig = XDocument.Load(@"UI Config/DiagPageConfig.xml");

            #region I/O
            foreach (XElement do_element in PageConfig.Root.Elements("Do"))
            {
                Control.DigitalIndicator LED = new Control.DigitalIndicator();
                LED.Caption = do_element.Attribute("Name").Value;
                LED.DigitalIndicatorClicked += DigitalOutput_Clicked;
                LED.Index = int.Parse(do_element.Attribute("Index").Value);
                DigitalOutputs.Add(LED);
            }
            foreach (XElement di_element in PageConfig.Root.Elements("Di"))
            {
                Control.DigitalIndicator LED = new Control.DigitalIndicator();
                LED.Caption = di_element.Attribute("Name").Value;
                //LED.DigitalIndicatorClicked += DigitalIndicator_Clicked;
                LED.Index = int.Parse(di_element.Attribute("Index").Value);
                DigitalInputs.Add(LED);
            }
            for (int i = 0; i < DigitalOutputs.Count; i++)
            {
                DoContent.Children.Add(DigitalOutputs[i]);
            }
            for (int i = 0; i < DigitalInputs.Count; i++)
            {
                DiContent.Children.Add(DigitalInputs[i]);
            }
            #endregion

            #region AXIS
            for (int i = 0; i < TwincatConnector.Axis_Count; i++)
            {
                TabItem AxisTab = new TabItem();
                AxisTab.Header = "Axis " + i.ToString();
                AxisDiagnostic AxisDiagObj = new AxisDiagnostic();
                AxisDiagObj.ID                 = i;
                AxisDiagObj.AxisName           = "Axis " + (i + 1).ToString();
                AxisDiagObj.ControlSetClicked += AxDiagSetControl_Clicked;
                AxisDiagObj.JogBwFastClicked  += AxisDiagObj_JogBwFastClicked;
                AxisDiagObj.JogBwSlowClicked  += AxisDiagObj_JogBwSlowClicked;
                AxisDiagObj.JogFwFastClicked  += AxisDiagObj_JogFwFastClicked;
                AxisDiagObj.JogFwSlowClicked  += AxisDiagObj_JogFwSlowClicked;
                AxisDiagObj.ResetClicked      += AxisDiagObj_ResetClicked;
                AxisDiagObj.MoveAbsClicked    += AxisDiagObj_MoveAbsClicked;
                AxisDiagObj.MoveRelClicked    += AxisDiagObj_MoveRelClicked;
                AxisTab.Content                = AxisDiagObj;
                MainContent.Items.Add(AxisTab);
            }
            #endregion

            if (TwincatConnector.IsConnected)
            {
                dispatcherTimer.Tick    += dispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
                dispatcherTimer.Start();
            }
            else
            {
                TwincatConnector.LogMessage("Not connected to device. Polling not started.");
            }
        }
コード例 #4
0
 private void DigitalOutput_Clicked(object sender, ADS_Sample.Control.DigitalIndicator.DigitalIndicationEventArgs e)
 {
     TwincatConnector.tcWriteData(e.Index, !e.State);
     TwincatConnector.LogMessage(string.Format("{0}\t: {1}", "Report", "Digital output triggered " + e.Index.ToString()));
 }
コード例 #5
0
 private void AxisDiagObj_MoveRelClicked(object sender, ADS_Sample.AxisDiagnostic.AxisDiagnosticClickEventArgs e)
 {
     TwincatConnector.tcSetAxisCommand(e.ID, e.COMMAND);
 }
コード例 #6
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     TwincatConnector.tcDispose();
 }