프로젝트/Wafer 코팅 시뮬레이션 [반도체 장비 제어 시스템]

WaferLine 공장 시뮬레이션 - Windows Forms

언제나 휴일 빅데이터 언제나휴일 2021. 2. 27. 08:57
반응형

WaferLine 공장 시뮬레이션은 Windows Forms 앱(.NET Framework)입니다.

 

WaferLine 공장 시뮬레이션 컴포넌트 다이어그램
WaferLine 공장 시뮬레이션.zip
0.11MB

1. Manager.cs

using System.Net;
using WaferLineCommLib;
using WaferLineLib;

namespace WaferLine_공장_시뮬레이션
{
    public class Manager
    {
        public event RecvStsEndPtEventHandler RecvStsEndPoint;
        public event AddWaferEventHandler AddedWafer;
        public event AddPREventHandler AddedPR;
        public event SetSpeedEventHandler SettedSpeed;
        public event SetDropEventHandler SettedDrop;
        private Manager()
        {

        }
        static Manager manager = new Manager();
        static public Manager Singleton
        {
            get
            {
                return manager;
            }
        }
        public void StartServer(string ip,int port)
        {
            FactoryServer fs = new FactoryServer(ip, port);
            fs.RecvStsEndPoint += Fs_RecvStsEndPoint;
            fs.AddedWafer += Fs_AddedWafer;
            fs.AddedPR += Fs_AddedPR;
            fs.SettedSpeed += Fs_SettedSpeed;
            fs.SettedDrop += Fs_SettedDrop;
            fs.StartAsync();
        }
        private void Fs_SettedDrop(object sender, SetDropEventArgs e)
        {
            if (SettedDrop != null)
            {
                SettedDrop(this, e);
            }
        }

        private void Fs_SettedSpeed(object sender, SetSpeedEventArgs e)
        {
            if (SettedSpeed != null)
            {
                SettedSpeed(this, e);
            }
        }



        private void Fs_AddedPR(object sender, AddPREventArgs e)
        {
            if (AddedPR != null)
            {
                AddedPR(this, e);
            }
        }

        private void Fs_AddedWafer(object sender, AddWaferEventArgs e)
        {
            if (AddedWafer != null)
            {
                AddedWafer(this, e);
            }
        }

        ControlClient cc;
        private void Fs_RecvStsEndPoint(object sender, RecvStsEndPtEventArgs e)
        {
            IPAddress cip = e.IPAddress;
            int cport = e.Port;
            cc = new ControlClient(cip, cport);
            if(RecvStsEndPoint != null)
            {
                RecvStsEndPoint(this, e);
            }
        }

        public void AddLine(int no)
        {
            if(cc == null)
            {
                return;
            }
            if(cc.SendAddLine(no) == false)
            {
                cc = null;
            }
        }

        public void AddWafer(int no, int bwcnt)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendAddWafer(no,bwcnt) == false)
            {
                cc = null;
            }
        }

        public void AddPR(int no, int pcnt)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendAddPR(no, pcnt) == false)
            {
                cc = null;
            }
        }

        public void EndedPR(int no)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendEndPR(no) == false)
            {
                cc = null;
            }
        }

        public void SetSpeed(int no, int spin)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendSetSpeed(no,spin) == false)
            {
                cc = null;
            }
        }

        public void SetDrop(int no, int drop)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendSetDrop(no, drop) == false)
            {
                cc = null;
            }
        }

        public void EndedCoating(int no, int bwcnt, int awcnt)
        {
            if (cc == null)
            {
                return;
            }
            if (cc.SendEndedCoating(no, bwcnt, awcnt) == false)
            {
                cc = null;
            }
        }
    }
}

2. MainForm.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using WaferLineCommLib;
using WaferLineLib;

namespace WaferLine_공장_시뮬레이션
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        int next_lineno = 1;
        Dictionary<int, WaferLineForm> wdic = new Dictionary<int, WaferLineForm>();

        private void btn_add_Click(object sender, EventArgs e)
        {
            int no = next_lineno;
            next_lineno++;
            WaferLine wl = new WaferLine(no);
            string[] sitems = new string[] { no.ToString(), "0", "0" };
            ListViewItem lvi = new ListViewItem(sitems);
            lvi.Tag = wl;
            lv_line.Items.Add(lvi);
            cb_line.Items.Add(wl);
            lb_next_no.Text = next_lineno.ToString();
            WaferLineForm wlf = new WaferLineForm(wl);
            wlf.EndedCoating += Wlf_EndedCoating;
            wlf.AddedWafer += Wlf_AddedWafer;
            wlf.AddedPR += Wlf_AddedPR;
            wlf.SettedSpeed += Wlf_SettedSpeed;
            wlf.SettedDrop += Wlf_SettedDrop;
            wlf.EndedPR += Wlf_EndedPR;
            wdic.Add(no, wlf);
            Manager manager = Manager.Singleton;
            manager.AddLine(no);
        }

        private void Wlf_EndedPR(object sender, EndPREventArgs e)
        {
            ListViewItem lvi = lv_line.Items[e.No - 1];
            if(lvi.Selected)
            {
                WaferLine wl = lvi.Tag as WaferLine;
                lb_pr.Text = wl.PCnt.ToString();
            }
        }

        private void Wlf_SettedDrop(object sender, SetDropEventArgs e)
        {
            ChangeStatusSelectedWaferLine(e.No);
        }

        private void ChangeStatusSelectedWaferLine(int no)
        {
            ListViewItem lvi = lv_line.Items[no - 1];
            if(lvi.Selected)
            {
                WaferLine wl = lvi.Tag as WaferLine;
                lb_spin.Text = wl.Spin.ToString();
                lb_drop.Text = wl.Drop.ToString();
                lb_pr.Text = wl.PCnt.ToString();
            }
        }

        private void Wlf_SettedSpeed(object sender, SetSpeedEventArgs e)
        {
            ChangeStatusSelectedWaferLine(e.No);
        }

        private void Wlf_AddedPR(object sender, AddPREventArgs e)
        {
            ChangeStatusSelectedWaferLine(e.No);
        }

        private void Wlf_AddedWafer(object sender, AddWaferEventArgs e)
        {
            ChangeStatusWaferLine(e.No);
        }
        void ChangeStatusWaferLine(int no)
        {
            ListViewItem lvi = lv_line.Items[no - 1];
            WaferLine wl = lvi.Tag as WaferLine;
            lvi.SubItems[1].Text = wl.BWCnt.ToString();
            lvi.SubItems[2].Text = wl.AWCnt.ToString();
            cb_line.Items[no - 1] = wl;
        }

        private void Wlf_EndedCoating(object sender, EndCoatingEventArgs e)
        {
            ChangeStatusWaferLine(e.No);
            ListViewItem lvi = lv_line.Items[e.No - 1];
            if(lvi.Selected)
            {
                WaferLine wl = lvi.Tag as WaferLine;
                cb_awafer.Items.Add(wl.LastWafer);
                lb_pr.Text = wl.PCnt.ToString();
            }
        }

        private void btn_manage_Click(object sender, EventArgs e)
        {
            if(cb_line.SelectedIndex == -1)
            {
                return;
            }
            WaferLine wl = cb_line.SelectedItem as WaferLine;
            if(wdic[wl.No].Visible == false)
            {
                wdic[wl.No].Show();
            }
        }

        private void cb_awafer_SelectedIndexChanged(object sender, EventArgs e)
        {
            pn_awafer.Wafer = cb_awafer.SelectedItem as Wafer;
            pn_awafer.Invalidate();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            cbox_ip.DataSource = MyNetwork.Addresses;
            Manager manager = Manager.Singleton;
            manager.RecvStsEndPoint += Manager_RecvStsEndPoint;
            manager.AddedWafer += Manager_AddedWafer;
            manager.AddedPR += Manager_AddedPR;
            manager.SettedSpeed += Manager_SettedSpeed;
            manager.SettedDrop += Manager_SettedDrop;
        }

        private void Manager_SettedDrop(object sender, SetDropEventArgs e)
        {
            if(this.InvokeRequired)
            {
                SetDropEventHandler dele = Manager_SettedDrop;
                this.Invoke(dele, new object[] { sender, e });
            }
            else
            {
                ListViewItem lvi = lv_line.Items[e.No - 1];
                WaferLine wl = lvi.Tag as WaferLine;
                wl.Drop = e.Drop;
                WaferLineForm lvf = wdic[e.No];
                lvf.SetStatus();
                if(lvi.Selected)
                {
                    lb_drop.Text = e.Drop.ToString();
                }
            }
        }

        private void Manager_SettedSpeed(object sender, SetSpeedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                SetSpeedEventHandler dele = Manager_SettedSpeed;
                this.Invoke(dele, new object[] { sender, e });
            }
            else
            {
                ListViewItem lvi = lv_line.Items[e.No - 1];
                WaferLine wl = lvi.Tag as WaferLine;
                wl.Spin = e.Speed;
                WaferLineForm lvf = wdic[e.No];
                lvf.SetStatus();
                if (lvi.Selected)
                {
                    lb_spin.Text = e.Speed.ToString();
                }
            }
        }

        private void Manager_AddedPR(object sender, AddPREventArgs e)
        {
            if (this.InvokeRequired)
            {
                AddPREventHandler dele = Manager_AddedPR;
                this.Invoke(dele, new object[] { sender, e });
            }
            else
            {
                ListViewItem lvi = lv_line.Items[e.No - 1];
                WaferLine wl = lvi.Tag as WaferLine;
                wl.InPr(e.PCnt);
                ChangeStatusWaferLine(e.No);
                WaferLineForm lvf = wdic[e.No];
                lvf.Invalidate(true);
            }
        }

        private void Manager_AddedWafer(object sender, AddWaferEventArgs e)
        {
            if (this.InvokeRequired)
            {
                AddWaferEventHandler dele = Manager_AddedWafer;
                this.Invoke(dele, new object[] { sender, e });
            }
            else
            {
                ListViewItem lvi = lv_line.Items[e.No - 1];
                WaferLine wl = lvi.Tag as WaferLine;
                wl.InWafer(e.BWCnt);
                ChangeStatusWaferLine(e.No);
                WaferLineForm lvf = wdic[e.No];
                lvf.Invalidate(true);
            }
        }

        private void Manager_RecvStsEndPoint(object sender, RecvStsEndPtEventArgs e)
        {
            if (this.InvokeRequired)
            {
                RecvStsEndPtEventHandler dele = Manager_RecvStsEndPoint;
                this.Invoke(dele, new object[] { sender, e });
            }
            else
            {
                Manager manager = Manager.Singleton;
                foreach(ListViewItem lvi in lv_line.Items)
                {
                    int no = int.Parse(lvi.SubItems[0].Text);
                    manager.AddLine(no);
                    manager.AddWafer(no, int.Parse(lvi.SubItems[1].Text));
                    WaferLine wl = lvi.Tag as WaferLine;
                    manager.AddPR(no, wl.PCnt);
                    manager.SetSpeed(no, wl.Spin);
                    manager.SetDrop(no, wl.Drop);
                }
                ts_lb.Text = string.Format("{0}:{1} 연결", e.IPAddress, e.Port);
            }
        }

        private void btn_set_Click(object sender, EventArgs e)
        {
            int port = int.Parse(tbox_port.Text);
            string ip = cbox_ip.Text;
            Manager manger = Manager.Singleton;
            manger.StartServer(ip, port);
        }

        WaferLine select_line = null;
        private void lv_line_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lv_line.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem lvi = lv_line.SelectedItems[0];
            select_line = lvi.Tag as WaferLine;
            SetSelectLine();
        }

        private void SetSelectLine()
        {
            lb_selno.Text = select_line.No.ToString();
            lb_spin.Text = select_line.Spin.ToString();
            lb_drop.Text = select_line.Drop.ToString();
            lb_pr.Text = select_line.PCnt.ToString();
            cb_awafer.Items.Clear();
            foreach (Wafer wafer in select_line)
            {
                cb_awafer.Items.Add(wafer);
            }
            cb_awafer.Text = "";
            pn_awafer.Invalidate();
        }

    }
}

3. WaferLineForm.cs

using System;
using System.Windows.Forms;
using WaferLineLib;

namespace WaferLine_공장_시뮬레이션
{
    public partial class WaferLineForm : Form
    {
        public event AddWaferEventHandler AddedWafer;
        public event AddPREventHandler AddedPR;
        public event SetSpeedEventHandler SettedSpeed;
        public event SetDropEventHandler SettedDrop;
        public event EndPREventHandler EndedPR;
        public event EndCoatingEventHandler EndedCoating;

        public WaferLine WLine { get; }
        public int No { get { return WLine.No; } }
        public WaferLineForm(WaferLine wl)
        {
            InitializeComponent();
            WLine = wl;
            WLine.AddedWafer += WLine_AddedWafer;
            WLine.AddedPR += WLine_AddedPR;
            WLine.EndedCoating += WLine_EndedCoating;
            WLine.EndedPR += WLine_EndedPR;
            WLine.SettedSpeed += WLine_SettedSpeed;
            WLine.SettedDrop += WLine_SettedDrop;
        }

        private void WLine_SettedDrop(object sender, SetDropEventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.SetDrop(e.No, e.Drop);
            if(SettedDrop != null)
            {
                SettedDrop(this, e);
            }
        }

        private void WLine_SettedSpeed(object sender, SetSpeedEventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.SetSpeed(No, e.Speed);
            if (SettedSpeed != null)
            {
                SettedSpeed(this, e);
            }
        }

        private void WLine_EndedPR(object sender, EndPREventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.EndedPR(e.No);
            if (EndedPR != null)
            {
                EndedPR(this, e);
            }
        }

        private void WLine_EndedCoating(object sender, EndCoatingEventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.EndedCoating(No, e.BWCnt, e.AWCnt);
            if (EndedCoating != null)
            {
                EndedCoating(this, e);
            }
        }

        private void WLine_AddedPR(object sender, AddPREventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.AddPR(e.No, e.PCnt);
            if (AddedPR != null)
            {
                AddedPR(this, e);
            }
        }

        private void WLine_AddedWafer(object sender, AddWaferEventArgs e)
        {
            Manager manager = Manager.Singleton;
            manager.AddWafer(e.No, e.BWCnt);
            if (AddedWafer != null)
            {
                AddedWafer(this, e);
            }
        }

        private void WaferLineForm_Load(object sender, EventArgs e)
        {
            lb_no.Text = No.ToString();
            wlc.Line = WLine;
        }

        private void WaferLineForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        internal void SetStatus()
        {
            wlc.SetStatus();
        }
    }
}
반응형