CIDebugControl.cs 5.3 KB
using OnlineStore;
using DeviceLibrary;
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.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using ConfigHelper;

namespace TheMachine.device
{
    public partial class CIDebugControl : UserControl
    {
        public CIDebugControl()
        {
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            //Config.PropertyBind(Setting_Init.VJCounter_COMPORT.Key, cb_com, "SelectedItem", "SelectedIndexChanged");
            //Config.PropertyBind(Setting_Init.VJCounter_BaudRate.Key, cb_bitrate, "SelectedItem", "SelectedIndexChanged");
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (!TrayStop.DeviceList.ContainsKey("CI"))
                return;
            CI.DeviceList["CI"].ReelReady += CIDebugControl_ReelReady;
            CI.DeviceList["CI"].XRayStep += CIDebugControl_XRayStep;
            CI.DeviceList["CI"].ManualCount = cb_manualcount.Checked;
        }
        XRayStepE currentstep= XRayStepE.Finish;
        private void CIDebugControl_XRayStep(object sender, XRayStepE e)
        {
            currentstep = e;
            LogUtil.info("CID:CI测试界面接受到步骤:" + e);
            this.Invoke((EventHandler)delegate
            {
                switch (e)
                {
                    case XRayStepE.WaitMTtoVJ:
                        btn_start.Enabled = true;
                        break;
                    case XRayStepE.Counting:
                        btn_start.Enabled = false;
                        break;
                    case XRayStepE.WaitVJtoMT:
                        btn_finishcount.Enabled = true;
                        break;
                    case XRayStepE.Finish:
                        btn_finishcount.Enabled = false;
                        btn_start.Enabled = false;
                        break;
                }
            });
        }

        private void CIDebugControl_ReelReady(object sender, string e)
        {
            this.Invoke((EventHandler)delegate {
                LogUtil.info("CID:CI测试界面接受到条码:" + e);
                txt_barcode.Text = e;
            });
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!TrayStop.DeviceList.ContainsKey("CI"))
                return;
            string status = "";
            if (TrayStop.DeviceList["CI"].IOValue(IO_Type.CI_Count_Finished).Equals(IO_VALUE.HIGH))
            {
                status = "Ready";
            }
            else
            {
                status = "Counting";
            }

            label_status.Text = status+", "+ currentstep;
            label_watchstatus.Text = $"Last SN:{RobotManage.folderWatcher.LastSN}, QTY:{RobotManage.folderWatcher.LastQty}, " + RobotManage.folderWatcher.LastUpdateTime.ToString();
        }

        private void btn_start_Click(object sender, EventArgs e)
        {
            if (CI.DeviceList["CI"].MoveInfo.MoveStep == MoveStep.MI_01)
                CI.DeviceList["CI"].MoveInfo.NextMoveStep(MoveStep.MI_02);
            else
                MessageBox.Show("没有准备点料的托盘");

            return;

            if (TrayStop.DeviceList["CI"].IOValue(IO_Type.CI_Count_Finished).Equals(IO_VALUE.HIGH))
            {
                if (VJCounter.CheckConnect())
                {
                    VJCounter.SendBarcode(txt_barcode.Text.Trim());
                    Thread.Sleep(500);
                    TrayStop.DeviceList["CI"].IOMove(IO_Type.CI_Start, IO_VALUE.HIGH, 500);
                    LogUtil.info("CID:手动点击开始点料");
                }
                else {
                    MessageBox.Show(crc.GetString("Res0117.c9f109fe","未成功连接VJ点料机"));
                }
            }
            else
            {
                MessageBox.Show(crc.GetString("Res0118.f955ef4e","点料机没有准备好,不能启动."));
            }
        }

        private void cb_manualcount_CheckedChanged(object sender, EventArgs e)
        {
            CI.DeviceList["CI"].ManualCount = cb_manualcount.Checked;
        }

        private void btn_finishcount_Click(object sender, EventArgs e)
        {
            LogUtil.info("CID:用户确认放料完成");
            CI.DeviceList["CI"].StartOutStore();
        }

        private void btn_manualsend_Click(object sender, EventArgs e)
        {
            LogUtil.info("CID:手动点击SendBarcode");

            var bc = txt_barcode.Text.Trim() + VJCounter.newline;
            VJCounter.SendBarcode(bc);
            MessageBox.Show("send: \"" + bc.Replace("\r","\\r").Replace("\n","\\n")+"\"");
        }

        private void btn_reopen_Click(object sender, EventArgs e)
        {
            if (!VJCounter.Connect(Setting_Init.VJCounter_COMPORT, Setting_Init.VJCounter_BaudRate, out string msgs))
            {
                MessageBox.Show(msgs);
            }
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            LogUtil.info("CID:手动点击startbtn");
            TrayStop.DeviceList["CI"].IOMove(IO_Type.CI_Start, IO_VALUE.HIGH, 500);
        }
    }
}