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

WaferLineLib 라이브러리

언제나휴일 2021. 2. 27. 08:43
반응형

WaferLineLib는 클래스 라이브러리(.Net Framework)입니다.

 

WaferLineLib.zip
0.00MB

1. Wafer.cs

namespace WaferLineLib
{
    /// <summary>
    /// Wafer 클래스
    /// </summary>
    public class Wafer
    {
        static int last_wn;
        readonly int wn;
        int[] cells = new int[100];
        int now;
        /// <summary>
        /// 기본 생성자
        /// </summary>
        public Wafer()
        {
            last_wn++;
            wn = last_wn;
        }
        /// <summary>
        /// 현재 코팅할 쉘 번호 - 가져오기
        /// </summary>
        public int Now
        {
            get
            {
                return now;
            }
        }
        /// <summary>
        /// 코팅할 쉘 번호 증가시키기
        /// </summary>
        /// <returns>증가 성공 여부</returns>
        public bool Increment()
        {
            if (now < 100)
            {
                now++;
                if (now == 100)
                {
                    return false;
                }
                return true;
            }
            return false;
        }
        /// <summary>
        /// 코팅 메서드
        /// </summary>
        /// <param name="quality">품질 수준</param>
        public void Coating(int quality)
        {
            if (Now < 100)
            {
                cells[Now] = quality;
            }
        }
        /// <summary>
        /// 특정 쉘의 품질 수준 인덱서  - 가져오기
        /// </summary>
        /// <param name="index">쉘 인덱스</param>
        /// <returns>특정 쉘의 품질</returns>
        public int this[int index]
        {
            get
            {
                if ((index < 0) || (index >= 100))
                {
                    return 0;
                }
                return cells[index];
            }
        }
        /// <summary>
        /// 평균 품질 - 가져오기
        /// </summary>
        public double Quality
        {
            get
            {
                int sum = 0;
                foreach (int elem in cells)
                {
                    sum += elem;
                }
                return sum / 100.0;
            }
        }
        /// <summary>
        /// ToString 메서드 재정의
        /// </summary>
        /// <returns>Wafer 번호와 평균 품질</returns>
        public override string ToString()
        {
            return string.Format("No:{0}, Quality:{1}", wn, Quality);
        }
    }
}

2. WaferLine.cs

using System;
using System.Collections;
using System.Collections.Generic;
using WaferLineLib;

namespace WaferLineLib
{
    public class WaferLine : IEnumerable<Wafer>
    {
        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 int No { get; }
        public int Spin
        {
            get;
            set;
        }
        public int Drop
        {
            get;
            set;
        }
        public WaferLine(int no)
        {
            No = no;
            Spin = 1000;
            Drop = 20;
        }
        List<Wafer> bwafers = new List<Wafer>();
        List<Wafer> awafers = new List<Wafer>();
        public Wafer LastWafer
        {
            get
            {
                if (awafers.Count == 0)
                {
                    return null;
                }
                return awafers[awafers.Count - 1];
            }
        }
        public void EndCoating(int bwcnt, int awcnt)
        {
            while (bwafers.Count > bwcnt)
            {
                bwafers.RemoveAt(0);
            }
            while (awafers.Count < awcnt)
            {
                awafers.Add(null);
            }
        }
        Wafer nwafer;
        int nowp;//1병은 1000쉘을 코팅할 수 있다.
        public Wafer Now { get { return nwafer; } }
        public int BWCnt
        {
            get { return bwafers.Count; }
        }
        public int InWafer(int wcnt)
        {
            int avail = 200 - BWCnt;
            if (wcnt > avail)
            {
                wcnt = avail;
            }
            for (int i = 0; i < wcnt; i++)
            {
                bwafers.Add(new Wafer());
            }
            if(AddedWafer != null)
            {
                AddedWafer(this, new AddWaferEventArgs(No, BWCnt));
            }
            return bwafers.Count;
        }
        public int AWCnt
        {
            get { return awafers.Count; }
        }
        public int PCnt { get; set; }
        public int NPcnt { get { return nowp; } }
        public int InPr(int pcnt)
        {
            int avail = 20 - PCnt;
            if (pcnt > avail)
            {
                pcnt = avail;
            }
            PCnt += pcnt;
            if(AddedPR != null)
            {
                AddedPR(this, new AddPREventArgs(No, PCnt));
            }
            return PCnt;
        }
        public void SetSpin(int spin)
        {
            Spin = spin;
            if(SettedSpeed != null)
            {
                SettedSpeed(this, new SetSpeedEventArgs(No,spin));
            }
        }
        public void SetDrop(int drop)
        {
            Drop = drop;
            if(SettedDrop != null)
            {
                SettedDrop(this, new SetDropEventArgs(No, drop));
            }
        }
        Random rand = new Random();
        public bool Coating()
        {
            if (nowp == 0)
            {
                if(EndedPR != null)
                {
                    EndedPR(this, new EndPREventArgs(No));
                }
                if (PCnt == 0)
                {
                    return false;
                }
                nowp = 1000;
                PCnt--;
            }
            if (nwafer == null)
            {
                if (bwafers.Count == 0)
                {
                    return false;
                }
                nwafer = bwafers[0];
                bwafers.RemoveAt(0);
            }
            nwafer.Coating(rand.Next(70, 100));
            nowp--;
            if (nwafer.Increment() == false)
            {
                awafers.Add(nwafer);
                nwafer = null;
                if(EndedCoating != null)
                {
                    EndedCoating(this, new EndCoatingEventArgs(No, BWCnt, AWCnt));
                }
            }
            return true;
        }
        public override string ToString()
        {
            return string.Format("WaferLine No:{0}", No);
        }

        public IEnumerator<Wafer> GetEnumerator()
        {
            return awafers.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return awafers.GetEnumerator();
        }
    }
}

3. AddPREventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void AddPREventHandler(object sender, AddPREventArgs e);
    public class AddPREventArgs:EventArgs
    {
        public int No { get; }
        public int PCnt { get; }
        public AddPREventArgs(int no,int pcnt)
        {
            No = no;
            PCnt = pcnt;
        }
    }
}

4. AddWaferEventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void AddWaferEventHandler(object sender, AddWaferEventArgs e);
    public class AddWaferEventArgs:EventArgs
    {
        public int No { get; }
        public int BWCnt
        { get; }
        public AddWaferEventArgs(int no, int bwcnt)
        {
            No = no;
            BWCnt = bwcnt;
        }
    }
}

5. EndCoatingEventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void EndCoatingEventHandler(object sender, EndCoatingEventArgs e);
    public class EndCoatingEventArgs:EventArgs
    {
        public int No { get; }
        public int BWCnt { get; }
        public int AWCnt { get; }
        public EndCoatingEventArgs(int no, int bwcnt,int awcnt)
        {
            No = no;
            BWCnt = bwcnt;
            AWCnt = awcnt;
        }
    }
}

6. EndPREventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void EndPREventHandler(object sender, EndPREventArgs e);
    public class EndPREventArgs:EventArgs
    {
        public int No { get; }
        public EndPREventArgs(int no)
        {
            No = no;
        }
    }
}

7. SetDropEventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void SetDropEventHandler(object sender, SetDropEventArgs e);
    public class SetDropEventArgs:EventArgs
    {
        public int No { get; }
        public int Drop { get; }
        public SetDropEventArgs(int no, int drop)
        {
            No = no;
            Drop = drop;
        }
    }
}

8. SetSpeedEventArgs.cs

using System;

namespace WaferLineLib
{
    public delegate void SetSpeedEventHandler(object sender, SetSpeedEventArgs e);
    public class SetSpeedEventArgs:EventArgs
    {
        public int No { get; }
        public int Speed { get; }
        public SetSpeedEventArgs(int no,int speed)
        {
            No = no;
            Speed = speed;
        }
    }
}
반응형