AxisControl.cs 5.1 KB
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class AxisControl : UserControl
    {
        public AxisControl()
        {
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            if (DesignMode)
                return;
            crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
        }

        private void Crc_LanguageChangeEvent(object sender, EventArgs e)
        {
            RobotManage_LoadFinishEvent(true, "");
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((EventHandler)delegate
                {
                    RobotManage_LoadFinishEvent(state, msg);
                });
                return;
            }

            if (!state)
                return;
            axisMoveControl1.LoadData(AxisBean.List);
            configControl1.Config = RobotManage.Config;
            LogUtil.info("伺服面板加载完成.");
            timer1.Start();

        }





        private void AxisControl_Load(object sender, EventArgs e)
        {

        }
        volatile bool roateloop = false;
        private void button2_Click(object sender, EventArgs e)
        {
            Task.Run(() => {
                var p1 = RobotManage.mainMachine.Config.UpDown_P1;
                var p1_speed = RobotManage.mainMachine.Config.UpDown_P1_speed;
                var axis = RobotManage.mainMachine.UpDown_Axis;
                roateloop = true;
                while (roateloop)
                {
                    axis.AbsMove(null, p1, p1_speed);
                    Task.Delay(200).Wait();
                    while (axis.IsBusy)
                    {
                        Task.Delay(100).Wait();
                    }
                    if (!roateloop)
                        break;
                    Task.Delay(500).Wait();
                    axis.AbsMove(null, 1, p1_speed);
                    Task.Delay(200).Wait();
                    while (axis.IsBusy)
                    {
                        Task.Delay(100).Wait();
                    }
                    Task.Delay(500).Wait();
                }

            });

            Task.Run(() => {
                var p1 = RobotManage.mainMachine.Config.Middle_P1;
                var p1_speed = RobotManage.mainMachine.Config.Middle_P1_speed;
                var axis = RobotManage.mainMachine.Middle_Axis;
                roateloop = true;
                while (roateloop)
                {
                    axis.AbsMove(null, p1, p1_speed);
                    Task.Delay(200).Wait();
                    while (axis.IsBusy)
                    {
                        Task.Delay(100).Wait();
                    }
                    if (!roateloop)
                        break;
                    Task.Delay(500).Wait();
                    axis.AbsMove(null, 1, p1_speed);
                    Task.Delay(200).Wait();
                    while (axis.IsBusy)
                    {
                        Task.Delay(100).Wait();
                    }
                    Task.Delay(500).Wait();
                }

            });
        }

        private void button3_Click(object sender, EventArgs e)
        {
            roateloop = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }
            try
            { 
                if (Setting_Init.Device_LedLight_PortName != "")
                {
                    lblLed.Text ="LED"+ Setting_Init.Device_LedLight_PortName+":"+ RobotManage.mainMachine.lastColor.ToString();
                }
                else
                {
                    lblLed.Text = "";
                }

                if (Setting_Init.Device_DauxiKS107_PortName != "")
                {
                    RobotManage.dauxiKS107Controller.Quary(out int currValue, out string msg);
                    lblSensor.Text = $"红外传感器{Setting_Init.Device_DauxiKS107_PortName}:" + currValue + ", /" + Setting_Init.Device_DauxiKS107_BaseValue + "/" + Setting_Init.Device_DauxiKS107_ErrorValue;
                }
                else
                {
                    lblSensor.Text = "";
                }
                if (Setting_Init.Device_WeightSensor_PortName != "")
                {
                    lblOkValue.Text = $"压力传感器{Setting_Init.Device_WeightSensor_PortName}: {Setting_Init.Device_WeightSensor_MaxValue}";
                }
                else
                {
                    lblOkValue.Text = "";
                }

            }
            catch(Exception ex)
            {
                LogUtil.error("出错:" + ex.ToString());
            }
        }
    }
}