FrmAxisDebug.cs 18.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
using DeviceLib;
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
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 OnlineStore.AutoInOutStore
{

    public partial class FrmAxisDebug : FrmBase
    {
        //private KTK_LA_BoxBean store;
        private ConfigMoveAxis middle = null;
        private ConfigMoveAxis updown = null;
        //private ConfigMoveAxis compress = null;
        private ConfigMoveAxis inout = null;
        private ConfigMoveAxis auto = null;
        private ConfigMoveAxis comp = null;
       

        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmAxisDebug(AC_SA_BoxBean boxBean)
        {
            middle = boxBean.Config.Middle_Axis;
            updown = boxBean.Config.UpDown_Axis;
            comp = boxBean.Config.Comp_Axis;
         //   compress_Slv = boxBean.Config.CompressAxis_Slv;
            inout = boxBean.Config.InOut_Axis;
            auto = boxBean.Config.Batch_Axis;
            InitializeComponent();
            this.Text = boxBean.StoreName + "_轴点动调试";
        }

        private void AxisMove(ConfigMoveAxis axis, int speed)
        {
            LogUtil.debug(LOGGER, "点动:deviceName=" + axis.DeviceName + ",axis=" + axis.GetAxisValue() + ",speed=" + speed);
            ACServerManager.SpeedMove(axis.DeviceName, axis.GetAxisValue(), speed);

        }
        private void FrmAxisDebug_Load(object sender, EventArgs e)
        {
            txtMiddleSpeed.Text = (middle.TargetSpeed / 5).ToString();
            txtInOutSpeed.Text = (inout.TargetSpeed / 5).ToString();
            txtUpDownSpeed.Text = (updown.TargetSpeed / 5).ToString();
            txtAutoSpeed.Text = (auto.TargetSpeed / 5).ToString();
            txtComSpeed.Text = (comp.TargetSpeed/5).ToString();
            //timer1.Start();
            UpdateMiddlePosition();
            UpdateInOutPosition();
            UpdateUpdownPosition();
            UpdateAutoPosition();
            UpdateCompPosition();
         //   txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
        }
        /// <summary>
        /// 判断进出轴是否在P1点
        /// </summary> 
        private bool InOutIsIsP1()
        {
            int InOutDefaultPosition = ConfigAppSettings.GetIntValue(Setting_Init.InOutDefaultPosition);
            //if (InOutDefaultPosition > 3000 || InOutDefaultPosition.Equals(0))
            //{
            //    InOutDefaultPosition = 3000;
            //}
            int currValue = ACServerManager.GetActualtPosition(inout.DeviceName, inout.GetAxisValue()); 
            if (currValue <= InOutDefaultPosition)
            {
                return true;
            }
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.InoutNotOk, "叉子不在待机位,请先将叉子退回待机位") + "(" + InOutDefaultPosition + ")!",
               ResourceCulture.GetString(ResourceCulture.InoutWarn, "警告(叉子在待机位时,才能移动升降轴和旋转轴)"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return false;
        }
        private void btnMiddleMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }
          
            if (btnMiddleMove.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtMiddleSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                btnMiddleMove.BackColor = Color.Green;
                AxisMove(middle, speed);
            }
        }

        private void btnMiddleMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMiddleMove.BackColor == Color.Green)
            {
                btnMiddleMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(middle.DeviceName, middle.GetAxisValue());
                UpdateMiddlePosition();
            }
        }

        private void btnUpDownMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }
            if (btnUpDownMove.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtUpDownSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                btnUpDownMove.BackColor = Color.Green;
                AxisMove(updown, speed);
            }
        }

        private void btnUpDownMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnUpDownMove.BackColor == Color.Green)
            {
                btnUpDownMove.BackColor = System.Drawing.SystemColors.Control;                
                ACServerManager.SuddenStop(updown.DeviceName, updown.GetAxisValue());
                UpdateUpdownPosition();
            }
        }

        private void btnInOutMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.btnInOutMove.BackColor .Equals(System.Drawing.SystemColors.Control))
            {
                if (StoreManager.Store.InOutAxisCanMove().Equals(false))
                {
                    MessageBox.Show(FrmStoreBox.cannotMove, FrmStoreBox.warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int speed = FormUtil.GetIntValue(txtInOutSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                this.btnInOutMove.BackColor = Color.Green;
                AxisMove(inout, speed);
            }
        }

        private void btnInOutMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.btnInOutMove.BackColor == Color.Green)
            {
                btnInOutMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(inout.DeviceName, inout.GetAxisValue());
                UpdateInOutPosition();
            }
        } 
        private void btnMiddleMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }
            if (btnMiddleMovej.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtMiddleSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                this.btnMiddleMovej.BackColor = Color.Green;
                AxisMove(middle, -speed);
            }
        }

        private void btnMiddleMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnMiddleMovej.BackColor == Color.Green)
            {
                btnMiddleMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(middle.DeviceName, middle.GetAxisValue());
                UpdateMiddlePosition();
            }
        }

        private void btnUpDownMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (!InOutIsIsP1())
            {
                return;
            }
            if (btnUpDownMovej.BackColor .Equals( System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtUpDownSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                btnUpDownMovej.BackColor = Color.Green;
                AxisMove(updown, -speed);
            }
        }

        private void btnUpDownMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnUpDownMovej.BackColor == Color.Green)
            {
                btnUpDownMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(updown.DeviceName, updown.GetAxisValue());
                UpdateUpdownPosition();
            }
        }

        private void btnInOutMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (btnInOutMovej.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                if (StoreManager.Store.InOutAxisCanMove().Equals(false))
                {
                    MessageBox.Show(FrmStoreBox.cannotMove, FrmStoreBox.warn, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int speed = FormUtil.GetIntValue(txtInOutSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                this.btnInOutMovej.BackColor = Color.Green;
                AxisMove(inout, -speed);
            }
        }

        private void btnInOutMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnInOutMovej.BackColor.Equals(Color.Green))
            {
                btnInOutMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(inout.DeviceName, inout.GetAxisValue());
                UpdateInOutPosition();
            } 
        }
        //private void btnComMove_MouseDown(object sender, MouseEventArgs e)
        //{
        //    int speed = FormUtil.GetIntValue(txtComSpeed);
        //    if (speed <= 0)
        //    {
        //          MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
        //        return;
        //    }
        //    this.btnComMove.BackColor = Color.Green;

        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
        //    ShuoKeControls.VolMove(compress_Slv, speed);
        //}

        //private void btnComMove_MouseUp(object sender, MouseEventArgs e)
        //{
        //    if (this.btnComMove.BackColor == Color.Green)
        //    {
        //        btnComMove.BackColor = System.Drawing.SystemColors.Control; 
        //        ShuoKeControls.SuddownStop(compress_Slv);
        //        txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
        //    }
        //}
        //private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
        //{
        //    int speed = FormUtil.GetIntValue(txtComSpeed);
        //    if (speed <= 0)
        //    {
        //          MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
        //        return;
        //    }
        //    this.btnComMovej.BackColor = Color.Green; 
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetEndSpeed, speed);
        //    ShuoKeControls.SetSpeed(compress_Slv, ShuoKeCMD.SetMaxSpeed, speed);
        //    ShuoKeControls.VolMove(compress_Slv,-speed);
        //}

        //private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
        //{
        //    if (btnComMovej.BackColor.Equals(Color.Green))
        //    {
        //        btnComMovej.BackColor = System.Drawing.SystemColors.Control;
        //        ShuoKeControls.SuddownStop(compress_Slv);
        //        txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
        //    }
        //}
        private void btnComMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (btnComMove.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtComSpeed);
                if (speed <= 0)
                {
                    MessageBox.Show("提示", "请先输入正确的速度");
                    return;
                }
                this.btnComMove.BackColor = Color.Green;
                AxisMove(comp, speed);
            }
        }

        private void btnComMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.btnComMove.BackColor == Color.Green)
            {
                btnComMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(comp.DeviceName, comp.GetAxisValue());
                UpdateCompPosition();
            }
        }
        private void btnComMovej_MouseDown(object sender, MouseEventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtComSpeed);
            if (speed <= 0)
            {
                MessageBox.Show("提示", "请先输入正确的速度");
                return;
            }
            this.btnComMovej.BackColor = Color.Green;
            AxisMove(comp, -speed);
        }

        private void btnComMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnComMovej.BackColor.Equals(Color.Green))
            {
                btnComMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(comp.DeviceName, comp.GetAxisValue());
                UpdateCompPosition();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
         

        private void FrmAxisDebug_Shown(object sender, EventArgs e)
        { 
            SetSkin(this);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                UpdateMiddlePosition();
                UpdateInOutPosition();
                UpdateUpdownPosition();
                UpdateAutoPosition();
                UpdateCompPosition();
                //txtComPosition.Text = ShuoKeControls.GetLastPosition(compress_Slv).ToString();
                
            }
        }
        private void UpdateCompPosition()
        {
            int compPosition = ACServerManager.GetTargetPosition(comp.DeviceName, comp.GetAxisValue());
            if (!txtComPosition.Text.Equals(compPosition.ToString()))
            {
                txtComPosition.Text = compPosition.ToString();
            }
        }
        private void UpdateUpdownPosition()
        {
            int updownPosition = ACServerManager.GetTargetPosition(updown.DeviceName, updown.GetAxisValue());
            if (!txtUpdownPosition.Text.Equals(updownPosition.ToString()))
            {
                txtUpdownPosition.Text = updownPosition.ToString();
            }
        }

        private void UpdateMiddlePosition()
        {
            int middlePosition = ACServerManager.GetTargetPosition(middle.DeviceName, middle.GetAxisValue());
            if (!txtMiddlePosition.Text.Equals(middlePosition.ToString()))
            {
                txtMiddlePosition.Text = middlePosition.ToString();
            }
        }

        private void UpdateInOutPosition()
        {
            int inoutPosition = ACServerManager.GetTargetPosition(inout.DeviceName, inout.GetAxisValue());
            if (!txtInOutPosition.Text.Equals(inoutPosition.ToString()))
            {
                txtInOutPosition.Text = inoutPosition.ToString();
            }
        }
        private void UpdateAutoPosition()
        {
            int autoPosition = ACServerManager.GetTargetPosition(auto.DeviceName, auto.GetAxisValue());
            if (!txtAutoPosition.Text.Equals(autoPosition.ToString()))
            {
                txtAutoPosition.Text = autoPosition.ToString();
            }
        }
        private void btnAutoMove_MouseDown(object sender, MouseEventArgs e)
        {
            if (btnAutoMove.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtAutoSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                btnAutoMove.BackColor = Color.Green;
                AxisMove(auto, speed);
            } 
        }

        private void btnAutoMove_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnAutoMove.BackColor == Color.Green)
            {
                btnAutoMove.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(auto.DeviceName, auto.GetAxisValue());
                UpdateAutoPosition();
            }
        }

        private void btnAutoMovej_MouseDown(object sender, MouseEventArgs e)
        {
            if (btnAutoMovej.BackColor.Equals(System.Drawing.SystemColors.Control))
            {
                int speed = FormUtil.GetIntValue(txtAutoSpeed);
                if (speed <= 0)
                {
                      MessageBox.Show(ResourceCulture.GetString(ResourceCulture.MsgTitle,"提示"),ResourceCulture.GetString(ResourceCulture.PWSpeed, "请先输入正确的速度"));
                    return;
                }
                btnAutoMovej.BackColor = Color.Green;
                AxisMove(auto, -speed);
            }
        }

        private void btnAutoMovej_MouseUp(object sender, MouseEventArgs e)
        {
            if (btnAutoMovej.BackColor == Color.Green)
            {
                btnAutoMovej.BackColor = System.Drawing.SystemColors.Control;
                ACServerManager.SuddenStop(auto.DeviceName, auto.GetAxisValue());
                UpdateAutoPosition();
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            UpdateMiddlePosition();
            UpdateInOutPosition();
            UpdateUpdownPosition();
            UpdateAutoPosition();
            UpdateCompPosition();
         //   txtComPosition.Text = ShuoKeControls.GetABSPosition(compress_Slv).ToString();
        }
    }
}