using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using SmartX;
using ITC81DB_2.DialogForms;
using InModbus;
using System.Net.Sockets;
using ITC81DB_2.Datastore;

namespace ITC81DB_2.Forms
{
    public partial class FormMain : Form
    {
        #region Field
        private SmartSplash SmartSplashProgramLoad;
        public bool IsCommunicationLogOpen;
        private int CommunicationCheckCount;
        public bool IsBootingComplete;
        public int BufferSmartUart;
        public bool IsJudgmentNow1;
        public bool IsJudgmentNow2;
        public int UpdateValue; // Modbus - Update 될 때마다 +1
        public bool IsOPCModbusUsing;
        public bool IsAlarmOccured;

        private static int ModbusTotalBytes = 100; // 전체 bytes

        // Ethernet
        private bool IsEthernetThreadStop;
        private bool IsEthernetTransferData;
        private bool IsUDPThreadStop = true;

        public object EthernetTransferData;

        private TcpClient EthernetTcpClient;

        private NetworkStream EthernetNetStream;
        private StreamReader EthernetStmReader;
        private StreamWriter EthernetStmWriter;

        // 로그온 색상
        public Color ColorLogOff;
        public Color ColorLogOn;

        // 파일 위치
        private string m_PathLaunchFolder;              // 프로그램 실행 폴더
        private string m_PathDataBackupFolder;          // 데이터 백업 폴더
        private string m_PathSystemFileFolder1;         // 시스템 파일 폴더1
        private string m_PathSystemFileFolder2;         // 시스템 파일 폴더2
        private string m_PathSystemFileBackupFolder;        // 시스템 파일 백업 폴더

        // 통신설정 - 전송 지연시간
        public Queue<object> QueueCOM1;
        public Queue<object> QueueCOM3;
        public Queue<object> QueueCOM4;
        public Queue<object> QueueEthernet;

        // Bacode
        public Barcode CurrentBarcode;
        // Modbus
        public Modbus Modbus;
        // Modbus Data
        public _30000_ModbusData Current30000ModbusData1;
        public _30000_ModbusData Current30000ModbusData2;
        public _40000_ModbusData Current40000ModbusData1;
        public _40000_ModbusData Current40000ModbusData2;

        // 시스템 상태
        private SystemStatus m_CurrentSystemStatus;

        // System Configuration
        public SystemConfigurationItem SystemConfig;
        // #1 현재 선택 된 품목
        public ProductItem CurrentProductItem1;
        // #2 현재 선택 된 품목
        public ProductItem CurrentProductItem2;
        // #1 JudgmentSet
        public JudgmentSetItem CurrentJudgmentSetItem1;
        // #2 JudgmentSet
        public JudgmentSetItem CurrentJudgmentSetItem2;
        // 중량 조정 설정값
        public CalibrationItem CurrentCalibrationItem;
        // #1 중량 데이터
        public WeightData CurrentWeightData1;
        // #2 중량 데이터
        public WeightData CurrentWeightData2;
        // 현재 피드백 값
        public FeedbackItem CurrentFeedbackItem1;
        // 현재 피드백 값
        public FeedbackItem CurrentFeedbackItem2;
        // 시스템파라미터 - 9507
        public SystemParameter9507 CurrentSystemParameter9507;
        // 시스템파라미터 - 9508
        public SystemParameter9508 CurrentSystemParameter9508;
        // 시스템파라미터 - 9509
        public SystemParameter9509 CurrentSystemParameter9509;
        // 시스템파라미터 - 9510
        public SystemParameter9510 CurrentSystemParameter9510;
        // 시스템파라미터 - 9511
        public SystemParameter9511 CurrentSystemParameter9511;

        // 시스템파라미터3 : 외부출력
        public SystemParameter3 CurrentSystemParameter3;

        // Form
        public FormMainDisplay ChildFormMainDisplay;
        public FormMenu ChildFormMenu;

        // IO Test Input 데이터 취합
        private Collection<string> CollectionIOTest_InputData;
        // 판정설정 그래프 데이터
        private Collection<int> CollectionGraphData;      
        
        // User
        public User CurrentUser;
        // UserGroup
        public UserGroup CurrentUserGroup;

        // 알람
        private AlarmList CurrentAlarmList;
        public List<short> CurrentAlarm;

        private delegate void TextStatusCallback(string strText);
        private delegate void UIServerStatusCallback(bool bEnable);

        private delegate void TransferByteArrayDataCallback(byte[] byteArray);
        private delegate void TransferStringDataCallback(string strText);
        private delegate void TransferByteDataCallback(byte byteText);
        private delegate void UIControlCallback(bool bEnable);
        private delegate void UITimerWorkCallback(bool bEnable);
        private delegate void TimerTryConnectCallback(bool bEnable);
        private delegate void UIOPT5QueueCountCallback(int count);
        #endregion

        #region Constructor
        public FormMain()
        {
            InitializeComponent();

            // 프로그램 로딩 이미지
            this.SmartSplashProgramLoad = new SmartX.SmartSplash();
            this.SmartSplashProgramLoad.CenterPosition = true;
            this.SmartSplashProgramLoad.AnimationInterval = 100;
            this.SmartSplashProgramLoad.LoadingImagePathname = "SmartLoading3";
            this.SmartSplashProgramLoad.Start();
        } 
        #endregion

        #region Property
        public string PathLaunchFolder
        {
            get { return this.m_PathLaunchFolder; }
            set { this.m_PathLaunchFolder = value; }
        }
        public string PathDataBackupFolder
        {
            get { return this.m_PathDataBackupFolder; }
            set { this.m_PathDataBackupFolder = value; }
        }
        public string PathSystemFileFolder1
        {
            get { return this.m_PathSystemFileFolder1; }
            set { this.m_PathSystemFileFolder1 = value; }
        }
        public string PathSystemFileFolder2
        {
            get { return this.m_PathSystemFileFolder2; }
            set { this.m_PathSystemFileFolder2 = value; }
        }
        public string PathSystemFileBackupFolder
        {
            get { return m_PathSystemFileBackupFolder; }
            set { m_PathSystemFileBackupFolder = value; }
        } 

        public SystemStatus CurrentSystemStatus
        {
            get { return this.m_CurrentSystemStatus; }
            private set { this.m_CurrentSystemStatus = value; }
        } 
        #endregion

        #region Method
        private void DefaultSetting()
        {
            this.IsCommunicationLogOpen = false;
            this.CommunicationCheckCount = 0;
            this.IsBootingComplete = false;
            this.BufferSmartUart = 1000000;
            this.IsJudgmentNow1 = false;
            this.IsJudgmentNow2 = false;
            this.UpdateValue = 0;
            this.IsOPCModbusUsing = false;
            this.EthernetTransferData = "";

            this.CurrentAlarmList = new AlarmList();
            this.CurrentAlarm = new List<short>();
            this.CurrentAlarmList.EventAlarmStateChange += new Define.EventHandlerAlarmStateChange(this.CurrentAlarmList_Change);

            this.Modbus = new Modbus();
            this.Current30000ModbusData1 = new _30000_ModbusData();
            this.Current40000ModbusData1 = new _40000_ModbusData();

            this.ColorLogOff = Color.Red;
            this.ColorLogOn = Color.Lime;

            this.PathLaunchFolder = "SD Card\\";
            this.PathSystemFileFolder1 = this.PathLaunchFolder + "SystemFile1\\";
            this.PathSystemFileFolder2 = this.PathLaunchFolder + "SystemFile2\\";
            this.PathDataBackupFolder = this.PathLaunchFolder + "DataBackup\\";
            this.PathSystemFileBackupFolder = this.PathLaunchFolder + "SystemFileBackup\\";

            this.CollectionIOTest_InputData = new Collection<string>();
            this.CollectionIOTest_InputData.Clear();
            for (int i = 0; i < 8; i++)
                this.CollectionIOTest_InputData.Add("0");

            this.CollectionGraphData = new Collection<int>();
            this.CollectionGraphData.Clear();
            for (int i = 0; i < 300; i++)
                this.CollectionGraphData.Add(0);

            this.QueueCOM1 = new Queue<object>();
            this.QueueCOM3 = new Queue<object>();
            this.QueueCOM4 = new Queue<object>();
            this.QueueEthernet = new Queue<object>();

            this.SystemConfig = new SystemConfigurationItem();
            this.CurrentProductItem1 = new ProductItem();
            this.CurrentProductItem2 = new ProductItem();
            this.CurrentJudgmentSetItem1 = new JudgmentSetItem();
            this.CurrentJudgmentSetItem2 = new JudgmentSetItem();
            this.CurrentCalibrationItem = new CalibrationItem();
            this.CurrentWeightData1 = new WeightData();
            this.CurrentWeightData2 = new WeightData();
            this.CurrentSystemStatus = new SystemStatus();
            this.CurrentFeedbackItem1 = new FeedbackItem();
            this.CurrentFeedbackItem2 = new FeedbackItem();
            this.CurrentSystemParameter9507 = new SystemParameter9507();
            this.CurrentSystemParameter9508 = new SystemParameter9508();
            this.CurrentSystemParameter9509 = new SystemParameter9509();
            this.CurrentSystemParameter9510 = new SystemParameter9510();
            this.CurrentSystemParameter9511 = new SystemParameter9511();
            this.CurrentUser = new User();
            this.CurrentUserGroup = new UserGroup();

            this.CurrentSystemParameter3 = new SystemParameter3();

            // SystemFile1 폴더 생성
            if (Directory.Exists(this.PathSystemFileFolder1) == false)
                Directory.CreateDirectory(this.PathSystemFileFolder1);

            // SystemFile2 폴더 생성
            if (Directory.Exists(this.PathSystemFileFolder2) == false)
                Directory.CreateDirectory(this.PathSystemFileFolder2);

            // DataBackup 폴더 생성
            if (Directory.Exists(this.PathDataBackupFolder) == false)
                Directory.CreateDirectory(this.PathDataBackupFolder);
        }
        private void DefaultSetting2()
        {
            // 이더넷
            if (this.SystemConfig.EthernetOperationMode == 1)
            {
                try
                {
                    if (string.Compare(this.smartConfigs.IPSettings.DeviceIP, "0.0.0.0") != 0)
                        this.EthernetServerStart();

                    this.ChildFormMainDisplay.TimerServer(true);
                }
                catch
                {

                }
            }
            else if (this.SystemConfig.EthernetOperationMode == 2)
            {
                this.EthernetClientDisconnect();
            }

            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : this.SystemConfig.EthernetCommMode", DateTime.Now, this.SystemConfig.EthernetCommMode));

            if (this.SystemConfig.EthernetCommMode != (int)Define.E_CommMode.f0_None)
            {
                switch (this.SystemConfig.EthernetCommMode)
                {
                    case (int)Define.E_CommMode.f99_Modbus:
                        this.ChildFormMainDisplay.MainBottomModbusIconAdd(true);
                        break;
                    default:
                        break;
                }
            }
            this.ChildFormMainDisplay.InitialEthernetIcon();
        }

        private void CreateForm()
        {
            this.ChildFormMainDisplay = new FormMainDisplay(this);
            this.ChildFormMenu = new FormMenu(this);

            this.smartForm.MainForm = this;

            this.smartForm.AddChildForm(this.ChildFormMainDisplay);
            this.smartForm.AddChildForm(this.ChildFormMenu);
        }

        public static void Exception(Exception ex)
        {
            try
            {
                string fileName = "SD Card\\Data\\Others\\Log\\" + string.Format("{0:yyyyMMdd_HHmmss}_Exception.txt", DateTime.Now);
                FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                sw.Write(ex.ToString());

                sw.Close();
                fs.Close();
            }
            catch
            {
                string fileName = "Flash Disk\\" + string.Format("{0:yyyyMMdd_HHmmss}_Exception.txt", DateTime.Now);
                FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                sw.Write(ex.ToString());

                sw.Close();
                fs.Close();
            }
        }

        public void TransferProductParameter1(int productNumber)
        {
            string value = "";

            StringBuilder sb = new StringBuilder();
            ProductItem pItem = new ProductItem();
            JudgmentSetItem jItem = new JudgmentSetItem();
            SystemParameter3 sItem = new SystemParameter3();

            this.LoadProductFile1(ref pItem, productNumber - 1);
            this.LoadJudgmentSetFile1(ref jItem, productNumber - 1);
            this.LoadSystemParameter3File(ref sItem);

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));                          // 하한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.PassRange));                           // 기준값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));                           // 상한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));                           // 용기(7)
            value = Helper.DoubleToString(jItem.DynamicCorrection, 6);
            value = value.Replace(".", "");
            sb.Append(Helper.StringZeroFillDigits7(value));                                             // 동보정(7)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Filter.ToString()));                          // 필터(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentDelayTime.ToString()));        // 판정지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DoubleDelayTime.ToString()));          // 이중지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentCount.ToString()));            // 판정개수(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AscendDelayTime.ToString()));            // 상승지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DescendDelayTime.ToString()));          // 하강지연(4)                    
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed1.ToString()));               // 인버터1속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed2.ToString()));               // 인버터2속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed3.ToString()));               // 인버터3속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgmentLength.ToString()));       // 자동판정-길이(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment1.ToString()));            // 자동판정-1(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment2.ToString()));            // 자동판정-2(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment3.ToString()));            // 자동판정-3(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1Mode.ToString()));              // 선별기1모드(4)    
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1DelayTime.ToString()));         // 선별기1지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1RunTime.ToString()));           // 선별기1동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut9Mode));              // 외부출력9모드(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut9DelayTime));         // 외부출력9지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut9RunTime));           // 외부출력9동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.EquipmentID.ToString()));  // 장비ID(4)
            sb.Append("0000000");                                                                  // Dummy1(7)
            sb.Append("0000000");                                                                  // Dummy2(7)
            sb.Append("0000");                                                                  // Dummy3(4)
            sb.Append("0000");                                                                  // Dummy4(4)
            sb.Append("0000");                                                                  // Dummy5(4)
            sb.Append(Helper.StringZeroFillDigits4(pItem.Number.ToString()));                   // 품번(4)

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9045_SystemParameterWrite, sb.ToString());
        }
        public void TransferProductParameter2(int productNumber)
        {
            string value = "";

            StringBuilder sb = new StringBuilder();
            ProductItem pItem = new ProductItem();
            JudgmentSetItem jItem = new JudgmentSetItem();
            SystemParameter3 sItem = new SystemParameter3();

            this.LoadProductFile2(ref pItem, productNumber - 1);
            this.LoadJudgmentSetFile2(ref jItem, productNumber - 1);
            this.LoadSystemParameter3File(ref sItem);

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));                          // 하한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.PassRange));                           // 기준값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));                           // 상한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));                           // 용기(7)
            value = Helper.DoubleToString(jItem.DynamicCorrection, 6);
            value = value.Replace(".", "");
            sb.Append(Helper.StringZeroFillDigits7(value));                                             // 동보정(7)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Filter.ToString()));                          // 필터(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentDelayTime.ToString()));        // 판정지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DoubleDelayTime.ToString()));          // 이중지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentCount.ToString()));            // 판정개수(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AscendDelayTime.ToString()));            // 상승지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DescendDelayTime.ToString()));          // 하강지연(4)                    
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed1.ToString()));               // 인버터1속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed2.ToString()));               // 인버터2속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed3.ToString()));               // 인버터3속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgmentLength.ToString()));       // 자동판정-길이(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment1.ToString()));            // 자동판정-1(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment2.ToString()));            // 자동판정-2(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment3.ToString()));            // 자동판정-3(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1Mode.ToString()));              // 선별기2모드(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1DelayTime.ToString()));         // 선별기2지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1RunTime.ToString()));           // 선별기2동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut10Mode));              // 외부출력10모드(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut10DelayTime));         // 외부출력10지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(sItem.ExternalOut10RunTime));           // 외부출력10동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.EquipmentID.ToString()));  // 장비ID(4)
            sb.Append("0000000");                                                                  // Dummy1(7)
            sb.Append("0000000");                                                                  // Dummy2(7)
            sb.Append("0000");                                                                  // Dummy3(4)
            sb.Append("0000");                                                                  // Dummy4(4)
            sb.Append("0000");                                                                  // Dummy5(4)
            sb.Append(Helper.StringZeroFillDigits4(pItem.Number.ToString()));                   // 품번(4)

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9046_SystemParameterWrite, sb.ToString());
        }
        public void TransferCurrentProductItem1(ProductItem pItem)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.PassRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.ProductNumber.ToString()));

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoard1, CommunicationAddress._9024_ParameterWeightSetting, sb.ToString());
        }
        public void TransferCurrentProductItem2(ProductItem pItem)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.PassRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.ProductNumber.ToString()));

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoard2, CommunicationAddress._9024_ParameterWeightSetting, sb.ToString());
        }

        private void ConverterAlarm(ref WeightData data, string alarm, int laneNum)
        {
            string sValue1 = "", sValue2 = "", sValue3 = "";

            if (alarm.Length != 3)
                return;

            sValue1 = Convert.ToString(Convert.ToInt16(alarm.Substring(0, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue2 = Convert.ToString(Convert.ToInt16(alarm.Substring(1, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue3 = Convert.ToString(Convert.ToInt16(alarm.Substring(2, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');

            // 알람 12-외부에러
            if (sValue3[0] == '0')
            { }
            else
            { }
            // 알람 11-진입센서걸림(센서에러감지시간)
            if (sValue3[1] == '0')
                data.IsEntryStucked = false;
            else
            {
                data.IsEntryStucked = true;
                if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                {
                    this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                    this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                }
            }
            // 알람 10-
            if (sValue3[2] == '0')
            { }
            else
            { }
            // 알람 9-인버터에러
            if (sValue3[3] == '0')
            { }
            else
            { }
            // 알람 8-제품진입 미감지
            if (sValue2[0] == '0')
                data.IsEntryNotDetected = false;
            else
            {
                if (laneNum == 1)
                {
                    if (this.IsJudgmentNow1 == false)
                    {
                        data.IsEntryNotDetected = true;
                        if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                        {
                            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                        }
                    }
                }
                else
                {
                    if (this.IsJudgmentNow2 == false)
                    {
                        data.IsEntryNotDetected = true;
                        if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                        {
                            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                        }
                    }
                }
            }
            // 알람 7-리젝터 동작 감지
            if (sValue2[1] == '0')
            { }
            else
            { }
            // 알람 6-적체센서 에러
            if (sValue2[2] == '0')
            { }
            else
            { }
            // 알람 5-공압에러
            if (sValue2[3] == '0')
            { }
            else
            { }

            // 알람 4-Emergency
            if (sValue1[0] == '0')
                data.IsEmergencyStop = false;
            else
                data.IsEmergencyStop = true;
            // 알람 3-도어인터록
            if (sValue1[1] == '0')
            { }
            else
            { }
            // 알람 2-셀 에러
            if (sValue1[2] == '0')
                data.IsLoadCellError = false;
            else
                data.IsLoadCellError = true;

            // 알람 1-입력센서 에러
            if (sValue1[3] == '0')
                data.IsEntrySensorError = false;
            else
                data.IsEntrySensorError = true;
        }

        /// <summary>
        /// Set Mode
        /// </summary>
        /// <param name="mode"></param>
        public void SetDisplayMode(Define.E_DisplayMode mode)
        {
            if (this.CurrentSystemStatus.CurrentMode == mode)
                return;
            else
                this.CurrentSystemStatus.CurrentMode = mode;

            switch (mode)
            {
                case Define.E_DisplayMode.Normal:
                    this.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.Menu:
                    this.TransferData(CommunicationCommand.ModeMenu, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.Calibration:
                    this.TransferData(CommunicationCommand.ModeCalibration, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.SystemSetting:
                    this.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.IOTest:
                    this.TransferData(CommunicationCommand.ModeIOTest, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.Bypass:
                    this.TransferData(CommunicationCommand.ModeBypass, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.EquipmentTest:
                    this.TransferData(CommunicationCommand.ModeEquipmentTest, CommunicationID.MainBoard);
                    break;
                case Define.E_DisplayMode.SorterTest:
                    this.TransferData(CommunicationCommand.ModeRejectorTest, CommunicationID.MainBoard);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// Set User
        /// </summary>
        /// <param name="user"></param>
        public void SetUser(Define.E_UserGroup user)
        {
            if (this.CurrentSystemStatus.CurrentUserPasswordType.Group != user)
                this.CurrentSystemStatus.CurrentUserPasswordType.Group = user;
        }

        public void PrintingHeadLine()
        {
            if (this.SystemConfig.SerialCOM1Mode == 3)
            {
                this.TransferSerialCOM1("\n--------------------------------");
                this.TransferSerialCOM1(" NO LANE GRADE WEIGHT    COUNT");
                this.TransferSerialCOM1("\n--------------------------------");
            }

            if (this.SystemConfig.SerialCOM3Mode == 3)
            {
                this.TransferSerialCOM3("\n--------------------------------");
                this.TransferSerialCOM3(" NO LANE GRADE WEIGHT    COUNT");
                this.TransferSerialCOM3("\n--------------------------------");
            }
        }
        public void PrintingWeight(WeightData data1, WeightData data2, ProductItem pItem1, ProductItem pItem2)
        {
            string value = "";

            if (this.SystemConfig.SerialCOM1Mode == 3)
            {
                this.TransferSerialCOM1("\n################################");
                this.TransferSerialCOM1("\n       TOTAL  PRINT  LANE 1 ");
                this.TransferSerialCOM1("\n################################");
                this.TransferSerialCOM1(string.Format("\nPART       = {0}", pItem1.Number));
                this.TransferSerialCOM1(string.Format("\nSTART      = {0}", data1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM1(string.Format("\nEND        = {0}", data1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM1(string.Format("\n\nUNDER      = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem1.UnderRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data1.UnderCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data1.UnderSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.UnderAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data1.UnderRatio));

                this.TransferSerialCOM1(string.Format("\n\nPASS       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem1.PassRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data1.PassCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data1.PassSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.PassAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data1.PassRatio));

                this.TransferSerialCOM1(string.Format("\n\nOVER       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem1.OverRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data1.OverCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data1.OverSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.OverAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data1.OverRatio));

                this.TransferSerialCOM1(string.Format("\n\nTARE       = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem1.TareRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM1(string.Format("\n\nFAULTY(WEIGHT NG : Over+Under)"));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data1.TotalUnderOverCount));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.NGAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM1(string.Format("\n\nOTHER FAULTY(ExNG)"));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data1.ExNGCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data1.ExNGSumWeightKG));

                this.TransferSerialCOM1(string.Format("\n\nTOTAL.COUNT = {0}", data1.TotalCount));
                this.TransferSerialCOM1(string.Format("\nTOTAL.WT    = {0}kg", data1.TotalSumWeightKG));

                this.TransferSerialCOM1("\n################################\n\n\n\n");

                //////////////////////////////////////////////////////////////////////////////////

                this.TransferSerialCOM1("\n################################");
                this.TransferSerialCOM1("\n       TOTAL  PRINT  LANE 2 ");
                this.TransferSerialCOM1("\n################################");
                this.TransferSerialCOM1(string.Format("\nPART       = {0}", pItem2.Number));
                this.TransferSerialCOM1(string.Format("\nSTART      = {0}", data2.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM1(string.Format("\nEND        = {0}", data2.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM1(string.Format("\n\nUNDER      = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem2.UnderRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data2.UnderCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data2.UnderSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.UnderAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data2.UnderRatio));

                this.TransferSerialCOM1(string.Format("\n\nPASS       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem2.PassRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data2.PassCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data2.PassSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.PassAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data2.PassRatio));

                this.TransferSerialCOM1(string.Format("\n\nOVER       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem2.OverRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data2.OverCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data2.OverSumWeightKG));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.OverAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM1(string.Format("\n RATIO     = {0}%", data2.OverRatio));

                this.TransferSerialCOM1(string.Format("\n\nTARE       = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem2.TareRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM1(string.Format("\n\nFAULTY(WEIGHT NG : Over+Under)"));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data2.TotalUnderOverCount));
                this.TransferSerialCOM1(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.NGAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM1(string.Format("\n\nOTHER FAULTY(ExNG)"));
                this.TransferSerialCOM1(string.Format("\n COUNT     = {0}", data2.ExNGCount));
                this.TransferSerialCOM1(string.Format("\n TOTAL.WT  = {0}kg", data2.ExNGSumWeightKG));

                this.TransferSerialCOM1(string.Format("\n\nTOTAL.COUNT = {0}", data2.TotalCount));
                this.TransferSerialCOM1(string.Format("\nTOTAL.WT    = {0}kg", data2.TotalSumWeightKG));

                this.TransferSerialCOM1("\n################################\n\n\n\n");
            }

            if (this.SystemConfig.SerialCOM3Mode == 3)
            {
                this.TransferSerialCOM3("\n################################");
                this.TransferSerialCOM3("\n       TOTAL  PRINT  LANE 1 ");
                this.TransferSerialCOM3("\n################################");
                this.TransferSerialCOM3(string.Format("\nPART       = {0}", pItem1.Number));
                this.TransferSerialCOM3(string.Format("\nSTART      = {0}", data1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM3(string.Format("\nEND        = {0}", data1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM3(string.Format("\n\nUNDER      = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem1.UnderRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data1.UnderCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data1.UnderSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.UnderAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data1.UnderRatio));

                this.TransferSerialCOM3(string.Format("\n\nPASS       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem1.PassRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data1.PassCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data1.PassSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.PassAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data1.PassRatio));

                this.TransferSerialCOM3(string.Format("\n\nOVER       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem1.OverRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data1.OverCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data1.OverSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.OverAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data1.OverRatio));

                this.TransferSerialCOM3(string.Format("\n\nTARE       = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem1.TareRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM3(string.Format("\n\nFAULTY(WEIGHT NG : Over+Under)"));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data1.TotalUnderOverCount));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data1.NGAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM3(string.Format("\n\nOTHER FAULTY(ExNG)"));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data1.ExNGCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}kg", data1.ExNGSumWeightKG));

                this.TransferSerialCOM3(string.Format("\n\nTOTAL.COUNT = {0}", data1.TotalCount));
                this.TransferSerialCOM3(string.Format("\nTOTAL.WT    = {0}kg", data1.TotalSumWeightKG));

                this.TransferSerialCOM3("\n################################\n\n\n\n");

                //////////////////////////////////////////////////////////////////////////////////

                this.TransferSerialCOM3("\n################################");
                this.TransferSerialCOM3("\n       TOTAL  PRINT  LANE 2 ");
                this.TransferSerialCOM3("\n################################");
                this.TransferSerialCOM3(string.Format("\nPART       = {0}", pItem2.Number));
                this.TransferSerialCOM3(string.Format("\nSTART      = {0}", data2.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM3(string.Format("\nEND        = {0}", data2.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM3(string.Format("\n\nUNDER      = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem2.UnderRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data2.UnderCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data2.UnderSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.UnderAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data2.UnderRatio));

                this.TransferSerialCOM3(string.Format("\n\nPASS       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem2.PassRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data2.PassCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data2.PassSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.PassAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data2.PassRatio));

                this.TransferSerialCOM3(string.Format("\n\nOVER       = {0}{1}",
                  Helper.StringToDecimalPlaces(pItem2.OverRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data2.OverCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}oz", data2.OverSumWeight));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.OverAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));
                this.TransferSerialCOM3(string.Format("\n RATIO     = {0}%", data2.OverRatio));

                this.TransferSerialCOM3(string.Format("\n\nTARE       = {0}{1}",
                    Helper.StringToDecimalPlaces(pItem2.TareRange, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM3(string.Format("\n\nFAULTY(WEIGHT NG : Over+Under)"));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data2.TotalUnderOverCount));
                this.TransferSerialCOM3(string.Format("\n MEAN      = {0}{1}",
                    Helper.DoubleToString(data2.NGAverage, this.SystemConfig.DecimalPlaces), this.SystemConfig.Unit));

                this.TransferSerialCOM3(string.Format("\n\nOTHER FAULTY(ExNG)"));
                this.TransferSerialCOM3(string.Format("\n COUNT     = {0}", data2.ExNGCount));
                this.TransferSerialCOM3(string.Format("\n TOTAL.WT  = {0}kg", data2.ExNGSumWeightKG));

                this.TransferSerialCOM3(string.Format("\n\nTOTAL.COUNT = {0}", data2.TotalCount));
                this.TransferSerialCOM3(string.Format("\nTOTAL.WT    = {0}kg", data2.TotalSumWeightKG));

                this.TransferSerialCOM3("\n################################\n\n\n\n");
            }
        }

        public void TimerSensorErrorInterval()
        {
            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            this.timerSensorError1.Interval = this.SystemConfig.SensorErrorDetectingTime;
            
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;
            this.timerSensorError2.Interval = this.SystemConfig.SensorErrorDetectingTime;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("timerSensorError Interval ({0:yyyy-MM-dd HH:mm:ss}): timer1:{1}, timer2:{2}", DateTime.Now, 
                    this.timerSensorError1.Interval, this.timerSensorError2.Interval));
        }
        public void TimerEntryNotDetectedIgnoreTimeInverval()
        {
            this.timerEntryNotDetectedIgnoreTime1.Interval = this.SystemConfig.EntryNotDetectedIgnoreTime;
            this.timerEntryNotDetectedIgnoreTime2.Interval = this.SystemConfig.EntryNotDetectedIgnoreTime;
        }

        // 피드백 데이터(피드백 편차 변경 X)
        public void UpdateFeedbackData1(ProductItem item, SystemParameter9508 parameter)
        {
            if (this.ChildFormMainDisplay.MainFeedback.IsUsingFeedback() == true)
            {
                int temp = 0;
                string feedbackValue = "";

                if (parameter.OPT1IsWeightSetting == "1")
                {
                    temp = item.PassRangeInt + this.CurrentFeedbackItem1.OverRangeDeviationInt;
                    if (temp <= 0)
                    {
                        parameter.OPT1OverRange1 = "0";
                        this.UpdateFeedbackDeviation1(this.CurrentProductItem1, this.CurrentSystemParameter9508);
                    }
                    else
                        parameter.OPT1OverRange1 = (item.PassRangeInt + this.CurrentFeedbackItem1.OverRangeDeviationInt).ToString();

                    temp = item.PassRangeInt + this.CurrentFeedbackItem1.UnderRangeDeviationInt;
                    if (temp <= 0)
                    {
                        parameter.OPT1UnderRange1 = "0";
                        this.UpdateFeedbackDeviation1(this.CurrentProductItem1, this.CurrentSystemParameter9508);
                    }
                    else
                        parameter.OPT1UnderRange1 = (item.PassRangeInt + this.CurrentFeedbackItem1.UnderRangeDeviationInt).ToString();
                }
                else
                {
                    parameter.OPT1OverRange1 = item.OverRange;
                    parameter.OPT1UnderRange1 = item.UnderRange;
                }

                if (parameter.OPT1OverRange1Int < item.PassRangeInt)
                    parameter.OPT1OverRange1 = item.PassRange;

                feedbackValue = Helper.StringZeroFillDigits7(parameter.OPT1OverRange1);
                this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6205_OPT1OverRange1, feedbackValue);
                feedbackValue = Helper.StringZeroFillDigits7(parameter.OPT1UnderRange1);
                this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6206_OPT1UnderRange1, feedbackValue);
            }

            this.ChildFormMainDisplay.MainFeedback.DisplayRefresh(this.CurrentSystemStatus);
        }
        public void UpdateFeedbackData2(ProductItem item, SystemParameter9508 parameter)
        {
            if (this.ChildFormMainDisplay.MainFeedback.IsUsingFeedback() == true)
            {
                int temp = 0;
                string feedbackValue = "";

                if (parameter.OPT1IsWeightSetting == "1")
                {
                    temp = item.PassRangeInt + this.CurrentFeedbackItem2.OverRangeDeviationInt;
                    if (temp <= 0)
                    {
                        parameter.OPT1OverRange2 = "0";
                        this.UpdateFeedbackDeviation2(this.CurrentProductItem2, this.CurrentSystemParameter9508);
                    }
                    else
                        parameter.OPT1OverRange2 = (item.PassRangeInt + this.CurrentFeedbackItem2.OverRangeDeviationInt).ToString();

                    temp = item.PassRangeInt + this.CurrentFeedbackItem2.UnderRangeDeviationInt;
                    if (temp <= 0)
                    {
                        parameter.OPT1UnderRange2 = "0";
                        this.UpdateFeedbackDeviation2(this.CurrentProductItem2, this.CurrentSystemParameter9508);
                    }
                    else
                        parameter.OPT1UnderRange2 = (item.PassRangeInt + this.CurrentFeedbackItem2.UnderRangeDeviationInt).ToString();
                }
                else
                {
                    parameter.OPT1OverRange2 = item.OverRange;
                    parameter.OPT1UnderRange2 = item.UnderRange;
                }

                if (parameter.OPT1OverRange2Int < item.PassRangeInt)
                    parameter.OPT1OverRange2 = item.PassRange;

                feedbackValue = Helper.StringZeroFillDigits7(parameter.OPT1OverRange2);
                this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6216_OPT1OverRange2, feedbackValue);
                feedbackValue = Helper.StringZeroFillDigits7(parameter.OPT1UnderRange2);
                this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6217_OPT1UnderRange2, feedbackValue);
            }

            this.ChildFormMainDisplay.MainFeedback.DisplayRefresh(this.CurrentSystemStatus);
        }
        public void UpdateFeedbackDeviation1(ProductItem item, SystemParameter9508 parameter)
        {
            string sValue = "";

            sValue = this.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(parameter.OPT1OverRange1Int);
            this.CurrentFeedbackItem1.OverRangeDeviation = sValue;

            sValue = this.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(parameter.OPT1UnderRange1Int);
            this.CurrentFeedbackItem1.UnderRangeDeviation = sValue;

            this.ChildFormMainDisplay.MainFeedback.DisplayRefresh(this.CurrentSystemStatus);
        }
        public void UpdateFeedbackDeviation2(ProductItem item, SystemParameter9508 parameter)
        {
            string sValue = "";

            sValue = this.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(parameter.OPT1OverRange2Int);
            this.CurrentFeedbackItem2.OverRangeDeviation = sValue;

            sValue = this.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(parameter.OPT1UnderRange2Int);
            this.CurrentFeedbackItem2.UnderRangeDeviation = sValue;

            this.ChildFormMainDisplay.MainFeedback.DisplayRefresh(this.CurrentSystemStatus);
        }

        private void UpdateScreen()
        {
            if (int.Parse(this.CurrentSystemParameter9507.OptionBoard) > 0)
            {
                this.ChildFormMainDisplay.CurrentBottomMenuControlEnable();
                this.ChildFormMainDisplay.UpdateIcomDisplay();

                this.ChildFormMenu.CenterConfiOptionBoard.InitializeDesign();

                this.ChildFormMenu.CenterConfiHelp.OptionBoardVisible();
                this.ChildFormMenu.BottomConfiguration.OptionBoardVisible();

                this.UpdateFeedbackData1(this.CurrentProductItem1, this.CurrentSystemParameter9508);
                this.UpdateFeedbackData2(this.CurrentProductItem2, this.CurrentSystemParameter9508);
                this.UpdateFeedbackDeviation1(this.CurrentProductItem1, this.CurrentSystemParameter9508);
                this.UpdateFeedbackDeviation2(this.CurrentProductItem2, this.CurrentSystemParameter9508);
            }
        }

        #region Uart Communication
        public void OpenSmartUartLink()
        {
            string fullPath = "";

            try
            {
                if (this.smartSerialPort2.IsOpen == false)
                    this.smartSerialPort2.Open();
            }
            catch
            {
            }

            #region Test 용 통신 로그
            fullPath = this.PathDataBackupFolder + "Communicationlog.txt";
            this.smartFileCommunicationLog.FilePathName = fullPath;
            //this.smartFileCommunicationLog.Open();
            //this.IsCommunicationLogOpen = true;
            #endregion
        }
        public void CloseSmartUartLink()
        {
            if (this.IsCommunicationLogOpen == true)
            {
                this.IsCommunicationLogOpen = false;
                this.smartFileCommunicationLog.Close();
            }
            this.smartSerialPort2.Close();
        }

        private bool SizeCheck(string cmd, string strTemp)
        {
            bool ret = false;
            string dataSize = "";
            int size = 0;

            if (strTemp == null || strTemp.Length == 0)
            {
                ret = false;
                return ret;
            }

            try
            {
                if (cmd == "P")
                    dataSize = strTemp.Substring(14, strTemp.Length - 16);
                else // "S"
                    dataSize = strTemp.Substring(10, strTemp.Length - 12);

                size = int.Parse(strTemp.Substring(6, 4).Trim());
            }
            catch
            {
                ret = false;
                return ret;
            }

            if (dataSize.Length == size)
                ret = true;
            else
                ret = false;

            return ret;
        }
        private bool ChksumCheck(string strTemp)
        {
            bool ret = false;
            string chkSum = "", dataChksum = "";

            if (strTemp == null || strTemp.Length == 0)
                ret = false;
            else
            {
                chkSum = strTemp.Substring(strTemp.Length - 2, 2);
                dataChksum = this.Checksumcalculator(strTemp.Substring(0, strTemp.Length - 2));

                if (chkSum == dataChksum)
                    ret = true;
                else
                    ret = false;
            }

            return ret;
        }
        private string Checksumcalculator(string strTemp)
        {
            string chkSum = "";
            byte[] temp;
            int value = 0, first = 0, second = 0;
            char char1, char2;

            if (strTemp == null || strTemp.Length == 0)
                chkSum = "cc";
            else
            {
                temp = new UTF8Encoding().GetBytes(strTemp);

                for (int i = 0; i < temp.Length; i++)
                    value += temp[i];

                first = (value & 0x00f0) >> 4;
                if (first > 9)
                    char1 = (char)(first + 0x37);
                else
                    char1 = (char)(first + 0x30);

                second = value & 0x000f;
                if (second > 9)
                    char2 = (char)(second + 0x37);
                else
                    char2 = (char)(second + 0x30);

                chkSum = char1.ToString() + char2.ToString();
            }

            return chkSum;
        }

        public int TransferData(string command, string id)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPort2.IsOpen == true)
                this.smartSerialPort2.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataCOM3(string command, string id)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPort3.IsOpen == true)
                this.smartSerialPort3.WriteNoneFrame((char)0x02 + sb.ToString() + (char)0x03, SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Send COM3({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataStream(string command, string id, string address, string data)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);
            sb.Append(Helper.StringZeroFillDigits4(data.Length.ToString()));
            sb.Append(address);
            sb.Append(data);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPort2.IsOpen == true)
                this.smartSerialPort2.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataToCOM3Stream(string command, string id, string address, string data)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);
            sb.Append(Helper.StringZeroFillDigits4(data.Length.ToString()));
            sb.Append(address);
            sb.Append(data);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPort3.IsOpen == true)
                this.smartSerialPort3.WriteNoneFrame((char)0x02 + sb.ToString() + (char)0x03, SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Send COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        private void ReceiveData()
        {
            int ret = 0;
            string strTemp = "";
            byte[] readByte;

            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPort2.ReadQueue(out readByte);
                strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
            {
                return;
            }

            try
            {
                switch (strTemp[0])
                {
                    case 'C':
                        if ((ret = this.ReceiveCommandC(strTemp)) != 0)
                            return;
                        break;
                    case 'P':
                        if ((ret = this.ReceiveCommandP(strTemp)) != 0)
                            return;
                        break;
                    case 'S':
                        if ((ret = this.ReceiveCommandS(strTemp)) != 0)
                            return;
                        break;
                    default:
                        break;
                }
            }
            catch
            {
            }
        }

        private int ReceiveCommandC(string strTemp)
        {
            int ret = 0;
            string cmd = "", lane = "";

            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Command Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            lane = strTemp.Substring(5, 1);

            switch (cmd)
            {
                case "CI0":
                    #region Main Board Booted
                    if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                    {
                        this.CurrentSystemStatus.Equipment = Define.E_EquipmentStatus.Stop;

                        // 생산속도 Clear
                        this.CurrentWeightData1.ProductionSpeed = 0;
                        this.CurrentWeightData2.ProductionSpeed = 0;
                        this.CurrentWeightData1.IsStart = false;
                        this.CurrentWeightData2.IsStart = false;

                        // 정지 시간 저장
                        this.CurrentWeightData1.StopTime = DateTime.Now;
                        this.CurrentWeightData2.StopTime = DateTime.Now;
                        this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);

                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    }
                    // Read SystemParameter1
                    this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9507_SystemParameterRead, ""); 
                    #endregion
                    break;
                case "CBI":
                    #region 공장초기화완료
                    this.ChildFormMenu.CenterEquipInitialize.UpdateDisplayMainBoardInitialization();
                    #endregion
                    break;
                case "CBS":
                    #region 운전
                    this.CurrentSystemStatus.Equipment = Define.E_EquipmentStatus.Start;

                    // 운전시 중량 0 으로 Clear
                    this.CurrentWeightData1.Weight = 0.0;
                    this.CurrentWeightData2.Weight = 0.0;

                    // 운전 시간 저장
                    if (this.CurrentWeightData1.TotalCount == 0 && this.CurrentWeightData2.TotalCount == 0)
                    {
                        this.CurrentWeightData1.StartTime = DateTime.Now;
                        this.CurrentWeightData2.StartTime = DateTime.Now;
                        this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);
                    }

                    // 운전 시, Pop up 창 자동 Close
                    this.ChildFormMainDisplay.PopUpWarningClose();

                    if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    else
                        this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);

                    if (this.ChildFormMainDisplay.MainFeedback.IsUsingFeedback() == true)
                        this.ChildFormMainDisplay.MainFeedback.ItemChangeEnable(false);
                    #endregion
                    break;
                case "CBT":
                    #region 정지
                    this.CurrentSystemStatus.Equipment = Define.E_EquipmentStatus.Stop;

                    // 생산속도 Clear
                    this.CurrentWeightData1.ProductionSpeed = 0;
                    this.CurrentWeightData2.ProductionSpeed = 0;
                    this.CurrentWeightData1.IsStart = false;
                    this.CurrentWeightData2.IsStart = false;

                    // 정지 시간 저장
                    this.CurrentWeightData1.StopTime = DateTime.Now;
                    this.CurrentWeightData2.StopTime = DateTime.Now;
                    this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                    this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);

                    if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    else
                        this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);

                    if (this.ChildFormMainDisplay.MainFeedback.IsUsingFeedback() == true)
                        this.ChildFormMainDisplay.MainFeedback.ItemChangeEnable(true);
                    #endregion
                    break;
                case "CBE":
                    #region 소거

                    #endregion
                    break;
                case "CBZ":
                    #region 영점

                    #endregion
                    break;
                case "CSa":
                    if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                    {
                        try
                        {
                            switch (lane)
                            {
                                case "A":
                                    // 센서에러 감지시간 설정 시
                                    if (this.SystemConfig.SensorErrorDetectingTime > 0)
                                        this.timerSensorError1.Enabled = true;
                                    break;
                                case "B":
                                    // 센서에러 감지시간 설정 시
                                    if (this.SystemConfig.SensorErrorDetectingTime > 0)
                                        this.timerSensorError2.Enabled = true;
                                    break;
                                default:
                                    break;
                            }
                        }
                        catch
                        {
                            ret = -1;
                        }
                    }
                    break;
                default:
                    break;
            }

            return ret;
        }
        private int ReceiveCommandP(string strTemp)
        {
            int ret = 0;
            string cmd = "", address = "", lane = "", receiveData = "";

            // SIZE 확인
            if (this.SizeCheck("P", strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
                return ret = -1;
            }
            // CHKSUM 확인
            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            lane = strTemp.Substring(5, 1);
            address = strTemp.Substring(10, 4);
            receiveData = strTemp.Substring(14, strTemp.Length - 16);

            switch (cmd)
            {
                case "PR0":
                    if ((ret = this.ReceiveCommandPR0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                case "PW0":
                    if ((ret = this.ReceiveCommandPW0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                case "PB0":
                    if ((ret = this.ReceiveCommandPB0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                default:
                    break;
            }

            return ret;
        }
        private int ReceiveCommandS(string strTemp)
        {
            int ret = 0;
            string cmd = "", lane = "", receiveData = "", transferCount = "";

            // SIZE 확인
            if (this.SizeCheck("S", strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
                return ret = -1;
            }
            // CHKSUM 확인
            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            transferCount = strTemp.Substring(3, 2);
            lane = strTemp.Substring(5, 1);
            receiveData = strTemp.Substring(10, strTemp.Length - 12);

            switch (cmd)
            {
                case "SN0":
                    if ((ret = this.ReceiveCommandSN0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SR0":
                    if ((ret = this.ReceiveCommandSR0(lane, transferCount, receiveData)) != 0)
                        return ret;
                    break;
                case "SC0":
                    if ((ret = this.ReceiveCommandSC0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "ST0":
                    if ((ret = this.ReceiveCommandST0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SF0":
                    if ((ret = this.ReceiveCommandSF0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SG0":
                    if ((ret = this.ReceiveCommandSG0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SB0":
                    if ((ret = this.ReceiveCommandSB0(lane, receiveData)) != 0)
                        return ret;
                    break;
                default:
                    break;
            }

            // ex
            #region ex
            //if (cmd == "SG0")
            //{
            //    byte[] a = new UTF8Encoding().GetBytes(strTemp.Substring(0, strTemp.Length - 2));
            //    int j = 0, first, second;
            //    char char1, char2;
            //    string value1 = "";
            //    for (int i = 0; i < a.Length; i++)
            //    {
            //        j += a[i];
            //    }

            //    first = (j & 0x00f0) >> 4;
            //    if (first > 9)
            //        char1 = (char)(first + 0x37);
            //    else
            //        char1 = (char)(first + 0x30);

            //    second = j & 0x000f;
            //    if (second > 9)
            //        char2 = (char)(second + 0x37);
            //    else
            //        char2 = (char)(second + 0x30);

            //    value1 = char1.ToString() + char2.ToString();
            //    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateChecksumDisplay(strTemp.Substring(strTemp.Length - 2, 2), value1);
            //}
            #endregion

            return ret;
        }

        // 파라미터 읽기 응답
        private int ReceiveCommandPR0(string lane, string address, string receiveData)
        {
            int ret = 0, iValue = 0;
            string sValue = "";

            try
            {
                switch (address)
                {
                    case "1501":
                        #region Value Assign
                        this.SystemConfig.MainBoardVersion = receiveData.Substring(0, 4);
                        #endregion
                        this.ChildFormMenu.CenterInforSystemInformation.UpdateMainBoardVersionDisplay(this.SystemConfig.MainBoardVersion);
                        break;
                    case "2001":
                        #region Value Assign
                        iValue = int.Parse(receiveData);
                        if (iValue <= 0 || iValue > 1000)
                            return ret = -1;
                        #endregion

                        this.SystemConfig.ProductNumber = iValue;
                        this.SaveSystemConfigurationFile1(this.SystemConfig);

                        // 최초에 부팅이 완료 되었는지 확인
                        if (this.IsBootingComplete == false)
                            this.IsBootingComplete = true;

                        this.LoadProductFile1(ref this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                        this.LoadProductFile2(ref this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);

                        this.LoadCounterFile1(ref this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.LoadCounterFile2(ref this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);

                        this.LoadJudgmentSetFile1(ref this.CurrentJudgmentSetItem1, this.SystemConfig.ProductNumber - 1);
                        this.LoadJudgmentSetFile2(ref this.CurrentJudgmentSetItem2, this.SystemConfig.ProductNumber - 1);

                        // 생산속도 Clear
                        this.CurrentWeightData1.ProductionSpeed = 0;
                        this.CurrentWeightData2.ProductionSpeed = 0;
                        this.CurrentWeightData1.IsStart = false;
                        this.CurrentWeightData2.IsStart = false;

                        this.UpdateScreen();

                        if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateCurrentProductDisplay(this.CurrentSystemStatus.Equipment,
                                this.CurrentProductItem1, this.CurrentProductItem2, this.CurrentWeightData1, this.CurrentWeightData2);
                        else if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.SystemJudgmentSetting)
                            this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateCurrentProductDisplay(this.CurrentSystemStatus.Equipment, this.CurrentProductItem1, this.CurrentProductItem2);
                        break;
                    case "3601":
                        #region Value Assign
                        this.CurrentCalibrationItem.Constant1 = receiveData.Substring(0, 7).Trim();
                        this.CurrentCalibrationItem.Constant2 = receiveData.Substring(7, 7).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.SystemCalibration)
                            this.ChildFormMenu.CenterSystemCalibration.UpdateConstantDisplay(this.CurrentCalibrationItem);
                        else if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.SystemJudgmentSetting)
                            this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateConstantDisplay(this.CurrentSystemStatus.Equipment, this.CurrentCalibrationItem);
                        break;
                    case "3901":
                        #region Value Assign
                        this.CurrentCalibrationItem.MaxWeight = receiveData.Substring(0, 7).Trim();
                        this.CurrentCalibrationItem.BalanceWeight = receiveData.Substring(7, 7).Trim();
                        this.CurrentCalibrationItem.Digit = receiveData.Substring(14, 7).Trim();
                        this.CurrentCalibrationItem.Constant1 = receiveData.Substring(21, 7).Trim();
                        this.CurrentCalibrationItem.Constant2 = receiveData.Substring(28, 7).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemCalibration.UpdateCalibrationItemDisplay(this.CurrentSystemStatus.Equipment, this.CurrentCalibrationItem);
                        break;
                    case "4901":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Mode = receiveData.Substring(12, 4).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.SystemAutoZero)
                            this.ChildFormMenu.CenterSystemAutoZero.UpdateZero1ParameterDisplay(this.CurrentSystemParameter9510);
                        else if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.MainSubMenu.UpdateZero1ParameterDisplay(this.CurrentSystemParameter9510);
                        break;
                    case "4902":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero2Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Time = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Range = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Variate = receiveData.Substring(12, 4).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemAutoZero.UpdateZero2ParameterDisplay(this.CurrentSystemParameter9510);
                        break;
                    case "4903":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Mode = receiveData.Substring(12, 4).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.SystemAutoZero)
                            this.ChildFormMenu.CenterSystemAutoZero.UpdateZero3ParameterDisplay(this.CurrentSystemParameter9511);
                        else if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.MainSubMenu.UpdateZero2ParameterDisplay(this.CurrentSystemParameter9511);
                        break;
                    case "4904":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero2Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Time = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Range = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Variate = receiveData.Substring(12, 4).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemAutoZero.UpdateZero4ParameterDisplay(this.CurrentSystemParameter9511);
                        break;
                    case "5302":
                        #region Value Assign
                        #endregion
                        break;
                    case "6901":
                        #region Value Assign
                        #endregion
                        break;
                    case "9507":
                        #region Value Assign
                        this.CurrentSystemParameter9507.BuzzerOnTime = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9507.RelayOnTime = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9507.SorterDoubleEntry = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9507.SensorChattering = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9507.EntryNotDetectedWeight = receiveData.Substring(16, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy2 = receiveData.Substring(23, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy3 = receiveData.Substring(30, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy4 = receiveData.Substring(37, 7).Trim();
                        if(receiveData.Substring(44, 4).Trim().StartsWith("-") == true)
                            this.CurrentSystemParameter9507.OptionBoard = "0";
                        else
                            this.CurrentSystemParameter9507.OptionBoard = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9507.SwitchChattering = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy5 = receiveData.Substring(52, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy6 = receiveData.Substring(56, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy7 = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy8 = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy9 = receiveData.Substring(68, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy10 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy11 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9508
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9508_SystemParameterRead, "");
                        break;
                    case "9508":
                        #region Value Assign
                        this.CurrentSystemParameter9508.OPT1SamplingCount = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1DelayCount = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1PulseWidth = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1IsWeightSetting = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1OverRange1 = receiveData.Substring(16, 7).Trim();
                        this.CurrentSystemParameter9508.OPT1UnderRange1 = receiveData.Substring(23, 7).Trim();
                        this.CurrentSystemParameter9508.OPT1Port = receiveData.Substring(30, 4).Trim();
                        this.CurrentSystemParameter9508.OPT2Port = receiveData.Substring(34, 4).Trim();
                        this.CurrentSystemParameter9508.OPT2DelayTime1 = receiveData.Substring(38, 4).Trim();
                        this.CurrentSystemParameter9508.OPT2DelayTime2 = receiveData.Substring(42, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1OverRange2 = receiveData.Substring(46, 7).Trim();
                        this.CurrentSystemParameter9508.OPT1UnderRange2 = receiveData.Substring(53, 7).Trim();
                        this.CurrentSystemParameter9508.Dummy1 = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy2 = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy3 = receiveData.Substring(68, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy4 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy5 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9509
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9509_SystemParameterRead, "");
                        break;
                    case "9509":
                        #region Value Assign
                        this.CurrentSystemParameter9509.ExternalOut1Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut1DelayTime = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut1RunTime = receiveData.Substring(8, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut2Mode = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut2DelayTime = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut2RunTime = receiveData.Substring(20, 4).Trim();
                        
                        this.CurrentSystemParameter9509.ExternalOut3Mode = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut3DelayTime = receiveData.Substring(28, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut3RunTime = receiveData.Substring(32, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut4Mode = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut4DelayTime = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut4RunTime = receiveData.Substring(44, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut9Mode = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut9DelayTime = receiveData.Substring(52, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut9RunTime = receiveData.Substring(56, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut10Mode = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut10DelayTime = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut10RunTime = receiveData.Substring(68, 4).Trim();

                        this.CurrentSystemParameter9509.Dummy1 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9509.Dummy2 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9510
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9510_SystemParameterRead, "");
                        break;
                    case "9510":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Mode = receiveData.Substring(12, 4).Trim();

                        this.CurrentSystemParameter9510.AutoZero2Mode = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Time = receiveData.Substring(20, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Range = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Variate = receiveData.Substring(28, 4).Trim();

                        this.CurrentSystemParameter9510.Dummy1 = receiveData.Substring(32, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy2 = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy3 = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy4 = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy5 = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy6 = receiveData.Substring(52, 4).Trim();
                        #endregion
                        // Read SystemParameter9511
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9511_SystemParameterRead, "");
                        break;
                    case "9511":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Mode = receiveData.Substring(12, 4).Trim();

                        this.CurrentSystemParameter9511.AutoZero2Mode = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Time = receiveData.Substring(20, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Range = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Variate = receiveData.Substring(28, 4).Trim();

                        this.CurrentSystemParameter9511.Dummy1 = receiveData.Substring(32, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy2 = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy3 = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy4 = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy5 = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy6 = receiveData.Substring(52, 4).Trim();
                        #endregion
                        this.TransferProductParameter1(this.SystemConfig.ProductNumber);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 파라미터 쓰기 응답
        private int ReceiveCommandPW0(string lane, string address, string receiveData)
        {
            int ret = 0;
            Define.E_ResponseData response = Define.E_ResponseData.NAK;

            try
            {
                if (receiveData == "0")
                    response = Define.E_ResponseData.NAK;
                else
                    response = Define.E_ResponseData.ACK;

                switch (address)
                {
                    case "4004":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4901_ParameterRead1, "");
                        break;
                    case "4005":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4902_ParameterRead2, "");
                        break;
                    case "4024":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4903_ParameterRead3, "");
                        break;
                    case "4025":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4904_ParameterRead4, "");
                        break;
                    case "9006":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferProductParameter1(this.SystemConfig.ProductNumber);
                        break;
                    case "9007":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
                        break;
                    case "9045":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferProductParameter2(this.SystemConfig.ProductNumber);
                        break;
                    case "9046":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // Bypass to motor
        private int ReceiveCommandPB0(string lane, string address, string receiveData)
        {
            int ret = 0;
            Define.E_ResponseData response = Define.E_ResponseData.NAK;

            try
            {
                if (receiveData == "0000")
                    response = Define.E_ResponseData.NAK;
                else
                    response = Define.E_ResponseData.ACK;

                switch (address)
                {
                    case "1101":
                        break;
                    case "1102":
                        break;
                    case "1103":
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }

        // 정지시 중량
        private int ReceiveCommandSN0(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign

                        if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                        {
                            this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                            this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                            this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                            this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                            this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                            this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                        }
                        else
                        {
                            this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);

                            this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                        }

                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateStopWeightDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CurrentWeightData2);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 운전시 중량
        private int ReceiveCommandSR0(string lane, string transferCount, string receiveData)
        {
            int ret = 0;

            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;

            try
            {
                switch (lane)
                {
                    case "A":
                        #region Value Assign
                        this.CurrentWeightData1.JudgmentStatus = Helper.StringToJudgmentStatus(receiveData.Substring(0, 2));
                        this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                        this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                        this.CurrentWeightData1.WeightString = receiveData.Substring(5, 5);
                        this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);
                        this.CurrentWeightData1.ProductionSpeed = int.Parse(receiveData.Substring(15, 4).Trim());

                        this.CurrentWeightData1.WeightSum(this.CurrentWeightData1.JudgmentStatus);
                        #endregion
                        // 통신 제대로 받으면 ACK
                        this.TransferData(string.Format("{0}{1}{2}", CommunicationCommand.RunWeightData, (int)Define.E_ResponseData.ACK, transferCount), CommunicationID.MainBoard);

                        this.IsJudgmentNow1 = true;
                        // 로그
                        if (this.IsCommunicationLogOpen == true)
                            this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow1 ({0:yyyy-MM-dd HH:mm:ss}): true", DateTime.Now));
                        this.timerEntryNotDetectedIgnoreTime1.Enabled = true;

                        #region 통신
                        if (this.SystemConfig.SerialCOM1Mode != 0)
                        {
                            #region COM1
                            switch (this.SystemConfig.SerialCOM1Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM1(this.Transfer_1_STD1(this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM1(this.Transfer_2_Remote(this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane2)
                                        if (this.SystemConfig.IsPrintPerProductEnable == true)
                                            this.TransferSerialCOM1("\n" + this.Transfer_3_Print(this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM1(this.Transfer_4_STD2(this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane2)
                                    {
                                        this.TransferSerialCOM1(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM1(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM1, this.CurrentWeightData1));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }
                        if (this.SystemConfig.SerialCOM3Mode != 0)
                        {
                            #region COM3
                            switch (this.SystemConfig.SerialCOM3Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM3(this.Transfer_1_STD1(this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM3(this.Transfer_2_Remote(this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane2)
                                            if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                this.TransferSerialCOM3("\n" + this.Transfer_3_Print(this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM3(this.Transfer_4_STD2(this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane2)
                                    {
                                        this.TransferSerialCOM3(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM3(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM3, this.CurrentWeightData1));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }
                        if (this.SystemConfig.SerialCOM4Mode != 0)
                        {
                            #region COM4
                            switch (this.SystemConfig.SerialCOM4Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM4(this.Transfer_1_STD1(this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM4(this.Transfer_2_Remote(this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane2)
                                            if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                this.TransferSerialCOM4("\n" + this.Transfer_3_Print(this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane2)
                                        this.TransferSerialCOM4(this.Transfer_4_STD2(this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane2)
                                    {
                                        this.TransferSerialCOM4(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM4(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM4, this.CurrentWeightData1));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }

                        // 이더넷
                        switch (this.SystemConfig.EthernetOperationMode)
                        {
                            case 1: // Server
                                if (this.smartTCPMultiServer.ClientInfoList != null)
                                {
                                    #region Server
                                    foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                    {
                                        switch (this.SystemConfig.EthernetCommMode)
                                        {
                                            case 1:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                    this.EthernetServerSendMessage(client,
                                                    this.Transfer_1_STD1
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                                break;
                                            case 2:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                    this.EthernetServerSendMessage(client, this.Transfer_2_Remote
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                                break;
                                            case 3:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                        if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                            this.EthernetServerSendMessage(client, "\n" + this.Transfer_3_Print
                                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                                break;
                                            case 4:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                    this.EthernetServerSendMessage(client, this.Transfer_4_STD2
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                                break;
                                            case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                {
                                                    this.EthernetServerSendMessage(client, this.SendChar(Define.E_CharValue.ENQ));
                                                    Thread.Sleep(30);
                                                    this.EthernetServerSendMessage(client, this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroEthernet, this.CurrentWeightData1));
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    #endregion
                                }
                                break;
                            case 2: // Client
                                switch (this.SystemConfig.EthernetCommMode)
                                {
                                    #region Client
                                    case 1:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                            this.EthernetWeightData(this.Transfer_1_STD1
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                        break;
                                    case 2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                            this.EthernetWeightData(this.Transfer_2_Remote
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                        break;
                                    case 3:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                                if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                    this.EthernetWeightData("\n" + this.Transfer_3_Print
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.CurrentWeightData1, this.CurrentProductItem1));
                                        break;
                                    case (int)Define.E_CommMode.f4_STD2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                            this.EthernetWeightData(this.Transfer_4_STD2
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane1, this.SystemConfig, this.CurrentWeightData1, this.CurrentProductItem1));
                                        break;
                                    case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane2)
                                        {
                                            this.EthernetWeightData(this.SendChar(Define.E_CharValue.ENQ));
                                            Thread.Sleep(30);
                                            this.EthernetWeightData(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroEthernet, this.CurrentWeightData1));
                                        }
                                        break;
                                    case (int)Define.E_CommMode.f99_Modbus: // 22, Modbus TCP
                                        if (this.SystemConfig.ModbusTCPSelectFunction == (int)Define.E_ModbusFunction._16_WriteMultipleRegister)
                                        {
                                            byte[] sendData = this.Modbus.MakeTCPSendAllData(this.Transfer_5_Modbus_Write_1Lane(), this.SystemConfig.ModbusTCPStartAddress);

                                            this.EthernetWeightDataForModbus(sendData);
                                        }
                                        break;
                                    default:
                                        break;
                                    #endregion
                                }
                                break;
                            default:
                                break;
                        }
                        #endregion

                        // CurrentDisplay
                        switch (this.CurrentSystemStatus.CurrentDisplay)
                        {
                            case Define.E_DisplayStore.MainDisplay:
                                #region MainDisplay
                                this.ChildFormMainDisplay.UpdateStartWeightDisplay1(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1);

                                if (this.CurrentWeightData1.JudgmentStatus != Define.E_JudgmentStatus.Empty)
                                    this.DataBackup1(this.CurrentWeightData1);

                                // 표준분포
                                this.CurrentWeightData1.SetNormalDistribution(this.CurrentProductItem1.CollectionNormalDistributionRange, this.CurrentWeightData1.WeightString);
                                #endregion
                                break;
                            default:
                                break;
                        }
                        break;
                    case "B":
                        #region Value Assign
                        this.CurrentWeightData2.JudgmentStatus = Helper.StringToJudgmentStatus(receiveData.Substring(0, 2));
                        this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 2);
                        this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                        this.CurrentWeightData2.WeightString = receiveData.Substring(5, 5);
                        this.CurrentWeightData2.ADCValue = receiveData.Substring(10, 5);
                        this.CurrentWeightData2.ProductionSpeed = int.Parse(receiveData.Substring(15, 4).Trim());

                        this.CurrentWeightData2.WeightSum(this.CurrentWeightData2.JudgmentStatus);
                        #endregion
                        // 통신 제대로 받으면 ACK
                        this.TransferData(string.Format("{0}{1}{2}", CommunicationCommand.RunWeightData, (int)Define.E_ResponseData.ACK, transferCount), CommunicationID.MainBoard);

                        this.IsJudgmentNow2 = true;
                        // 로그
                        //if (this.IsCommunicationLogOpen == true)
                        //    this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow2 ({0:yyyy-MM-dd HH:mm:ss}): true", DateTime.Now));
                        this.timerEntryNotDetectedIgnoreTime2.Enabled = true;

                        #region 통신
                        if (this.SystemConfig.SerialCOM1Mode != 0)
                        {
                            #region COM1
                            switch (this.SystemConfig.SerialCOM1Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM1(this.Transfer_1_STD1
                                            (this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM1(this.Transfer_2_Remote
                                            (this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane1, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane1)
                                            if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                this.TransferSerialCOM1("\n" + this.Transfer_3_Print
                                            (this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM1(this.Transfer_4_STD2
                                            (this.SystemConfig.IsCharToFillZeroCOM1, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM1 != (int)Define.E_Lane.Lane1)
                                    {
                                        this.TransferSerialCOM1(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM1(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM1, this.CurrentWeightData2));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }
                        if (this.SystemConfig.SerialCOM3Mode != 0)
                        {
                            #region COM3
                            switch (this.SystemConfig.SerialCOM3Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM3(this.Transfer_1_STD1
                                            (this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM3(this.Transfer_2_Remote
                                            (this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane1)
                                            if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                this.TransferSerialCOM3("\n" + this.Transfer_3_Print
                                            (this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM3(this.Transfer_4_STD2
                                            (this.SystemConfig.IsCharToFillZeroCOM3, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM3 != (int)Define.E_Lane.Lane1)
                                    {
                                        this.TransferSerialCOM3(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM3(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM3, this.CurrentWeightData2));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }
                        if (this.SystemConfig.SerialCOM4Mode != 0)
                        {
                            #region COM4
                            switch (this.SystemConfig.SerialCOM4Mode)
                            {
                                case 1:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM4(this.Transfer_1_STD1
                                            (this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 2:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM4(this.Transfer_2_Remote
                                            (this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 3:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane1)
                                            if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                this.TransferSerialCOM4("\n" + this.Transfer_3_Print
                                            (this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 4:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane1)
                                        this.TransferSerialCOM4(this.Transfer_4_STD2
                                            (this.SystemConfig.IsCharToFillZeroCOM4, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                    if (this.SystemConfig.SelectLaneCOM4 != (int)Define.E_Lane.Lane1)
                                    {
                                        this.TransferSerialCOM4(this.SendChar(Define.E_CharValue.ENQ)); // ACK
                                        Thread.Sleep(30);
                                        this.TransferSerialCOM4(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroCOM4, this.CurrentWeightData2));
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }

                        // 이더넷
                        switch (this.SystemConfig.EthernetOperationMode)
                        {
                            case 1: // Server
                                if (this.smartTCPMultiServer.ClientInfoList != null)
                                {
                                    #region Server
                                    foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                    {
                                        switch (this.SystemConfig.EthernetCommMode)
                                        {
                                            case 1:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                    this.EthernetServerSendMessage(client,
                                                    this.Transfer_1_STD1
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                                break;
                                            case 2:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                    this.EthernetServerSendMessage(client, this.Transfer_2_Remote
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                                break;
                                            case 3:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                        if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                            this.EthernetServerSendMessage(client, "\n" + this.Transfer_3_Print
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                                break;
                                            case 4:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                    this.EthernetServerSendMessage(client,
                                                    this.Transfer_4_STD2
                                                    (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                                break;
                                            case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                                if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                {
                                                    this.EthernetServerSendMessage(client, this.SendChar(Define.E_CharValue.ENQ));
                                                    Thread.Sleep(30);
                                                    this.EthernetServerSendMessage(client, this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroEthernet, this.CurrentWeightData2));
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    #endregion
                                }
                                break;
                            case 2: // Client
                                switch (this.SystemConfig.EthernetCommMode)
                                {
                                    #region Client
                                    case 1:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                            this.EthernetWeightData(this.Transfer_1_STD1
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                        break;
                                    case 2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                            this.EthernetWeightData(this.Transfer_2_Remote
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                        break;
                                    case 3:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                                if (this.SystemConfig.IsPrintPerProductEnable == true)
                                                    this.EthernetWeightData("\n" + this.Transfer_3_Print
                                                (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.CurrentWeightData2, this.CurrentProductItem2));
                                        break;
                                    case (int)Define.E_CommMode.f4_STD2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                            this.EthernetWeightData(this.Transfer_4_STD2
                                        (this.SystemConfig.IsCharToFillZeroEthernet, Define.E_Lane.Lane2, this.SystemConfig, this.CurrentWeightData2, this.CurrentProductItem2));
                                        break;
                                    case (int)Define.E_CommMode.f5_imaje_9028_OPT2:
                                        if (this.SystemConfig.SelectLaneEthernet != (int)Define.E_Lane.Lane1)
                                        {
                                            this.EthernetWeightData(this.SendChar(Define.E_CharValue.ENQ));
                                            Thread.Sleep(30);
                                            this.EthernetWeightData(this.Transfer_5_imaje9028OPT2(this.SystemConfig.IsCharToFillZeroEthernet, this.CurrentWeightData2));
                                        }
                                        break;
                                    case (int)Define.E_CommMode.f99_Modbus: // 22, Modbus TCP
                                        if (this.SystemConfig.ModbusTCPSelectFunction == (int)Define.E_ModbusFunction._16_WriteMultipleRegister)
                                        {
                                            byte[] sendData = this.Modbus.MakeTCPSendAllData(this.Transfer_5_Modbus_Write_1Lane(), this.SystemConfig.ModbusTCPStartAddress);

                                            this.EthernetWeightDataForModbus(sendData);
                                        }
                                        break;
                                    default:
                                        break;
                                    #endregion
                                }
                                break;
                            default:
                                break;
                        }
                        #endregion

                        // CurrentDisplay
                        switch (this.CurrentSystemStatus.CurrentDisplay)
                        {
                            case Define.E_DisplayStore.MainDisplay:
                                #region MainDisplay
                                this.ChildFormMainDisplay.UpdateStartWeightDisplay2(this.CurrentSystemStatus.Equipment, this.CurrentWeightData2);

                                if (this.CurrentWeightData2.JudgmentStatus != Define.E_JudgmentStatus.Empty)
                                    this.DataBackup2(this.CurrentWeightData2);

                                // 표준분포
                                this.CurrentWeightData2.SetNormalDistribution(this.CurrentProductItem2.CollectionNormalDistributionRange, this.CurrentWeightData2.WeightString);
                                #endregion
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 중량조정시 중량
        private int ReceiveCommandSC0(string lane, string receiveData)
        {
            int ret = 0;

            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                    #endregion
                    this.ChildFormMenu.CenterSystemCalibration.UpdateWeightDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CurrentWeightData2);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // IO테스트-IN
        private int ReceiveCommandST0(string lane, string receiveData)
        {
            int ret = 0;

            switch (lane)
            {
                case "0":
                    #region Value Assign
                    for (int i = 0; i < 8; i++)
                        this.CollectionIOTest_InputData[i] = receiveData.Substring(i, 1);
                    #endregion
                    if (this.CurrentSystemStatus.CurrentMode == Define.E_DisplayMode.IOTest)
                        this.ChildFormMenu.CenterSystemIOTest.UpdateInputRead(this.CollectionIOTest_InputData);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 판정설정시 중량 - 정지
        private int ReceiveCommandSF0(string lane, string receiveData)
        {
            int ret = 0;
            
            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateStopWeightDisplay(this.CurrentSystemStatus.Equipment,
                        this.CurrentWeightData1, this.CurrentWeightData2);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 판정설정 그래프
        private int ReceiveCommandSG0(string lane, string receiveData)
        {
            int ret = 0, temp = 15;

            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;

            switch (lane)
            {
                case "A":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    for (int i = 0; i < this.CollectionGraphData.Count; i++)
                    {
                        this.CollectionGraphData[i] = int.Parse(receiveData.Substring(temp, 5));
                        temp += 5;
                    }
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateGraphDataDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CollectionGraphData);
                    break;
                case "B":
                    #region Value Assign
                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(2, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(10, 5);

                    for (int i = 0; i < this.CollectionGraphData.Count; i++)
                    {
                        this.CollectionGraphData[i] = int.Parse(receiveData.Substring(temp, 5));
                        temp += 5;
                    }
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateGraphDataDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData2, this.CollectionGraphData);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 피드백 데이터
        private int ReceiveCommandSB0(string lane, string receiveData)
        {
            int ret = 0;
            int temp = 0;

            try
            {
                switch (lane)
                {
                    case "A":
                        #region Value Assign
                        this.CurrentFeedbackItem1.SampleCount = receiveData.Substring(0, 4);
                        this.CurrentFeedbackItem1.DelayCount = receiveData.Substring(4, 4);
                        this.CurrentFeedbackItem1.Sign = receiveData.Substring(8, 1);
                        this.CurrentFeedbackItem1.FeedbackWeight = receiveData.Substring(9, 7);
                        #endregion
                        this.ChildFormMainDisplay.MainFeedback.UpdateDisplayCurrentValue1(this.CurrentFeedbackItem1);
                        break;
                    case "B":
                        #region Value Assign
                        this.CurrentFeedbackItem2.SampleCount = receiveData.Substring(0, 4);
                        this.CurrentFeedbackItem2.DelayCount = receiveData.Substring(4, 4);
                        this.CurrentFeedbackItem2.Sign = receiveData.Substring(8, 1);
                        this.CurrentFeedbackItem2.FeedbackWeight = receiveData.Substring(9, 7);
                        #endregion
                        this.ChildFormMainDisplay.MainFeedback.UpdateDisplayCurrentValue2(this.CurrentFeedbackItem2);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        #endregion

        #region Communication protocol
        private string Transfer_1_STD1(bool isFillZero, Define.E_Lane line, SystemConfigurationItem system, WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append(string.Format("IN{0:000}", system.EquipmentID));
            sb.Append(string.Format("{0:0000}", product.Number));
            sb.Append((int)line);

            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.UnderRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.PassRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.OverRange, this.SystemConfig.DecimalPlaces)));

            switch (weight.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Empty:
                    break;
                case Define.E_JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case Define.E_JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case Define.E_JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case Define.E_JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case Define.E_JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case Define.E_JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append("E");
                    break;
            }

            sb.Append(Helper.StringZeroFillDigits6(Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces)));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        private string Transfer_2_Remote(bool isFillZero, Define.E_Lane line, WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append("01");

            switch (weight.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Empty:
                    break;
                case Define.E_JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case Define.E_JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case Define.E_JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case Define.E_JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case Define.E_JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case Define.E_JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append(" ");
                    break;
            }

            sb.Append(Helper.StringZeroFillDigits6(Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces)));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        private string Transfer_3_Print(bool isFillZero, Define.E_Lane line, WeightData weight, ProductItem product)
        {
            string value = "";
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return "";

            sb.Append(string.Format("{0, 4}", this.SystemConfig.ProductNumber));
            sb.Append(string.Format("{0, 3}", (int)line));

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Under)
                sb.Append("    U");
            else if (weight.JudgmentStatus == Define.E_JudgmentStatus.Pass)
                sb.Append("    P");
            else if (weight.JudgmentStatus == Define.E_JudgmentStatus.Over)
                sb.Append("    O");
            else if (weight.JudgmentStatus == Define.E_JudgmentStatus.Double)
                sb.Append("    D");
            else
                sb.Append("    E");

            value = Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces);
            sb.Append(value.PadLeft(8, ' '));
            value = weight.TotalCount.ToString();
            sb.Append(value.PadLeft(12, ' '));

            return sb.ToString();
        }
        private string Transfer_4_STD2(bool isFillZero, Define.E_Lane line, SystemConfigurationItem system, WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append(string.Format("IN{0:000}", system.EquipmentID));
            sb.Append(string.Format("{0:0000}", product.Number));
            sb.Append((int)line);

            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.UnderRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.PassRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.OverRange, this.SystemConfig.DecimalPlaces)));

            sb.Append(string.Format("{0:0000000}", weight.UnderCount));
            sb.Append(string.Format("{0:0000000}", weight.PassCount));
            sb.Append(string.Format("{0:0000000}", weight.OverCount));
            sb.Append(string.Format("{0:0000000}", weight.ETCExNGCount));
            sb.Append(string.Format("{0:000000000}", weight.TotalCount));

            switch (weight.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Empty:
                    break;
                case Define.E_JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case Define.E_JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case Define.E_JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case Define.E_JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case Define.E_JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case Define.E_JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append("E");
                    break;
            }

            if (weight.Weight <= 0.0)
                sb.Append("-");
            else
                sb.Append(" ");

            string temp = Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces);
            if (temp.StartsWith("-"))
                temp = temp.Substring(1, temp.Length - 1);
            sb.Append(temp.PadLeft(6, ' '));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        private byte[] Transfer_5_imaje9028OPT2(bool isFillZero, WeightData weight)
        {
            int tempStringLength = 0;
            string tempString = "";

            byte[] byteArray = new byte[11];
            byte[] weightBytes = new byte[5];

            // 중량발송 : 0x99
            byteArray[0] = 0x99;

            // Length : 0x00, 0x02 고정값
            byteArray[1] = 0x00;
            byteArray[2] = 0x07;
            byteArray[3] = 0x12;

            if (weight.JudgmentStatus == Define.E_JudgmentStatus.Pass)
            {
                tempStringLength = weight.Weight.ToString().Trim().Length;
                if (tempStringLength > 5)
                {
                    tempString = weight.Weight.ToString().Trim().Substring(tempStringLength - 5, 5).Replace(".", "");
                    if (isFillZero == true)
                        tempString = Helper.StringZeroFillDigits5(Helper.StringToDecimalPlaces(tempString, this.SystemConfig.DecimalPlaces));
                    else
                        tempString = this.PadLeft(5, Helper.StringToDecimalPlaces(tempString, this.SystemConfig.DecimalPlaces));
                }
                else
                {
                    if (isFillZero == true)
                        tempString = Helper.StringZeroFillDigits5(Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces));
                    else
                        tempString = this.PadLeft(5, Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces));
                }

                weightBytes = new UTF8Encoding().GetBytes(tempString);
                for (int i = 0; i < weightBytes.Length; i++)
                {
                    byteArray[i + 4] = weightBytes[i];
                }
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    byteArray[i + 4] = 0x20;
                }
            }

            byteArray[9] = 0x12;
            byteArray[10] = 0x00;
            byteArray[10] = Helper.ChecksumCalculator(byteArray);

            return byteArray;
        }
        public byte[] Transfer_5_Modbus_Write_1Lane()
        {
            byte[] madeData = new byte[ModbusTotalBytes];
            byte[] Length4Value = new byte[4];
            byte[] productName = new UTF8Encoding().GetBytes(this.CurrentProductItem1.Name);
            //Console.Write("\n" + string.Format("Transfer_22_Modbus_Write {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, this.CurrentProductItem1.Name));

            double underValue = Helper.StringToWeight(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces);
            double passValue = Helper.StringToWeight(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces);
            double overValue = Helper.StringToWeight(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces);
            double tareValue = Helper.StringToWeight(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces);

            int equipmentStatus;
            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                equipmentStatus = 1;
            else
                equipmentStatus = 0;

            int alarmStatus;
            if (this.IsAlarmOccured == true)
                alarmStatus = 1;
            else
                alarmStatus = 0;

            int judgmentStatus;
            switch (this.CurrentWeightData1.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Over:
                    judgmentStatus = 0;
                    break;
                case Define.E_JudgmentStatus.Pass:
                    judgmentStatus = 1;
                    break;
                case Define.E_JudgmentStatus.Under:
                    judgmentStatus = 2;
                    break;
                case Define.E_JudgmentStatus.Metal:
                    judgmentStatus = 3;
                    break;
                case Define.E_JudgmentStatus.Double:
                    judgmentStatus = 4;
                    break;
                default:
                    judgmentStatus = 5;
                    break;
            }

            Length4Value = GetBytes(this.UpdateValue);
            for (int i = 0; i < 4; i++)
                madeData[i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.SystemConfig.EquipmentID);
            for (int i = 0; i < 4; i++)
                madeData[4 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.SystemConfig.ProductNumber);
            for (int i = 0; i < 4; i++)
                madeData[8 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)underValue);
            for (int i = 0; i < 4; i++)
                madeData[12 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)passValue);
            for (int i = 0; i < 4; i++)
                madeData[16 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)overValue);
            for (int i = 0; i < 4; i++)
                madeData[20 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)tareValue);
            for (int i = 0; i < 4; i++)
                madeData[24 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.UnderCount);
            for (int i = 0; i < 4; i++)
                madeData[28 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.PassCount);
            for (int i = 0; i < 4; i++)
                madeData[32 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.OverCount);
            for (int i = 0; i < 4; i++)
                madeData[36 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.OverCount + this.CurrentWeightData1.UnderCount);
            for (int i = 0; i < 4; i++)
                madeData[40 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.ExNGCount);
            for (int i = 0; i < 4; i++)
                madeData[44 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.TotalCount);
            for (int i = 0; i < 4; i++)
                madeData[48 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(judgmentStatus);
            for (int i = 0; i < 4; i++)
                madeData[52 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)this.CurrentWeightData1.Weight);
            for (int i = 0; i < 4; i++)
                madeData[56 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(equipmentStatus);
            for (int i = 0; i < 4; i++)
                madeData[60 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(alarmStatus);
            for (int i = 0; i < 4; i++)
                madeData[64 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.ProductionSpeed);
            for (int i = 0; i < 4; i++)
                madeData[68 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.MetalDetectionCount);
            for (int i = 0; i < 4; i++)
                madeData[72 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData1.DoubleEntryCount);
            for (int i = 0; i < 4; i++)
                madeData[76 + i] = Length4Value[3 - i];

            int nameLength = productName.Length;
            for (int i = 0; i < nameLength; i++)
                madeData[80 + i] = productName[i];
            for (int i = 0; i < 20 - nameLength; i++)
                madeData[80 + nameLength + i] = 0x00;
            //Console.Write("\n" + string.Format("Transfer_22_Modbus_Write {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, Helper.ByteToHexString(madeData)));

            return madeData;
        }
        public byte[] Transfer_5_Modbus_Write_2Lane()
        {
            byte[] madeData = new byte[ModbusTotalBytes];
            byte[] Length4Value = new byte[4];
            byte[] productName = new UTF8Encoding().GetBytes(this.CurrentProductItem2.Name);
            //Console.Write("\n" + string.Format("Transfer_22_Modbus_Write {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, this.CurrentProductItem1.Name));

            double underValue = Helper.StringToWeight(this.CurrentProductItem2.UnderRange, this.SystemConfig.DecimalPlaces);
            double passValue = Helper.StringToWeight(this.CurrentProductItem2.PassRange, this.SystemConfig.DecimalPlaces);
            double overValue = Helper.StringToWeight(this.CurrentProductItem2.OverRange, this.SystemConfig.DecimalPlaces);
            double tareValue = Helper.StringToWeight(this.CurrentProductItem2.TareRange, this.SystemConfig.DecimalPlaces);

            int equipmentStatus;
            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                equipmentStatus = 1;
            else
                equipmentStatus = 0;

            int alarmStatus;
            if (this.IsAlarmOccured == true)
                alarmStatus = 1;
            else
                alarmStatus = 0;

            int judgmentStatus;
            switch (this.CurrentWeightData2.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Over:
                    judgmentStatus = 0;
                    break;
                case Define.E_JudgmentStatus.Pass:
                    judgmentStatus = 1;
                    break;
                case Define.E_JudgmentStatus.Under:
                    judgmentStatus = 2;
                    break;
                case Define.E_JudgmentStatus.Metal:
                    judgmentStatus = 3;
                    break;
                case Define.E_JudgmentStatus.Double:
                    judgmentStatus = 4;
                    break;
                default:
                    judgmentStatus = 5;
                    break;
            }

            Length4Value = GetBytes(this.UpdateValue);
            for (int i = 0; i < 4; i++)
                madeData[i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.SystemConfig.EquipmentID);
            for (int i = 0; i < 4; i++)
                madeData[4 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.SystemConfig.ProductNumber);
            for (int i = 0; i < 4; i++)
                madeData[8 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)underValue);
            for (int i = 0; i < 4; i++)
                madeData[12 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)passValue);
            for (int i = 0; i < 4; i++)
                madeData[16 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)overValue);
            for (int i = 0; i < 4; i++)
                madeData[20 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)tareValue);
            for (int i = 0; i < 4; i++)
                madeData[24 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.UnderCount);
            for (int i = 0; i < 4; i++)
                madeData[28 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.PassCount);
            for (int i = 0; i < 4; i++)
                madeData[32 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.OverCount);
            for (int i = 0; i < 4; i++)
                madeData[36 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.OverCount + this.CurrentWeightData2.UnderCount);
            for (int i = 0; i < 4; i++)
                madeData[40 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.ExNGCount);
            for (int i = 0; i < 4; i++)
                madeData[44 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.TotalCount);
            for (int i = 0; i < 4; i++)
                madeData[48 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(judgmentStatus);
            for (int i = 0; i < 4; i++)
                madeData[52 + i] = Length4Value[3 - i];

            Length4Value = GetBytes((Single)this.CurrentWeightData2.Weight);
            for (int i = 0; i < 4; i++)
                madeData[56 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(equipmentStatus);
            for (int i = 0; i < 4; i++)
                madeData[60 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(alarmStatus);
            for (int i = 0; i < 4; i++)
                madeData[64 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.ProductionSpeed);
            for (int i = 0; i < 4; i++)
                madeData[68 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.MetalDetectionCount);
            for (int i = 0; i < 4; i++)
                madeData[72 + i] = Length4Value[3 - i];

            Length4Value = GetBytes(this.CurrentWeightData2.DoubleEntryCount);
            for (int i = 0; i < 4; i++)
                madeData[76 + i] = Length4Value[3 - i];

            int nameLength = productName.Length;
            for (int i = 0; i < nameLength; i++)
                madeData[80 + i] = productName[i];
            for (int i = 0; i < 20 - nameLength; i++)
                madeData[80 + nameLength + i] = 0x00;
            //Console.Write("\n" + string.Format("Transfer_22_Modbus_Write {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, Helper.ByteToHexString(madeData)));

            return madeData;
        }
        private byte[] Transfer_5_Modbus_Read_RTU(byte[] readByte)
        {
            byte[] startAddressByte = new byte[2] { readByte[2], readByte[3] };
            byte[] numberOfRegisterByte = new byte[2] { readByte[4], readByte[5] };
            int startAddressInt;
            int numberOfRegisterInt;
            int madeDataIndex = 0;
            byte[] length2Value = new byte[2];
            byte[] length4Value = new byte[4];

            startAddressInt = Modbus.ToBigEndianAndInt(startAddressByte);
            numberOfRegisterInt = Modbus.ToBigEndianAndInt(numberOfRegisterByte);

            byte[] madeData = new byte[numberOfRegisterInt * 2];

            if (readByte[1] == ModbusFunctionCode.FunctionCode_03)
            {
                #region Read Holding Register(0x03)
                for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
                {
                    switch (j)
                    {
                        #region Make data
                        case _40000_ModbusAddress._01_Clear:
                            length2Value = GetBytes(this.Current40000ModbusData1._40011_Clear);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._02_ClearResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40012_ClearResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._03_Operation:
                            length2Value = GetBytes(this.Current40000ModbusData1._40013_Operation);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._04_OperationResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40014_OperationResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._05_ProductChange_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40015_ProductChange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._06_ProductChange_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40015_ProductChange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._07_ProductChangeResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40017_ProductChangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._08_UnderRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40018_UnderRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._09_UnderRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40018_UnderRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._10_UnderRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40020_UnderRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._11_PassRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40021_PassRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._12_PassRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40021_PassRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._13_PassRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40023_PassRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._14_OverRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40024_OverRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._15_OverRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40024_OverRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._16_OverRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40026_OverRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._17_TareWeight1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40027_TareWeight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._18_TareWeight1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40027_TareWeight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._19_TareWeightResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40029_TareWeightResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        default:
                            break;
                        #endregion
                    }
                    madeDataIndex += 2;
                }
                #endregion
            }
            else if (readByte[1] == ModbusFunctionCode.FunctionCode_04)
            {
                #region Read Input Register(0x04)
                double underValue = Helper.StringToWeight(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces);
                double passValue = Helper.StringToWeight(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces);
                double overValue = Helper.StringToWeight(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces);
                double tareValue = Helper.StringToWeight(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces);

                int equipmentStatus;
                if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                    equipmentStatus = 1;
                else
                    equipmentStatus = 0;

                int alarmStatus;
                if (this.IsAlarmOccured == true)
                    alarmStatus = 1;
                else
                    alarmStatus = 0;

                int judgmentStatus;
                switch (this.CurrentWeightData1.JudgmentStatus)
                {
                    case Define.E_JudgmentStatus.Over:
                        judgmentStatus = 0;
                        break;
                    case Define.E_JudgmentStatus.Pass:
                        judgmentStatus = 1;
                        break;
                    case Define.E_JudgmentStatus.Under:
                        judgmentStatus = 2;
                        break;
                    case Define.E_JudgmentStatus.Metal:
                        judgmentStatus = 3;
                        break;
                    case Define.E_JudgmentStatus.Double:
                        judgmentStatus = 4;
                        break;
                    default:
                        judgmentStatus = 5;
                        break;
                }

                byte[] productName = this.Current30000ModbusData1.ProductName;

                for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
                {
                    switch (j)
                    {
                        #region Make data

                        #region Data
                        case _30000_ModbusAddress._01_IsUpdate_High:
                            length4Value = GetBytes(this.UpdateValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._02_IsUpdate_Low:
                            length4Value = GetBytes(this.UpdateValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._03_EquipmentID_High:
                            length4Value = GetBytes(this.SystemConfig.EquipmentID);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._04_EquipmentID_Low:
                            length4Value = GetBytes(this.SystemConfig.EquipmentID);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._05_ProductNo_High:
                            length4Value = GetBytes(this.SystemConfig.ProductNumber);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._06_ProductNo_Low:
                            length4Value = GetBytes(this.SystemConfig.ProductNumber);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._07_UnderValue_High:
                            length4Value = GetBytes((Single)underValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._08_UnderValue_Low:
                            length4Value = GetBytes((Single)underValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._09_PassValue_High:
                            length4Value = GetBytes((Single)passValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._10_PassValue_Low:
                            length4Value = GetBytes((Single)passValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._11_OverValue_High:
                            length4Value = GetBytes((Single)overValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._12_OverValue_Low:
                            length4Value = GetBytes((Single)overValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._13_TareValue_High:
                            length4Value = GetBytes((Single)tareValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._14_TareValue_Low:
                            length4Value = GetBytes((Single)tareValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._15_UnderCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._16_UnderCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._17_PassCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.PassCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._18_PassCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.PassCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._19_OverCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._20_OverCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._21_NGCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount + this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._22_NGCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount + this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._23_ExNGCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.ExNGCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._24_ExNGCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.ExNGCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._25_TotalCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.TotalCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._26_TotalCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.TotalCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._27_Grade_High:
                            length4Value = GetBytes(judgmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._28_Grade_Low:
                            length4Value = GetBytes(judgmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._29_Weight_High:
                            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                length4Value = GetBytes((Single)0.0);
                            else
                                length4Value = GetBytes((Single)this.CurrentWeightData1.Weight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._30_Weight_Low:
                            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                length4Value = GetBytes((Single)0.0);
                            else
                                length4Value = GetBytes((Single)this.CurrentWeightData1.Weight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._31_OperationStatus_High:
                            length4Value = GetBytes(equipmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._32_OperationStatus_Low:
                            length4Value = GetBytes(equipmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._33_AlarmStatus_High:
                            length4Value = GetBytes(alarmStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._34_AlarmStatus_Low:
                            length4Value = GetBytes(alarmStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._35_Speed_High:
                            length4Value = GetBytes(this.CurrentWeightData1.ProductionSpeed);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._36_Speed_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.ProductionSpeed);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._37_MetalDetectionCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.MetalDetectionCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._38_MetalDetectionCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.MetalDetectionCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._39_DoubleEntryCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.DoubleEntryCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._40_DoubleEntryCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.DoubleEntryCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._41_ProductName:
                            for (int i = 0; i < productName.Length; i++)
                                madeData[madeDataIndex + i] = productName[i];
                            break;
                        #endregion

                        #region Alarm
                        case _30000_ModbusAddress._1001_Alarm1:
                            if (this.CurrentAlarm.Count > 0)
                                length2Value = GetBytes(this.CurrentAlarm[0]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1002_Alarm2:
                            if (this.CurrentAlarm.Count > 1)
                                length2Value = GetBytes(this.CurrentAlarm[1]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1003_Alarm3:
                            if (this.CurrentAlarm.Count > 2)
                                length2Value = GetBytes(this.CurrentAlarm[2]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1004_Alarm4:
                            if (this.CurrentAlarm.Count > 3)
                                length2Value = GetBytes(this.CurrentAlarm[3]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1005_Alarm5:
                            if (this.CurrentAlarm.Count > 4)
                                length2Value = GetBytes(this.CurrentAlarm[4]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1006_Alarm6:
                            if (this.CurrentAlarm.Count > 5)
                                length2Value = GetBytes(this.CurrentAlarm[5]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        #endregion

                        default:
                            break;
                        #endregion
                    }
                    if (j == (int)_30000_ModbusAddress._41_ProductName)
                        madeDataIndex += 20;
                    else
                        madeDataIndex += 2;
                }
                #endregion
            }

            return madeData;
        }
        private byte[] Transfer_5_Modbus_Read_TCP(byte[] readByte)
        {
            byte[] startAddressByte = new byte[2] { readByte[8], readByte[9] };
            byte[] numberOfRegisterByte = new byte[2] { readByte[10], readByte[11] };
            int startAddressInt;
            int numberOfRegisterInt;
            int madeDataIndex = 0;
            byte[] length2Value = new byte[2];
            byte[] length4Value = new byte[4];

            startAddressInt = Modbus.ToBigEndianAndInt(startAddressByte);
            numberOfRegisterInt = Modbus.ToBigEndianAndInt(numberOfRegisterByte);

            byte[] madeData = new byte[numberOfRegisterInt * 2];

            if (readByte[7] == ModbusFunctionCode.FunctionCode_03)
            {
                #region Read Holding Register(0x03)
                for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
                {
                    switch (j)
                    {
                        #region Make data
                        case _40000_ModbusAddress._01_Clear:
                            length2Value = GetBytes(this.Current40000ModbusData1._40011_Clear);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._02_ClearResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40012_ClearResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._03_Operation:
                            length2Value = GetBytes(this.Current40000ModbusData1._40013_Operation);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._04_OperationResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40014_OperationResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._05_ProductChange_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40015_ProductChange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._06_ProductChange_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40015_ProductChange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._07_ProductChangeResult:
                            length2Value = GetBytes(this.Current40000ModbusData1._40017_ProductChangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._08_UnderRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40018_UnderRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._09_UnderRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40018_UnderRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._10_UnderRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40020_UnderRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._11_PassRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40021_PassRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._12_PassRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40021_PassRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._13_PassRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40023_PassRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._14_OverRange1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40024_OverRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._15_OverRange1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40024_OverRange);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._16_OverRangeResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40026_OverRangeResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _40000_ModbusAddress._17_TareWeight1_High:
                            length4Value = GetBytes(this.Current40000ModbusData1._40027_TareWeight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _40000_ModbusAddress._18_TareWeight1_Low:
                            length4Value = GetBytes(this.Current40000ModbusData1._40027_TareWeight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _40000_ModbusAddress._19_TareWeightResult1:
                            length2Value = GetBytes(this.Current40000ModbusData1._40029_TareWeightResult);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        default:
                            break;
                        #endregion
                    }
                    madeDataIndex += 2;
                }
                #endregion
            }
            else if (readByte[7] == ModbusFunctionCode.FunctionCode_04)
            {
                #region Read Input Register(0x04)
                double underValue = Helper.StringToWeight(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces);
                double passValue = Helper.StringToWeight(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces);
                double overValue = Helper.StringToWeight(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces);
                double tareValue = Helper.StringToWeight(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces);
                double weight = this.CurrentWeightData1.Weight;

                int equipmentStatus;
                if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
                    equipmentStatus = 1;
                else
                    equipmentStatus = 0;

                int alarmStatus;
                if (this.IsAlarmOccured == true)
                    alarmStatus = 1;
                else
                    alarmStatus = 0;

                int judgmentStatus;
                switch (this.CurrentWeightData1.JudgmentStatus)
                {
                    case Define.E_JudgmentStatus.Over:
                        judgmentStatus = 0;
                        break;
                    case Define.E_JudgmentStatus.Pass:
                        judgmentStatus = 1;
                        break;
                    case Define.E_JudgmentStatus.Under:
                        judgmentStatus = 2;
                        break;
                    case Define.E_JudgmentStatus.Metal:
                        judgmentStatus = 3;
                        break;
                    case Define.E_JudgmentStatus.Double:
                        judgmentStatus = 4;
                        break;
                    default:
                        judgmentStatus = 5;
                        break;
                }

                byte[] productName = this.Current30000ModbusData1.ProductName;

                for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
                {
                    switch (j)
                    {
                        #region Make data

                        #region Data
                        case _30000_ModbusAddress._01_IsUpdate_High:
                            length4Value = GetBytes(this.UpdateValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._02_IsUpdate_Low:
                            length4Value = GetBytes(this.UpdateValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._03_EquipmentID_High:
                            length4Value = GetBytes(this.SystemConfig.EquipmentID);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._04_EquipmentID_Low:
                            length4Value = GetBytes(this.SystemConfig.EquipmentID);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._05_ProductNo_High:
                            length4Value = GetBytes(this.SystemConfig.ProductNumber);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._06_ProductNo_Low:
                            length4Value = GetBytes(this.SystemConfig.ProductNumber);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._07_UnderValue_High:
                            length4Value = GetBytes((Single)underValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._08_UnderValue_Low:
                            length4Value = GetBytes((Single)underValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._09_PassValue_High:
                            length4Value = GetBytes((Single)passValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._10_PassValue_Low:
                            length4Value = GetBytes((Single)passValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._11_OverValue_High:
                            length4Value = GetBytes((Single)overValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._12_OverValue_Low:
                            length4Value = GetBytes((Single)overValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._13_TareValue_High:
                            length4Value = GetBytes((Single)tareValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._14_TareValue_Low:
                            length4Value = GetBytes((Single)tareValue);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._15_UnderCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._16_UnderCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._17_PassCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.PassCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._18_PassCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.PassCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._19_OverCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._20_OverCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._21_NGCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount + this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._22_NGCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.OverCount + this.CurrentWeightData1.UnderCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._23_ExNGCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.ExNGCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._24_ExNGCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.ExNGCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._25_TotalCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.TotalCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._26_TotalCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.TotalCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._27_Grade_High:
                            length4Value = GetBytes(judgmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._28_Grade_Low:
                            length4Value = GetBytes(judgmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._29_Weight_High:
                            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                length4Value = GetBytes((Single)0.0);
                            else
                                length4Value = GetBytes((Single)this.CurrentWeightData1.Weight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._30_Weight_Low:
                            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                length4Value = GetBytes((Single)0.0);
                            else
                                length4Value = GetBytes((Single)this.CurrentWeightData1.Weight);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._31_OperationStatus_High:
                            length4Value = GetBytes(equipmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._32_OperationStatus_Low:
                            length4Value = GetBytes(equipmentStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._33_AlarmStatus_High:
                            length4Value = GetBytes(alarmStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._34_AlarmStatus_Low:
                            length4Value = GetBytes(alarmStatus);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._35_Speed_High:
                            length4Value = GetBytes(this.CurrentWeightData1.ProductionSpeed);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._36_Speed_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.ProductionSpeed);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._37_MetalDetectionCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.MetalDetectionCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._38_MetalDetectionCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.MetalDetectionCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._39_DoubleEntryCount_High:
                            length4Value = GetBytes(this.CurrentWeightData1.DoubleEntryCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[3 - i];
                            break;
                        case _30000_ModbusAddress._40_DoubleEntryCount_Low:
                            length4Value = GetBytes(this.CurrentWeightData1.DoubleEntryCount);
                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length4Value[1 - i];
                            break;
                        case _30000_ModbusAddress._41_ProductName:
                            for (int i = 0; i < productName.Length; i++)
                                madeData[madeDataIndex + i] = productName[i];
                            break;
                        #endregion

                        #region Alarm
                        case _30000_ModbusAddress._1001_Alarm1:
                            if (this.CurrentAlarm.Count > 0)
                                length2Value = GetBytes(this.CurrentAlarm[0]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1002_Alarm2:
                            if (this.CurrentAlarm.Count > 1)
                                length2Value = GetBytes(this.CurrentAlarm[1]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1003_Alarm3:
                            if (this.CurrentAlarm.Count > 2)
                                length2Value = GetBytes(this.CurrentAlarm[2]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1004_Alarm4:
                            if (this.CurrentAlarm.Count > 3)
                                length2Value = GetBytes(this.CurrentAlarm[3]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1005_Alarm5:
                            if (this.CurrentAlarm.Count > 4)
                                length2Value = GetBytes(this.CurrentAlarm[4]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        case _30000_ModbusAddress._1006_Alarm6:
                            if (this.CurrentAlarm.Count > 5)
                                length2Value = GetBytes(this.CurrentAlarm[5]);
                            else
                                length2Value = GetBytes(0);

                            for (int i = 0; i < 2; i++)
                                madeData[madeDataIndex + i] = length2Value[1 - i];
                            break;
                        #endregion

                        default:
                            break;
                        #endregion
                    }
                    if (j == (int)_30000_ModbusAddress._41_ProductName)
                        madeDataIndex += 20;
                    else
                        madeDataIndex += 2;
                }
                #endregion
            }

            return madeData;
        }
        #endregion

        #region Serial Communication
        public string SendChar(Define.E_CharValue sendChar)
        {
            StringBuilder temp = new StringBuilder();

            switch (sendChar)
            {
                case Define.E_CharValue.ENQ:
                    temp.Append((char)0x05);
                    break;
                case Define.E_CharValue.ACK:
                    temp.Append((char)0x06);
                    break;
                case Define.E_CharValue.NAK:
                    temp.Append((char)0x15);
                    break;
                case Define.E_CharValue.Space:
                    temp.Append((char)0x20);
                    break;
            }

            return temp.ToString();
        }
        public string PadLeft(int length, string sValue)
        {
            string temp;

            temp = sValue.PadLeft(length, ' ');

            return temp;
        }

        // 전송지연시간
        private void CreateTimer(Define.E_MenuBottomConfiguration port)
        {
            switch (port)
            {
                case Define.E_MenuBottomConfiguration.SerialCOM1:
                    System.Windows.Forms.Timer timerCOM1 = new System.Windows.Forms.Timer();
                    timerCOM1.Interval = this.SystemConfig.TransmissionDelayTimeCOM1;
                    timerCOM1.Tick += new EventHandler(this.timerCOM1_Tick);
                    timerCOM1.Enabled = true;
                    break;
                case Define.E_MenuBottomConfiguration.SerialCOM3:
                    System.Windows.Forms.Timer timerCOM3 = new System.Windows.Forms.Timer();
                    timerCOM3.Interval = this.SystemConfig.TransmissionDelayTimeCOM3;
                    timerCOM3.Tick += new EventHandler(this.timerCOM3_Tick);
                    timerCOM3.Enabled = true;
                    break;
                case Define.E_MenuBottomConfiguration.SerialCOM4:
                    System.Windows.Forms.Timer timerCOM4 = new System.Windows.Forms.Timer();
                    timerCOM4.Interval = this.SystemConfig.TransmissionDelayTimeCOM4;
                    timerCOM4.Tick += new EventHandler(this.timerCOM4_Tick);
                    timerCOM4.Enabled = true;
                    break;
                default:
                    break;
            }
        }
        #endregion
        #region Serial COM1
        public void OpenSerialCOM1()
        {
            int baudrate = 9600;

            if (this.SystemConfig.SerialCOM1Mode == 0)
                return;

            this.CloseSerialCOM1();

            switch (this.SystemConfig.SerialCOM1BaudRate)
            {
                case 0:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
                case 1:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
                    baudrate = 19200;
                    break;
                case 2:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
                    baudrate = 38400;
                    break;
                case 3:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
                    baudrate = 57600;
                    break;
                case 4:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
                    baudrate = 115200;
                    break;
                default:
                    this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
            }


            //if (this.FlagSerialDll == false)
            //{
            this.smartSerialPort1.Open();
            //}
            //else
            //{
            //    // Port : COM1
            //    SerialMgrComm.serialPortOpen("COM1:", baudrate, 0, 0, 8);
            //}
        }
        public void CloseSerialCOM1()
        {
            //if (this.FlagSerialDll == false)
            if (this.CheckOpenCOM1() == true)
                this.smartSerialPort1.Close();
            //else
            //    SerialMgrComm.serialPortClose("COM1:");
        }
        public bool CheckOpenCOM1()
        {
            //if (this.FlagSerialDll == false)
            //{
            if (this.smartSerialPort1.IsOpen == true)
                return true;
            else
                return false;
            //}
            //else
            //    return true;
        }
        public void TransferDirectSerialCOM1(string strTemp)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort1.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
            //else
            //    SerialMgrComm.serialPortMessageRaw("COM1:", strTemp);
        }
        public void TransferDirectSerialCOM1(byte[] buffer)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort1.WriteNoneFrame(buffer);
            //else
            //    SerialMgrComm.serialPortMessageByte("COM1:", buffer, buffer.Length);
        }
        public void TransferSerialCOM1(string strTemp)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM1 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort1.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
                //else
                //    SerialMgrComm.serialPortMessageRaw("COM1:", strTemp);
            }
            else
            {
                this.QueueCOM1.Enqueue(strTemp);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM1);
            }
        }
        public void TransferSerialCOM1(byte[] buffer)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM1 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort1.WriteNoneFrame(buffer);
                //else
                //    SerialMgrComm.serialPortMessageByte("COM1:", buffer, buffer.Length);
            }
            else
            {
                this.QueueCOM1.Enqueue(buffer);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM1);
            }
        }
        public void ChangeSerialCOM1FrameSeparateType(Define.E_SeparateType type)
        {
            //if (this.FlagSerialDll == true)
            //    return;

            // 통신 포트 설정
            //this.CloseSerialCOM1();

            if (type == Define.E_SeparateType.ETXONLY)
            {
                this.smartSerialPort1.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.ETXONLY;

                byte[] etxCodes = new byte[2];
                etxCodes[0] = 13;
                etxCodes[1] = 10;
                this.smartSerialPort1.ETXCodes = etxCodes;
            }
            else if (type == Define.E_SeparateType.STXANDETX)
            {
                this.smartSerialPort1.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;

                this.smartSerialPort1.STXCode = 2;
                this.smartSerialPort1.ETXCode = 3;
            }
            else if (type == Define.E_SeparateType.NONEFRAME_READTIMEOUT)
            {
                this.smartSerialPort1.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.NONEFRAME_READTIMEOUT;
                this.smartSerialPort1.ReadTimeout = 300;
            }
            else
            {

            }

            //this.smartSerialPort1.Open();
        }
        #endregion
        #region Serial COM3
        public void OpenSerialCOM3()
        {
            int baudrate = 9600;

            if (this.SystemConfig.SerialCOM3Mode == (int)Define.E_CommMode.f0_None)
                return;

            this.CloseSerialCOM3();

            switch (this.SystemConfig.SerialCOM3BaudRate)
            {
                case 0:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
                case 1:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
                    baudrate = 19200;
                    break;
                case 2:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
                    baudrate = 38400;
                    break;
                case 3:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
                    baudrate = 57600;
                    break;
                case 4:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
                    baudrate = 115200;
                    break;
                default:
                    this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
            }

            this.smartSerialPort3.Open();
        }
        public void CloseSerialCOM3()
        {
            //if (this.FlagSerialDll == false)
            if (this.CheckOpenCOM3() == true)
                this.smartSerialPort3.Close();
            //else
            //    SerialMgrComm.serialPortClose("COM3:");
        }
        public bool CheckOpenCOM3()
        {
            //if (this.FlagSerialDll == false)
            //{
            if (this.smartSerialPort3.IsOpen == true)
                return true;
            else
                return false;
            //}
            //else
            //    return true;
        }
        public void TransferDirectSerialCOM3(string strTemp)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort3.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
            //else
            //    SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
        }
        public void TransferDirectSerialCOM3(byte[] buffer)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort3.WriteNoneFrame(buffer);
            //else
            //    SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
        }
        public void TransferDirectSerialCOM3RawData(string strTemp)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort3.RawSerialPort.Write(strTemp);
            //else
            //    SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
        }
        public void TransferDirectSerialCOM3RawData(byte[] buffer)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort3.RawSerialPort.Write(buffer, 0, buffer.Length);
            //else
            //    SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
        }
        public void TransferSerialCOM3(string strTemp)
        {
            if (strTemp == "" || strTemp == null)
                return;

            if (this.SystemConfig.TransmissionDelayTimeCOM3 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort3.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
                //else
                //    SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
            }
            else
            {
                this.QueueCOM3.Enqueue(strTemp);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
            }
        }
        public void TransferSerialCOM3(byte[] buffer)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM3 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort3.WriteNoneFrame(buffer);
                //else
                //    SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
            }
            else
            {
                this.QueueCOM3.Enqueue(buffer);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
            }
        }
        public void TransferSerialCOM3RawData(byte[] buffer)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM3 == 0)
            {
                //if (this.FlagSerialDll == false)
                //RawSerialPort 기능을 사용하여 데이터를 전송
                this.smartSerialPort3.RawSerialPort.Write(buffer, 0, buffer.Length);
                //else
                //    SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);

            }
            else
            {
                this.QueueCOM3.Enqueue(buffer);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
            }
        }
        public void ReceiveSerialCOM3()
        {
            int ret = 0;
            string strTemp = "";
            byte[] readByte;

            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPort3.ReadQueue(out readByte);
                strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
                return;
        }

        public void ChangeSerialCOM3FrameSeparateType(Define.E_SeparateType type)
        {
            //if (this.FlagSerialDll == true)
            //    return;

            // 통신 포트 설정
            //this.CloseSerialCOM3();

            if (type == Define.E_SeparateType.ETXONLY)
            {
                this.smartSerialPort3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.ETXONLY;

                byte[] etxCodes = new byte[2];
                etxCodes[0] = 13;
                etxCodes[1] = 10;
                this.smartSerialPort3.ETXCodes = etxCodes;
            }
            else if (type == Define.E_SeparateType.STXANDETX)
            {
                this.smartSerialPort3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;

                this.smartSerialPort3.STXCode = 2;
                this.smartSerialPort3.ETXCode = 3;
            }
            else if (type == Define.E_SeparateType.NONEFRAME_READTIMEOUT)
            {
                this.smartSerialPort3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.NONEFRAME_READTIMEOUT;
                this.smartSerialPort3.ReadTimeout = 300;
            }
            else
            {

            }

            //this.smartSerialPort3.Open();
        }
        public void ChangeSerialCOM3ReceiveDetect(SmartSerialPort.RECEIVEDETECTTYPE detectType)
        {
            this.smartSerialPort3.ReceiveDetect = detectType;
        }
        public void ChangeSerialCOM3FrameBufferSize(uint size)
        {
            this.smartSerialPort3.FrameBufferSize = size;
        }
        #endregion
        #region Serial COM4
        public void OpenSerialCOM4()
        {
            int baudrate = 9600;

            if (this.SystemConfig.SerialCOM4Mode == 0)
                return;

            this.CloseSerialCOM4();

            switch (this.SystemConfig.SerialCOM4BaudRate)
            {
                case 0:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
                case 1:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
                    baudrate = 19200;
                    break;
                case 2:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
                    baudrate = 38400;
                    break;
                case 3:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
                    baudrate = 57600;
                    break;
                case 4:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
                    baudrate = 115200;
                    break;
                default:
                    this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
                    baudrate = 9600;
                    break;
            }

            //if (this.FlagSerialDll == false)
            //{
            this.smartSerialPort4.Open();
            //}
            //else
            //{
            //    // Port : COM4
            //    SerialMgrComm.serialPortOpen("COM4:", baudrate, 0, 0, 8);
            //}
        }
        public void CloseSerialCOM4()
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort4.Close();
            //else
            //    SerialMgrComm.serialPortClose("COM4:");
        }
        public bool CheckOpenCOM4()
        {
            //if (this.FlagSerialDll == false)
            //{
            if (this.smartSerialPort4.IsOpen == true)
                return true;
            else
                return false;
            //}
            //else
            //    return true;
        }
        public void TransferDirectSerialCOM4(string strTemp)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort4.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
            //else
            //    SerialMgrComm.serialPortMessageRaw("COM4:", strTemp);
        }
        public void TransferDirectSerialCOM4(byte[] buffer)
        {
            //if (this.FlagSerialDll == false)
            this.smartSerialPort4.WriteNoneFrame(buffer);
            //else
            //    SerialMgrComm.serialPortMessageByte("COM4:", buffer, buffer.Length);
        }
        public void TransferSerialCOM4(string strTemp)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM4 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort4.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
                //else
                //    SerialMgrComm.serialPortMessageRaw("COM4:", strTemp);
            }
            else
            {
                this.QueueCOM4.Enqueue(strTemp);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM4);
            }
        }
        public void TransferSerialCOM4(byte[] buffer)
        {
            if (this.SystemConfig.TransmissionDelayTimeCOM4 == 0)
            {
                //if (this.FlagSerialDll == false)
                this.smartSerialPort4.WriteNoneFrame(buffer);
                //else
                //    SerialMgrComm.serialPortMessageByte("COM4:", buffer, buffer.Length);
            }
            else
            {
                this.QueueCOM4.Enqueue(buffer);
                this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM4);
            }
        }
        public void ChangeSerialCOM4FrameSeparateType(Define.E_SeparateType type)
        {
            //if (this.FlagSerialDll == true)
            //    return;

            // 통신 포트 설정
            //this.CloseSerialCOM4();

            if (type == Define.E_SeparateType.ETXONLY)
            {
                this.smartSerialPort4.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.ETXONLY;

                byte[] etxCodes = new byte[2];
                etxCodes[0] = 13;
                etxCodes[1] = 10;
                this.smartSerialPort4.ETXCodes = etxCodes;
            }
            else if (type == Define.E_SeparateType.STXANDETX)
            {
                this.smartSerialPort4.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;

                this.smartSerialPort4.STXCode = 2;
                this.smartSerialPort4.ETXCode = 3;
            }
            else if (type == Define.E_SeparateType.NONEFRAME_READTIMEOUT)
            {
                this.smartSerialPort4.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.NONEFRAME_READTIMEOUT;
                this.smartSerialPort4.ReadTimeout = 300;
            }
            else
            {

            }

            //this.smartSerialPort4.Open();
        }
        #endregion

        #region Data Backup
        private void RemoveUsbBackupFile()
        {
            bool directoryCheck = false;

            try
            {
                string dday = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(-180)) + ".csv";

                DirectoryInfo dir = new DirectoryInfo(this.PathDataBackupFolder);

                directoryCheck = dir.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    dir.Create();

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo subfile in files)
                {
                    if (subfile.Name.StartsWith("20"))  // 날짜 비교하여 180일 지난화일은 삭제함 
                    {
                        if (subfile.Name.CompareTo(dday) < 0)
                        {
                            subfile.Delete();
                        }
                    }
                }
            }
            catch
            {

            }

        }
        private void DataBackup1(WeightData item)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            this.RemoveUsbBackupFile();

            if (this.SystemConfig.IsDataBackup == true)
            {
                fullFilePath = string.Format("{0}{1:yyyyMMdd}_{2}_{3}_Line1.csv", this.PathDataBackupFolder, DateTime.Now, this.SystemConfig.UsbID, this.CurrentProductItem1.Name);

                DirectoryInfo di = new DirectoryInfo(this.PathDataBackupFolder);
                directoryCheck = di.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    di.Create();
                // 파일 체크
                FileInfo fileInfo = new FileInfo(fullFilePath);
                fileCheck = fileInfo.Exists;

                sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);

                if (fileCheck == false)
                {
                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("P_No");
                    sw.Write(",");
                    sw.Write("Name");
                    sw.Write(",");
                    sw.Write("Lot");
                    sw.Write(",");
                    sw.Write("UnderRange");
                    sw.Write(",");
                    sw.Write("PassRange");
                    sw.Write(","); 
                    sw.Write("OverRange");
                    sw.Write(",");
                    sw.Write("TareRange");
                    sw.Write(",");
                    sw.Write("Weight");
                    sw.Write(",");
                    sw.Write("Grade");
                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", time));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", time));
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Number);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Name);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.LotNo);
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.DoubleToString(item.Weight, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(item.JudgmentStatus);
                sw.WriteLine();

                sw.Close();
            }
        }
        private void DataBackup2(WeightData item)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            this.RemoveUsbBackupFile();

            if (this.SystemConfig.IsDataBackup == true)
            {
                fullFilePath = string.Format("{0}{1:yyyyMMdd}_{2}_{3}_Line2.csv", this.PathDataBackupFolder, DateTime.Now, this.SystemConfig.UsbID, this.CurrentProductItem1.Name);

                DirectoryInfo di = new DirectoryInfo(this.PathDataBackupFolder);
                directoryCheck = di.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    di.Create();
                // 파일 체크
                FileInfo fileInfo = new FileInfo(fullFilePath);
                fileCheck = fileInfo.Exists;

                sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);

                if (fileCheck == false)
                {
                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("P_No");
                    sw.Write(",");
                    sw.Write("Name");
                    sw.Write(",");
                    sw.Write("Lot");
                    sw.Write(",");
                    sw.Write("UnderRange");
                    sw.Write(",");
                    sw.Write("PassRange");
                    sw.Write(",");
                    sw.Write("OverRange");
                    sw.Write(",");
                    sw.Write("TareRange");
                    sw.Write(",");
                    sw.Write("Weight");
                    sw.Write(",");
                    sw.Write("Grade");
                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", time));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", time));
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Number);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Name);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.LotNo);
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.DoubleToString(item.Weight, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(item.JudgmentStatus);
                sw.WriteLine();

                sw.Close();
            }
        }
        #endregion

        #region OPC, Modbus
        public static byte[] GetBytes(int argument)
        {
            byte[] byteArray = BitConverter.GetBytes(argument);
            return byteArray;
        }
        public static byte[] GetBytes(Single argument)
        {
            byte[] byteArray = BitConverter.GetBytes(argument);
            return byteArray;
        }
        public static byte[] GetBytes(uint argument)
        {
            byte[] byteArray = BitConverter.GetBytes(argument);
            return byteArray;
        }

        /// <summary>
        /// OPC, Modbus - 항목 업데이트 시마다 +1
        /// </summary>
        public void Update30000ModbusItem()
        {
            if (this.IsOPCModbusUsing == false)
                return;

            if (this.UpdateValue > 999999999)
                this.UpdateValue = 0;
            else
                this.UpdateValue++;

            this.Current30000ModbusData1.IsUpdate = this.UpdateValue;
            this.Current30000ModbusData1.EquipmentID = this.SystemConfig.EquipmentID;
            this.Current30000ModbusData1.ProductNo = this.SystemConfig.ProductNumber;

            this.Current30000ModbusData1.UnderValue = Helper.StringToWeight(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces);
            this.Current30000ModbusData1.PassValue = Helper.StringToWeight(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces);
            this.Current30000ModbusData1.OverValue = Helper.StringToWeight(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces);
            this.Current30000ModbusData1.TareValue = Helper.StringToWeight(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces);

            this.Current30000ModbusData1.UnderCount = (UInt32)this.CurrentWeightData1.UnderCount;
            this.Current30000ModbusData1.PassCount = (UInt32)this.CurrentWeightData1.PassCount;
            this.Current30000ModbusData1.OverCount = (UInt32)this.CurrentWeightData1.OverCount;
            this.Current30000ModbusData1.NGCount = (UInt32)this.CurrentWeightData1.UnderCount + (UInt32)this.CurrentWeightData1.OverCount;
            this.Current30000ModbusData1.ExNGCount = (UInt32)this.CurrentWeightData1.ETCExNGCount;
            this.Current30000ModbusData1.TotalCount = (UInt32)this.CurrentWeightData1.TotalCount;

            switch (this.CurrentWeightData1.JudgmentStatus)
            {
                case Define.E_JudgmentStatus.Over:
                    this.Current30000ModbusData1.Grade = 0;
                    break;
                case Define.E_JudgmentStatus.Pass:
                    this.Current30000ModbusData1.Grade = 1;
                    break;
                case Define.E_JudgmentStatus.Under:
                    this.Current30000ModbusData1.Grade = 2;
                    break;
                case Define.E_JudgmentStatus.Metal:
                    this.Current30000ModbusData1.Grade = 3;
                    break;
                case Define.E_JudgmentStatus.Double:
                    this.Current30000ModbusData1.Grade = 4;
                    break;
                default:
                    this.Current30000ModbusData1.Grade = 5;
                    break;
            }

            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start)
            {
                this.Current30000ModbusData1.Weight = this.CurrentWeightData1.Weight;
                this.Current30000ModbusData1.OperationStatus = 1;
            }
            else
            {
                this.Current30000ModbusData1.Weight = 0.0;
                this.Current30000ModbusData1.OperationStatus = 0;
            }

            if (this.IsAlarmOccured == true)
                this.Current30000ModbusData1.AlarmStatus = 1;
            else
                this.Current30000ModbusData1.AlarmStatus = 0;

            if (this.CurrentWeightData1.ProductionSpeed <= 500)
                this.Current30000ModbusData1.Speed = this.CurrentWeightData1.ProductionSpeed;
            this.Current30000ModbusData1.MetalDetectionCount = (UInt32)this.CurrentWeightData1.MetalDetectionCount;
            this.Current30000ModbusData1.DoubleEntryCount = (UInt32)this.CurrentWeightData1.DoubleEntryCount;

            try
            {
                byte[] productName = new UTF8Encoding().GetBytes(this.CurrentProductItem1.Name);
                if (productName.Length > 20)
                {
                    for (int i = 0; i < 20; i++)
                        this.Current30000ModbusData1.ProductName[i] = productName[i];
                }
                else
                {
                    for (int i = 0; i < productName.Length; i++)
                        this.Current30000ModbusData1.ProductName[i] = productName[i];
                    for (int i = productName.Length; i < 20; i++)
                        this.Current30000ModbusData1.ProductName[i] = 0x20;
                }

                // 로그
                //if (this.IsCommunicationLogOpen == true)
                //{
                //    this.smartFileCommunicationLog.WriteString(string.Format("Update30000ModbusItem ({0:yyyy-MM-dd HH:mm:ss}): {1}, {2}", DateTime.Now, BitConverter.ToString(productName), productName.Length));
                //}
            }
            catch
            {
                byte[] productName = new UTF8Encoding().GetBytes(this.SystemConfig.ProductNumber.ToString() + "_Name");
                for (int i = 0; i < productName.Length; i++)
                    this.Current30000ModbusData1.ProductName[i] = productName[i];
                for (int i = productName.Length; i < 20; i++)
                    this.Current30000ModbusData1.ProductName[i] = 0x20;
            }

            this.ChildFormMainDisplay.MainModbus.UpdateData(this.Current30000ModbusData1);
        }
        public void Update31000ModbusAlarmItem()
        {

        }
        /// <summary>
        /// Modbus RTU - Write Multiple Register에 대한 Manage 메소드
        /// </summary>
        /// <param name="readByte">전송받은 Modbus Data</param>
        public void ReceiveModbusRTUWriteManager(byte[] readByte)
        {
            int startAddressInt;
            int numberOfRegisterInt;
            float floatNum;
            byte[] startAddressByte = new byte[2] { readByte[2], readByte[3] };
            byte[] numberOfRegisterByte = new byte[2] { readByte[4], readByte[5] };

            int madeDataIndex = 0;
            byte[] Length2Value = new byte[2];
            byte[] Length4Value = new byte[4];
            byte[] Length12Value = new byte[12];
            byte[] Length14Value = new byte[14];

            startAddressInt = Modbus.ToBigEndianAndInt(startAddressByte);
            numberOfRegisterInt = Modbus.ToBigEndianAndInt(numberOfRegisterByte);

            try
            {
                for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
                {
                    switch (j)
                    {
                        #region Change data
                        case _40000_ModbusAddress._01_Clear:
                            #region 40011_소거 요청
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40011_Clear = Modbus.ToBigEndianAndInt(Length2Value);

                            if (this.Current40000ModbusData1._40011_Clear == 1)
                            {
                                try
                                {
                                    this.ChildFormMainDisplay.Clear();
                                    this.Current40000ModbusData1._40011_Clear = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40012_ClearResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40012_ClearResult = 2;
                                }
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._02_ClearResult:
                            #region 40012_소거 요청 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40012_ClearResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._03_Operation:
                            #region 40013_운전/정지 요청, 1:운전/2:정지
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40013_Operation = Modbus.ToBigEndianAndInt(Length2Value);

                            if (this.Current40000ModbusData1._40013_Operation != 0)
                            {
                                try
                                {
                                    if (this.Current40000ModbusData1._40013_Operation == 1)
                                    {
                                        this.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
                                    }
                                    else
                                    {
                                        this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                                    }

                                    this.Current40000ModbusData1._40013_Operation = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40014_OperationResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40014_OperationResult = 2;
                                }
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._04_OperationResult:
                            #region 40014_운전/정지 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40014_OperationResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._05_ProductChange_High:
                            #region 40015_품번 변경 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40015_ProductChange = Modbus.ToBigEndianAndInt(Length4Value);

                            if (this.Current40000ModbusData1._40015_ProductChange != 0)
                            {
                                try
                                {
                                    if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                    {
                                        if (this.Current40000ModbusData1._40015_ProductChange >= 1
                                            && this.Current40000ModbusData1._40015_ProductChange <= 1000)
                                            this.ChildFormMainDisplay.ProductChange(this.Current40000ModbusData1._40015_ProductChange);

                                        this.Current40000ModbusData1._40015_ProductChange = 0;

                                        // 성공
                                        this.Current40000ModbusData1._40017_ProductChangeResult = 1;
                                    }
                                    else
                                    {
                                        this.Current40000ModbusData1._40015_ProductChange = 0;
                                        this.Current40000ModbusData1._40017_ProductChangeResult = 2;
                                    }
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40017_ProductChangeResult = 2;
                                }
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._07_ProductChangeResult:
                            #region 40017_품번 변경 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40017_ProductChangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._08_UnderRange1_High:
                            #region 40018_Under 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._40018_UnderRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._40018_UnderRange >= 0 && this.Current40000ModbusData1._40018_UnderRange <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem1.UnderRange = this.Current40000ModbusData1._40018_UnderRange.ToString();

                                    this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._40018_UnderRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40020_UnderRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40020_UnderRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._40020_UnderRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._10_UnderRangeResult1:
                            #region 40020_Under 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40020_UnderRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._11_PassRange1_High:
                            #region 40021_Pass 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._40021_PassRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._40021_PassRange >= 0 && this.Current40000ModbusData1._40021_PassRange <= 99999)
                            {
                                try
                                {
                                    string value = "";
                                    int digit = 0, temp = 0;
                                    int oldUnderRangeDeviation = this.CurrentProductItem1.UnderRangeDeviation;
                                    int oldOverRangeDeviation = this.CurrentProductItem1.OverRangeDeviation;

                                    this.CurrentProductItem1.PassRange = this.Current40000ModbusData1._40021_PassRange.ToString();

                                    #region UnderRange
                                    temp = this.CurrentProductItem1.PassRangeInt + oldUnderRangeDeviation;
                                    if (temp < 0)
                                        value = "0";
                                    else
                                        value = temp.ToString();

                                    this.CurrentProductItem1.UnderRange = value;
                                    #endregion

                                    #region OverRange
                                    temp = this.CurrentProductItem1.PassRangeInt + oldOverRangeDeviation;
                                    if (temp > 99999)
                                        value = "99999";
                                    else
                                        value = temp.ToString();

                                    this.CurrentProductItem1.OverRange = value;
                                    #endregion

                                    this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._40021_PassRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40023_PassRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40023_PassRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._40023_PassRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._13_PassRangeResult1:
                            #region 40023_Pass 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40023_PassRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._14_OverRange1_High:
                            #region 40024_Over 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._40024_OverRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._40024_OverRange >= 0 && this.Current40000ModbusData1._40024_OverRange <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem1.OverRange = this.Current40000ModbusData1._40024_OverRange.ToString();

                                    this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._40024_OverRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40026_OverRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40026_OverRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._40026_OverRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._16_OverRangeResult1:
                            #region 40026_Over 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40026_OverRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._17_TareWeight1_High:
                            #region 40027_Tare 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._40027_TareWeight =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._40027_TareWeight >= 0 && this.Current40000ModbusData1._40027_TareWeight <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem1.TareRange = this.Current40000ModbusData1._40027_TareWeight.ToString();

                                    this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._40027_TareWeight = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40029_TareWeightResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._40029_TareWeightResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._40029_TareWeightResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._19_TareWeightResult1:
                            #region 40029_Tare 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._40029_TareWeightResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._20_UnderRange2_High:
                            #region 42018_Under 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._42018_UnderRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._42018_UnderRange >= 0 && this.Current40000ModbusData1._42018_UnderRange <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem2.UnderRange = this.Current40000ModbusData1._42018_UnderRange.ToString();

                                    this.SaveProductFile2(this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem2(this.CurrentProductItem2);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._42018_UnderRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._42020_UnderRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._42020_UnderRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._42020_UnderRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._22_UnderRangeResult2:
                            #region 42020_Under 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._42020_UnderRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._23_PassRange2_High:
                            #region 42021_Pass 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._42021_PassRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._42021_PassRange >= 0 && this.Current40000ModbusData1._42021_PassRange <= 99999)
                            {
                                try
                                {
                                    string value = "";
                                    int digit = 0, temp = 0;
                                    int oldUnderRangeDeviation = this.CurrentProductItem2.UnderRangeDeviation;
                                    int oldOverRangeDeviation = this.CurrentProductItem2.OverRangeDeviation;

                                    this.CurrentProductItem2.PassRange = this.Current40000ModbusData1._42021_PassRange.ToString();

                                    #region UnderRange
                                    temp = this.CurrentProductItem2.PassRangeInt + oldUnderRangeDeviation;
                                    if (temp < 0)
                                        value = "0";
                                    else
                                        value = temp.ToString();

                                    this.CurrentProductItem2.UnderRange = value;
                                    #endregion

                                    #region OverRange
                                    temp = this.CurrentProductItem2.PassRangeInt + oldOverRangeDeviation;
                                    if (temp > 99999)
                                        value = "99999";
                                    else
                                        value = temp.ToString();

                                    this.CurrentProductItem2.OverRange = value;
                                    #endregion

                                    this.SaveProductFile2(this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem2(this.CurrentProductItem2);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._42021_PassRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._42023_PassRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._42023_PassRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._42023_PassRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._25_PassRangeResult2:
                            #region 42023_Pass 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._42023_PassRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._26_OverRange2_High:
                            #region 42024_Over 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._42024_OverRange =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._42024_OverRange >= 0 && this.Current40000ModbusData1._42024_OverRange <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem2.OverRange = this.Current40000ModbusData1._42024_OverRange.ToString();

                                    this.SaveProductFile2(this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem2(this.CurrentProductItem2);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._42024_OverRange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._42026_OverRangeResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._42026_OverRangeResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._42026_OverRangeResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._28_OverRangeResult2:
                            #region 42026_Over 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._42026_OverRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        case _40000_ModbusAddress._29_TareWeight2_High:
                            #region 42027_Tare 중량설정 요청
                            for (int i = 0; i < 4; i++)
                                Length4Value[i] = readByte[7 + madeDataIndex + i];
                            floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                            this.Current40000ModbusData1._42027_TareWeight =
                                int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                            if (this.Current40000ModbusData1._42027_TareWeight >= 0 && this.Current40000ModbusData1._42027_TareWeight <= 99999)
                            {
                                try
                                {
                                    this.CurrentProductItem2.TareRange = this.Current40000ModbusData1._42027_TareWeight.ToString();

                                    this.SaveProductFile2(this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
                                    this.TransferCurrentProductItem2(this.CurrentProductItem2);

                                    this.Update30000ModbusItem();
                                    this.UpdateScreen();

                                    // 초기값으로 설정해놓기
                                    this.Current40000ModbusData1._42027_TareWeight = 0;

                                    // 성공
                                    this.Current40000ModbusData1._42029_TareWeightResult = 1;
                                }
                                catch
                                {
                                    // 실패
                                    this.Current40000ModbusData1._42029_TareWeightResult = 2;
                                }
                            }
                            else
                            {
                                // 실패
                                this.Current40000ModbusData1._42029_TareWeightResult = 2;
                            }
                            #endregion
                            break;
                        case _40000_ModbusAddress._31_TareWeightResult2:
                            #region 42029_Tare 중량설정 요청 수행 결과
                            for (int i = 0; i < 2; i++)
                                Length2Value[i] = readByte[7 + madeDataIndex + i];
                            this.Current40000ModbusData1._42029_TareWeightResult = Modbus.ToBigEndianAndInt(Length2Value);
                            #endregion
                            break;
                        default:
                            break;
                        #endregion
                    }
                    madeDataIndex += 2;
                }
            }
            catch
            {

            }
        }
        /// <summary>
        /// Modbus TCP - Write Multiple Register에 대한 Manage 메소드
        /// </summary>
        /// <param name="readByte">전송받은 Modbus Data</param>
        public void ReceiveModbusTCPWriteManager(byte[] readByte)
        {
            int startAddressInt;
            int numberOfRegisterInt;
            float floatNum;
            byte[] startAddressByte = new byte[2] { readByte[8], readByte[9] };
            byte[] numberOfRegisterByte = new byte[2] { readByte[10], readByte[11] };

            int madeDataIndex = 0;
            byte[] Length2Value = new byte[2];
            byte[] Length4Value = new byte[4];
            byte[] Length12Value = new byte[12];
            byte[] Length14Value = new byte[14];

            startAddressInt = Modbus.ToBigEndianAndInt(startAddressByte);
            numberOfRegisterInt = Modbus.ToBigEndianAndInt(numberOfRegisterByte);

            for (int j = startAddressInt; j < startAddressInt + numberOfRegisterInt; j++)
            {
                switch (j)
                {
                    #region Change data
                    case _40000_ModbusAddress._01_Clear:
                        #region 40011_소거 요청
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40011_Clear = Modbus.ToBigEndianAndInt(Length2Value);

                        if (this.Current40000ModbusData1._40011_Clear == 1)
                        {
                            try
                            {
                                this.ChildFormMainDisplay.Clear();
                                this.Current40000ModbusData1._40011_Clear = 0;

                                // 성공
                                this.Current40000ModbusData1._40012_ClearResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40012_ClearResult = 2;
                            }
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._02_ClearResult:
                        #region 40012_소거 요청 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40012_ClearResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._03_Operation:
                        #region 40013_운전/정지 요청, 1:운전/2:정지
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40013_Operation = Modbus.ToBigEndianAndInt(Length2Value);

                        if (this.Current40000ModbusData1._40013_Operation != 0)
                        {
                            try
                            {
                                if (this.Current40000ModbusData1._40013_Operation == 1)
                                {
                                    this.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
                                }
                                else
                                {
                                    this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                                }

                                this.Current40000ModbusData1._40013_Operation = 0;

                                // 성공
                                this.Current40000ModbusData1._40014_OperationResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40014_OperationResult = 2;
                            }
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._04_OperationResult:
                        #region 40014_운전/정지 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40014_OperationResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._05_ProductChange_High:
                        #region 40015_품번 변경 요청
                        for (int i = 0; i < 4; i++)
                            Length4Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40015_ProductChange = Modbus.ToBigEndianAndInt(Length4Value);

                        if (this.Current40000ModbusData1._40015_ProductChange != 0)
                        {
                            try
                            {
                                if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                                {
                                    if (this.Current40000ModbusData1._40015_ProductChange >= 1
                                        && this.Current40000ModbusData1._40015_ProductChange <= 1000)
                                        this.ChildFormMainDisplay.ProductChange(this.Current40000ModbusData1._40015_ProductChange);

                                    this.Current40000ModbusData1._40015_ProductChange = 0;

                                    // 성공
                                    this.Current40000ModbusData1._40017_ProductChangeResult = 1;
                                }
                                else
                                {
                                    this.Current40000ModbusData1._40015_ProductChange = 0;
                                    this.Current40000ModbusData1._40017_ProductChangeResult = 2;
                                }
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40017_ProductChangeResult = 2;
                            }
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._07_ProductChangeResult:
                        #region 40017_품번 변경 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40017_ProductChangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._08_UnderRange1_High:
                        #region 40018_Under 중량설정 요청
                        for (int i = 0; i < 4; i++)
                            Length4Value[i] = readByte[13 + madeDataIndex + i];
                        floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                        this.Current40000ModbusData1._40018_UnderRange =
                            int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                        if (this.Current40000ModbusData1._40018_UnderRange >= 0 && this.Current40000ModbusData1._40018_UnderRange <= 99999)
                        {
                            try
                            {
                                this.CurrentProductItem1.UnderRange = this.Current40000ModbusData1._40018_UnderRange.ToString();

                                this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                this.Update30000ModbusItem();
                                this.UpdateScreen();

                                // 초기값으로 설정해놓기
                                this.Current40000ModbusData1._40018_UnderRange = 0;

                                // 성공
                                this.Current40000ModbusData1._40020_UnderRangeResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40020_UnderRangeResult = 2;
                            }
                        }
                        else
                        {
                            // 실패
                            this.Current40000ModbusData1._40020_UnderRangeResult = 2;
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._10_UnderRangeResult1:
                        #region 40020_Under 중량설정 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40020_UnderRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._11_PassRange1_High:
                        #region 40021_Pass 중량설정 요청
                        for (int i = 0; i < 4; i++)
                            Length4Value[i] = readByte[13 + madeDataIndex + i];
                        floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                        this.Current40000ModbusData1._40021_PassRange =
                            int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                        if (this.Current40000ModbusData1._40021_PassRange >= 0 && this.Current40000ModbusData1._40021_PassRange <= 99999)
                        {
                            try
                            {
                                string value = "";
                                int digit = 0, temp = 0;
                                int oldUnderRangeDeviation = this.CurrentProductItem1.UnderRangeDeviation;
                                int oldOverRangeDeviation = this.CurrentProductItem1.OverRangeDeviation;

                                this.CurrentProductItem1.PassRange = this.Current40000ModbusData1._40021_PassRange.ToString();

                                #region UnderRange
                                temp = this.CurrentProductItem1.PassRangeInt + oldUnderRangeDeviation;
                                if (temp < 0)
                                    value = "0";
                                else
                                    value = temp.ToString();

                                this.CurrentProductItem1.UnderRange = value;
                                #endregion

                                #region OverRange
                                temp = this.CurrentProductItem1.PassRangeInt + oldOverRangeDeviation;
                                if (temp > 99999)
                                    value = "99999";
                                else
                                    value = temp.ToString();

                                this.CurrentProductItem1.OverRange = value;
                                #endregion

                                this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                this.Update30000ModbusItem();
                                this.UpdateScreen();

                                // 초기값으로 설정해놓기
                                this.Current40000ModbusData1._40021_PassRange = 0;

                                // 성공
                                this.Current40000ModbusData1._40023_PassRangeResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40023_PassRangeResult = 2;
                            }
                        }
                        else
                        {
                            // 실패
                            this.Current40000ModbusData1._40023_PassRangeResult = 2;
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._13_PassRangeResult1:
                        #region 40023_Pass 중량설정 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40023_PassRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._14_OverRange1_High:
                        #region 40024_Over 중량설정 요청
                        for (int i = 0; i < 4; i++)
                            Length4Value[i] = readByte[13 + madeDataIndex + i];
                        floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                        this.Current40000ModbusData1._40024_OverRange =
                            int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                        if (this.Current40000ModbusData1._40024_OverRange >= 0 && this.Current40000ModbusData1._40024_OverRange <= 99999)
                        {
                            try
                            {
                                this.CurrentProductItem1.OverRange = this.Current40000ModbusData1._40024_OverRange.ToString();

                                this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                this.Update30000ModbusItem();
                                this.UpdateScreen();

                                // 초기값으로 설정해놓기
                                this.Current40000ModbusData1._40024_OverRange = 0;

                                // 성공
                                this.Current40000ModbusData1._40026_OverRangeResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40026_OverRangeResult = 2;
                            }
                        }
                        else
                        {
                            // 실패
                            this.Current40000ModbusData1._40026_OverRangeResult = 2;
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._16_OverRangeResult1:
                        #region 40026_Over 중량설정 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40026_OverRangeResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    case _40000_ModbusAddress._17_TareWeight1_High:
                        #region 40027_Tare 중량설정 요청
                        for (int i = 0; i < 4; i++)
                            Length4Value[i] = readByte[13 + madeDataIndex + i];
                        floatNum = Modbus.ToBigEndianAndFloat(Length4Value);
                        this.Current40000ModbusData1._40027_TareWeight =
                            int.Parse(Helper.DoubleToString((double)floatNum, this.SystemConfig.DecimalPlaces).Replace(".", ""));

                        if (this.Current40000ModbusData1._40027_TareWeight >= 0 && this.Current40000ModbusData1._40027_TareWeight <= 99999)
                        {
                            try
                            {
                                this.CurrentProductItem1.TareRange = this.Current40000ModbusData1._40027_TareWeight.ToString();

                                this.SaveProductFile1(this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                                this.TransferCurrentProductItem1(this.CurrentProductItem1);

                                this.Update30000ModbusItem();
                                this.UpdateScreen();

                                // 초기값으로 설정해놓기
                                this.Current40000ModbusData1._40027_TareWeight = 0;

                                // 성공
                                this.Current40000ModbusData1._40029_TareWeightResult = 1;
                            }
                            catch
                            {
                                // 실패
                                this.Current40000ModbusData1._40029_TareWeightResult = 2;
                            }
                        }
                        else
                        {
                            // 실패
                            this.Current40000ModbusData1._40029_TareWeightResult = 2;
                        }
                        #endregion
                        break;
                    case _40000_ModbusAddress._19_TareWeightResult1:
                        #region 40029_Tare 중량설정 요청 수행 결과
                        for (int i = 0; i < 2; i++)
                            Length2Value[i] = readByte[13 + madeDataIndex + i];
                        this.Current40000ModbusData1._40029_TareWeightResult = Modbus.ToBigEndianAndInt(Length2Value);
                        #endregion
                        break;
                    default:
                        break;
                    #endregion
                }
                madeDataIndex += 2;
            }
        }
        #endregion

        #region Ethernet
        public void IsUsingTimerEthernetPing(bool bValue)
        {
            if (this.SystemConfig.IsEthernetPingTimer == true)
            {
                this.timerEthernetPing.Enabled = bValue;
            }
            else
                this.timerEthernetPing.Enabled = false;
        }

        #region Client
        public void EthernetClientConnect()
        {
            if (this.IsEthernetThreadStop == false)
                return;  // Online 경우 
            if (this.SystemConfig.IsEthernetEnable == false)
            {
                this.TextStatusOut("<Disable");
                return;
            }

            if (string.Compare(this.SystemConfig.EthernetAddress, "0.0.0.0") == 0)
            {
                this.TextStatusOut("<Addr Err");
                return;
            }

            try
            {
                Thread cpClientThread = new Thread(new ThreadStart(EthernetClientReceiveThread));

                cpClientThread.IsBackground = true;

                cpClientThread.Start();

                //this.IsUsingTimerEthernetPing(true);
            }
            catch
            {
                TextStatusOut(">Thread Error");
            }
        }
        public void EthernetClientDisconnect()
        {
            this.IsUsingTimerEthernetPing(false);

            this.DelegateUISeverStatus(false);
            if (null != this.EthernetStmReader)
                this.EthernetStmReader.Close();

            if (null != this.EthernetStmWriter)
                this.EthernetStmWriter.Close();

            if (null != this.EthernetNetStream)
                this.EthernetNetStream.Close();

            if (null != this.EthernetTcpClient)
                this.EthernetTcpClient.Close();

            this.IsEthernetThreadStop = true;
            this.DelegateTextStatusOut(">Disconnected");
            //this.SetTrackingHistoryData(Define.E_TrackingOperation.ClientDisconnect, "");

            if (this.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Start
                && this.CurrentSystemStatus.CurrentDisplay == Define.E_DisplayStore.MainDisplay)
                this.DelegateTimerTryConnect(true);
        }

        private void EthernetClientReceiveThread()
        {
            int nConnectPort = Convert.ToInt32(this.SystemConfig.EthernetHostPort);
            try
            {
                this.DelegateTextStatusOut(">Now Connecting..");
                this.EthernetTcpClient = new TcpClient(this.SystemConfig.EthernetAddress, nConnectPort);

                this.EthernetNetStream = this.EthernetTcpClient.GetStream();
                this.EthernetStmReader = new StreamReader(this.EthernetNetStream);
                this.EthernetStmWriter = new StreamWriter(this.EthernetNetStream);

                this.DelegateUISeverStatus(true);
                this.DelegateTextStatusOut(">Connected Server");
                //this.SetTrackingHistoryData(Define.E_TrackingOperation.ClientConnect, "");

                this.IsEthernetThreadStop = false;

                // 판정 데이터 전송
                if (this.IsEthernetTransferData == true)
                {
                    this.IsEthernetTransferData = false;
                    Type type = this.EthernetTransferData.GetType();
                    if (type == typeof(string))
                        this.DelegateTransferData((string)this.EthernetTransferData);
                    else if (type == typeof(byte[]))
                        this.DelegateTransferData((byte[])this.EthernetTransferData);
                    else if (type == typeof(byte))
                        this.DelegateTransferData((byte)this.EthernetTransferData);
                }

                char[] charArray = new char[20];

                while (this.IsEthernetThreadStop == false)
                {
                    var strRecDataCount = this.EthernetStmReader.Read(charArray, 0, charArray.Length);
                    var strRecData = new string(charArray, 0, strRecDataCount);

                    //Console.Write("\n" + string.Format("EthernetStmReader.Read {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, strRecData));

                    if (null == strRecData)
                    {
                        this.DelegateTextStatusOut(">Server Out");
                        this.IsEthernetThreadStop = true;
                        break;
                    }

                    this.DelegateTextStatusOut(strRecData);
                }
            }
            catch
            {
                this.DelegateTextStatusOut(">Connect Fail !");
            }
            finally
            {
                this.EthernetClientDisconnect();
            }

            return;
        }

        private void UIServerStatus(bool status)
        {
            this.ChildFormMainDisplay.UpdateEthernetStatusDisplay(status);
        }
        public void DelegateUISeverStatus(bool status)
        {
            this.Invoke(new UIServerStatusCallback(this.UIServerStatus), status);
        }

        private void TextStatusOut(string value)
        {
            if (this.ChildFormMenu.CenterConfiEthernet != null)
                this.ChildFormMenu.CenterConfiEthernet.UpdateEthernetStatusDisplay(value);
        }
        private void DelegateTextStatusOut(string value)
        {
            this.Invoke(new TextStatusCallback(this.TextStatusOut), value);
        }

        private void TimerTryConnect(bool status)
        {
            this.timerClientTryConnect.Enabled = status;
        }
        private void DelegateTimerTryConnect(bool status)
        {
            this.Invoke(new TimerTryConnectCallback(this.TimerTryConnect), status);
        }

        private void DelegateTransferData(string data)
        {
            this.Invoke(new TransferStringDataCallback(this.EthernetSendMessage), data);
        }
        private void DelegateTransferData(byte[] data)
        {
            this.Invoke(new TransferByteArrayDataCallback(this.EthernetSendMessage), data);
        }
        private void DelegateTransferData(byte data)
        {
            this.Invoke(new TransferByteDataCallback(this.EthernetSendMessage), data);
        }
        public void EthernetSendMessage(string msg)
        {
            try
            {
                this.EthernetStmWriter.Write(msg);
                this.EthernetStmWriter.Flush();
            }
            catch
            {
                this.DelegateUISeverStatus(false);
                this.DelegateTextStatusOut("> Disconnect");
            }
        }
        public void EthernetSendMessage(byte[] msg)
        {
            try
            {
                this.EthernetStmWriter.BaseStream.Write(msg, 0, msg.Length);
                this.EthernetStmWriter.Flush();
            }
            catch
            {
                this.DelegateUISeverStatus(false);
                this.DelegateTextStatusOut("> Disconnect");
            }
        }
        public void EthernetSendMessage(byte msg)
        {
            try
            {
                this.EthernetStmWriter.Write(msg);
                this.EthernetStmWriter.Flush();
            }
            catch
            {
                this.DelegateUISeverStatus(false);
                this.DelegateTextStatusOut("> Disconnect");
            }
        }
        public void EthernetWeightData(string strTemp)
        {
            this.IsEthernetTransferData = true;
            this.EthernetTransferData = strTemp;

            if (this.IsEthernetThreadStop == true)
                this.EthernetClientConnect();
            else
                this.EthernetSendMessage((string)this.EthernetTransferData);
        }
        public void EthernetWeightData(byte[] bytes)
        {
            this.IsEthernetTransferData = true;
            this.EthernetTransferData = bytes;

            if (this.IsEthernetThreadStop == true)
                this.EthernetClientConnect();
            else
                this.EthernetSendMessage(bytes);
        }
        public void EthernetWeightDataForModbus(byte[] bytes)
        {
            this.IsEthernetTransferData = true;
            this.EthernetTransferData = bytes;

            if (this.IsEthernetThreadStop == true)
                this.EthernetClientConnect();
            else
                this.EthernetSendMessage(bytes);
        }
        #endregion

        #region Server
        public void EthernetServerStart()
        {
            if (this.smartTCPMultiServer.IsStart == false)
            {
                this.IsUsingTimerEthernetPing(true);
                this.ChildFormMenu.CenterConfiEthernet.DisplayLabelLocalPort(false);
                this.smartTCPMultiServer.Port = this.SystemConfig.EthernetLocalPort;
                this.smartTCPMultiServer.Start();
            }
        }
        public void EthernetServerStop()
        {
            if (this.smartTCPMultiServer.IsStart == true)
            {
                this.IsUsingTimerEthernetPing(false);
                this.ChildFormMenu.CenterConfiEthernet.DisplayLabelLocalPort(true);
                this.smartTCPMultiServer.Stop();
            }
        }
        public void EthernetServerSendMessage(SmartTCPMultiServer.CLIENTSINFOS client, string msg)
        {
            if (this.smartTCPMultiServer.SendStringASCIIID(client.strID, msg) == true)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Ethernet Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, msg));
            }
        }
        public void EthernetServerSendMessage(SmartTCPMultiServer.CLIENTSINFOS client, byte[] bytes)
        {
            if (this.smartTCPMultiServer.SendByteByClientID(client.strID, bytes) == true)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(string.Format("Ethernet Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, Encoding.Default.GetString(bytes, 0, bytes.Length)));
            }
        }
        #endregion

        #endregion

        #region SystemConfiguration File1
        private void CreateSystemConfigurationFile1()
        {
            StructSystemConfigurationItem1 structItem;

            this.SystemConfig.Initialization();

            structItem.IsDataBackup = this.SystemConfig.IsDataBackup;
            structItem.IsLogin = this.SystemConfig.IsLogin;

            structItem.EquipmentID = this.SystemConfig.EquipmentID;
            structItem.DecimalPlaces = this.SystemConfig.DecimalPlaces;
            structItem.ProductNumber = this.SystemConfig.ProductNumber;
            structItem.UsbID = this.SystemConfig.UsbID;
            structItem.SerialCOM1BaudRate = this.SystemConfig.SerialCOM1BaudRate;
            structItem.SerialCOM1Mode = this.SystemConfig.SerialCOM1Mode;
            structItem.SerialCOM3BaudRate = this.SystemConfig.SerialCOM3BaudRate;
            structItem.SerialCOM3Mode = this.SystemConfig.SerialCOM3Mode;
            structItem.SerialCOM4BaudRate = this.SystemConfig.SerialCOM4BaudRate;
            structItem.SerialCOM4Mode = this.SystemConfig.SerialCOM4Mode;

            structItem.SerialNumber = this.SystemConfig.SerialNumber;
            structItem.Language = this.SystemConfig.Language;
            structItem.Unit = this.SystemConfig.Unit;

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.IsPrintPerProductEnable = this.SystemConfig.IsPrintPerProductEnable;
            structItem.DummyInt1 = 1;
            structItem.DummyInt2 = 1;
            structItem.EntryNotDetectedIgnoreTime = this.SystemConfig.EntryNotDetectedIgnoreTime;
            structItem.SensorErrorDetectingTime = this.SystemConfig.SensorErrorDetectingTime;
            structItem.EquipmentType = this.SystemConfig.EquipmentType;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, 0);
        }
        public void SaveSystemConfigurationFile1(SystemConfigurationItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem1 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile1();
                this.CreateSystemConfigurationFile2();
            }

            structItem.IsDataBackup = item.IsDataBackup;
            structItem.IsLogin = item.IsLogin;

            structItem.EquipmentID = item.EquipmentID;
            structItem.DecimalPlaces = item.DecimalPlaces;
            structItem.ProductNumber = item.ProductNumber;
            structItem.UsbID = item.UsbID;
            structItem.SerialCOM1BaudRate = item.SerialCOM1BaudRate;
            structItem.SerialCOM1Mode = item.SerialCOM1Mode;
            structItem.SerialCOM3BaudRate = item.SerialCOM3BaudRate;
            structItem.SerialCOM3Mode = item.SerialCOM3Mode;
            structItem.SerialCOM4BaudRate = item.SerialCOM4BaudRate;
            structItem.SerialCOM4Mode = item.SerialCOM4Mode;

            structItem.SerialNumber = item.SerialNumber;
            structItem.Language = item.Language;
            structItem.Unit = item.Unit;

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.IsPrintPerProductEnable = item.IsPrintPerProductEnable;
            structItem.DummyInt1 = 1;
            structItem.DummyInt2 = 1;
            structItem.EntryNotDetectedIgnoreTime = item.EntryNotDetectedIgnoreTime;
            structItem.SensorErrorDetectingTime = item.SensorErrorDetectingTime;
            structItem.EquipmentType = item.EquipmentType;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, 0);
            this.smartFileIO.Close();
        }
        public void LoadSystemConfigurationFile1()
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem1 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile1();
                this.CreateSystemConfigurationFile2();
            }

            try
            {
                structItem = (StructSystemConfigurationItem1)this.smartFileIO.ReadStructure(0, typeof(StructSystemConfigurationItem1));

                this.SystemConfig.IsDataBackup = structItem.IsDataBackup;
                this.SystemConfig.IsLogin = structItem.IsLogin;
                this.SystemConfig.IsPrintPerProductEnable = structItem.IsPrintPerProductEnable;

                this.SystemConfig.EquipmentID = structItem.EquipmentID;
                this.SystemConfig.DecimalPlaces = structItem.DecimalPlaces;
                this.SystemConfig.ProductNumber = structItem.ProductNumber;
                this.SystemConfig.UsbID = structItem.UsbID;
                this.SystemConfig.SerialCOM1BaudRate = structItem.SerialCOM1BaudRate;
                this.SystemConfig.SerialCOM1Mode = structItem.SerialCOM1Mode;
                this.SystemConfig.SerialCOM3BaudRate = structItem.SerialCOM3BaudRate;
                this.SystemConfig.SerialCOM3Mode = structItem.SerialCOM3Mode;
                this.SystemConfig.SerialCOM4BaudRate = structItem.SerialCOM4BaudRate;
                this.SystemConfig.SerialCOM4Mode = structItem.SerialCOM4Mode;

                this.SystemConfig.SerialNumber = structItem.SerialNumber;
                this.SystemConfig.Language = structItem.Language;
                this.SystemConfig.Unit = structItem.Unit;

                this.SystemConfig.EquipmentType = structItem.EquipmentType;
                this.SystemConfig.SensorErrorDetectingTime = structItem.SensorErrorDetectingTime;
                this.SystemConfig.EntryNotDetectedIgnoreTime = structItem.EntryNotDetectedIgnoreTime;
            }
            catch
            {
                // 초기화를 실행해 주세요
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion
        #region SystemConfiguration File2
        private void CreateSystemConfigurationFile2()
        {
            StructSystemConfigurationItem2 structItem;

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.DummyBool5 = false;
            structItem.DummyBool6 = false;
            structItem.DummyBool7 = false;
            structItem.DummyBool8 = false;
            structItem.DummyBool9 = false;
            structItem.DummyBool10 = false;
            structItem.DummyBool11 = false;
            structItem.DummyBool12 = false;
            structItem.DummyBool13 = false;
            structItem.DummyBool14 = false;
            structItem.DummyBool15 = false;
            structItem.DummyBool16 = false;
            structItem.DummyBool17 = false;
            structItem.DummyBool18 = false;
            structItem.DummyBool19 = false;
            structItem.IsModbus = this.SystemConfig.IsModbus;
            structItem.IsPart11 = this.SystemConfig.IsPart11;
            structItem.IsEthernetPingTimer = this.SystemConfig.IsEthernetPingTimer;
            structItem.IsCharToFillZeroEthernet = this.SystemConfig.IsCharToFillZeroEthernet;
            structItem.IsTransmitWhenPassEthernet = this.SystemConfig.IsTransmitWhenPassEthernet;
            structItem.IsCharToFillZeroCOM1 = this.SystemConfig.IsCharToFillZeroCOM1;
            structItem.IsTransmitWhenPassCOM1 = this.SystemConfig.IsTransmitWhenPassCOM1;
            structItem.IsCharToFillZeroCOM3 = this.SystemConfig.IsCharToFillZeroCOM3;
            structItem.IsTransmitWhenPassCOM3 = this.SystemConfig.IsTransmitWhenPassCOM3;
            structItem.IsCharToFillZeroCOM4 = this.SystemConfig.IsCharToFillZeroCOM4;
            structItem.IsTransmitWhenPassCOM4 = this.SystemConfig.IsTransmitWhenPassCOM4;
            structItem.IsModbusRTUUsingConverterCOM1 = this.SystemConfig.IsModbusRTUUsingConverterCOM1;
            structItem.IsModbusRTUUsingConverterCOM3 = this.SystemConfig.IsModbusRTUUsingConverterCOM3;
            structItem.IsModbusRTUUsingConverterCOM4 = this.SystemConfig.IsModbusRTUUsingConverterCOM4;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;
            structItem.DummyInt6 = 0;
            structItem.DummyInt7 = 0;
            structItem.DummyInt8 = 0;
            structItem.DummyInt9 = 0;
            structItem.DummyInt10 = 0;
            structItem.DummyInt11 = 0;
            structItem.TransmissionDelayTimeEthernet = this.SystemConfig.TransmissionDelayTimeEthernet;
            structItem.SelectLaneCOM1 = this.SystemConfig.SelectLaneCOM1;
            structItem.SelectLaneCOM3 = this.SystemConfig.SelectLaneCOM3;
            structItem.SelectLaneCOM4 = this.SystemConfig.SelectLaneCOM4;
            structItem.SelectLaneEthernet = this.SystemConfig.SelectLaneEthernet;
            structItem.TransmissionDelayTimeCOM1 = this.SystemConfig.TransmissionDelayTimeCOM1;
            structItem.TransmissionDelayTimeCOM3 = this.SystemConfig.TransmissionDelayTimeCOM3;
            structItem.TransmissionDelayTimeCOM4 = this.SystemConfig.TransmissionDelayTimeCOM4;
            structItem.ModbusRTUSelectFunction = this.SystemConfig.ModbusRTUSelectFunction;
            structItem.ModbusRTUSlaveIDCOM1 = this.SystemConfig.ModbusRTUSlaveIDCOM1;
            structItem.ModbusRTUSlaveIDCOM3 = this.SystemConfig.ModbusRTUSlaveIDCOM3;
            structItem.ModbusRTUSlaveIDCOM4 = this.SystemConfig.ModbusRTUSlaveIDCOM4;
            structItem.ModbusTCPSelectFunction = this.SystemConfig.ModbusTCPSelectFunction;
            structItem.EthernetLocalPort = this.SystemConfig.EthernetLocalPort;
            structItem.EthernetHostPort = this.SystemConfig.EthernetHostPort;
            structItem.EthernetCommMode = this.SystemConfig.EthernetCommMode;
            structItem.EthernetOperationMode = this.SystemConfig.EthernetOperationMode;
            structItem.StoragePeriod = this.SystemConfig.StoragePeriod;
            structItem.NumberOfLoginFailures = this.SystemConfig.NumberOfLoginFailures;
            structItem.ModbusTCPStartAddress = this.SystemConfig.ModbusTCPStartAddress;
            structItem.ModbusRTUStartAddressCOM1 = this.SystemConfig.ModbusRTUStartAddressCOM1;
            structItem.ModbusRTUStartAddressCOM3 = this.SystemConfig.ModbusRTUStartAddressCOM3;
            structItem.ModbusRTUStartAddressCOM4 = this.SystemConfig.ModbusRTUStartAddressCOM4;
            structItem.CommunicationControlCharacter = this.SystemConfig.CommunicationControlCharacter;

            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";
            structItem.DummyString6 = "";
            structItem.DummyString7 = "";
            structItem.DummyString8 = "";
            structItem.DummyString9 = "";
            structItem.DummyString10 = "";
            structItem.UserGroupLevel1Name = this.SystemConfig.UserGroupLevel1Name;
            structItem.UserGroupLevel2Name = this.SystemConfig.UserGroupLevel2Name;
            structItem.UserGroupLevel3Name = this.SystemConfig.UserGroupLevel3Name;
            structItem.EthernetAddress = this.SystemConfig.EthernetAddress;

            this.smartFileIO.WriteStructure(structItem, 1);
        }
        public void SaveSystemConfigurationFile2(SystemConfigurationItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem2 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile1();
                this.CreateSystemConfigurationFile2();
            }

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.DummyBool5 = false;
            structItem.DummyBool6 = false;
            structItem.DummyBool7 = false;
            structItem.DummyBool8 = false;
            structItem.DummyBool9 = false;
            structItem.DummyBool10 = false;
            structItem.DummyBool11 = false;
            structItem.DummyBool12 = false;
            structItem.DummyBool13 = false;
            structItem.DummyBool14 = false;
            structItem.DummyBool15 = false;
            structItem.DummyBool16 = false;
            structItem.DummyBool17 = false;
            structItem.DummyBool18 = false;
            structItem.DummyBool19 = false;
            structItem.IsModbus = item.IsModbus;
            structItem.IsPart11 = item.IsPart11;
            structItem.IsEthernetPingTimer = item.IsEthernetPingTimer;
            structItem.IsCharToFillZeroEthernet = item.IsCharToFillZeroEthernet;
            structItem.IsTransmitWhenPassEthernet = item.IsTransmitWhenPassEthernet;
            structItem.IsCharToFillZeroCOM1 = item.IsCharToFillZeroCOM1;
            structItem.IsTransmitWhenPassCOM1 = item.IsTransmitWhenPassCOM1;
            structItem.IsCharToFillZeroCOM3 = item.IsCharToFillZeroCOM3;
            structItem.IsTransmitWhenPassCOM3 = item.IsTransmitWhenPassCOM3;
            structItem.IsCharToFillZeroCOM4 = item.IsCharToFillZeroCOM4;
            structItem.IsTransmitWhenPassCOM4 = item.IsTransmitWhenPassCOM4;
            structItem.IsModbusRTUUsingConverterCOM1 = item.IsModbusRTUUsingConverterCOM1;
            structItem.IsModbusRTUUsingConverterCOM3 = item.IsModbusRTUUsingConverterCOM3;
            structItem.IsModbusRTUUsingConverterCOM4 = item.IsModbusRTUUsingConverterCOM4;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;
            structItem.DummyInt6 = 0;
            structItem.DummyInt7 = 0;
            structItem.DummyInt8 = 0;
            structItem.DummyInt9 = 0;
            structItem.DummyInt10 = 0;
            structItem.DummyInt11 = 0;
            structItem.TransmissionDelayTimeEthernet = item.TransmissionDelayTimeEthernet;
            structItem.SelectLaneCOM1 = item.SelectLaneCOM1;
            structItem.SelectLaneCOM3 = item.SelectLaneCOM3;
            structItem.SelectLaneCOM4 = item.SelectLaneCOM4;
            structItem.SelectLaneEthernet = item.SelectLaneEthernet;
            structItem.TransmissionDelayTimeCOM1 = item.TransmissionDelayTimeCOM1;
            structItem.TransmissionDelayTimeCOM3 = item.TransmissionDelayTimeCOM3;
            structItem.TransmissionDelayTimeCOM4 = item.TransmissionDelayTimeCOM4;
            structItem.ModbusRTUSelectFunction = item.ModbusRTUSelectFunction;
            structItem.ModbusRTUSlaveIDCOM1 = item.ModbusRTUSlaveIDCOM1;
            structItem.ModbusRTUSlaveIDCOM3 = item.ModbusRTUSlaveIDCOM3;
            structItem.ModbusRTUSlaveIDCOM4 = item.ModbusRTUSlaveIDCOM4;
            structItem.ModbusTCPSelectFunction = item.ModbusTCPSelectFunction;
            structItem.EthernetLocalPort = item.EthernetLocalPort;
            structItem.EthernetHostPort = item.EthernetHostPort;
            structItem.EthernetCommMode = item.EthernetCommMode;
            structItem.EthernetOperationMode = item.EthernetOperationMode;
            structItem.StoragePeriod = item.StoragePeriod;
            structItem.NumberOfLoginFailures = item.NumberOfLoginFailures;
            structItem.ModbusTCPStartAddress = item.ModbusTCPStartAddress;
            structItem.ModbusRTUStartAddressCOM1 = item.ModbusRTUStartAddressCOM1;
            structItem.ModbusRTUStartAddressCOM3 = item.ModbusRTUStartAddressCOM3;
            structItem.ModbusRTUStartAddressCOM4 = item.ModbusRTUStartAddressCOM4;
            structItem.CommunicationControlCharacter = item.CommunicationControlCharacter;

            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";
            structItem.DummyString6 = "";
            structItem.DummyString7 = "";
            structItem.DummyString8 = "";
            structItem.DummyString9 = "";
            structItem.DummyString10 = "";
            structItem.UserGroupLevel1Name = item.UserGroupLevel1Name;
            structItem.UserGroupLevel2Name = item.UserGroupLevel2Name;
            structItem.UserGroupLevel3Name = item.UserGroupLevel3Name;
            structItem.EthernetAddress = item.EthernetAddress;

            this.smartFileIO.WriteStructure(structItem, 1);
            this.smartFileIO.Close();
        }
        public void LoadSystemConfigurationFile2()
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem2 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile1();
                this.CreateSystemConfigurationFile2();
            }

            try
            {
                try
                {
                    structItem = (StructSystemConfigurationItem2)this.smartFileIO.ReadStructure(1, typeof(StructSystemConfigurationItem2));
                }
                catch
                {
                    this.CreateSystemConfigurationFile2();
                    structItem = (StructSystemConfigurationItem2)this.smartFileIO.ReadStructure(1, typeof(StructSystemConfigurationItem2));
                }

                this.SystemConfig.IsModbus = structItem.IsModbus;
                this.SystemConfig.IsPart11 = structItem.IsPart11;
                this.SystemConfig.IsEthernetPingTimer = structItem.IsEthernetPingTimer;
                this.SystemConfig.IsCharToFillZeroEthernet = structItem.IsCharToFillZeroEthernet;
                this.SystemConfig.IsTransmitWhenPassEthernet = structItem.IsTransmitWhenPassEthernet;
                this.SystemConfig.IsCharToFillZeroCOM1 = structItem.IsCharToFillZeroCOM1;
                this.SystemConfig.IsTransmitWhenPassCOM1 = structItem.IsTransmitWhenPassCOM1;
                this.SystemConfig.IsCharToFillZeroCOM3 = structItem.IsCharToFillZeroCOM3;
                this.SystemConfig.IsTransmitWhenPassCOM3 = structItem.IsTransmitWhenPassCOM3;
                this.SystemConfig.IsCharToFillZeroCOM4 = structItem.IsCharToFillZeroCOM4;
                this.SystemConfig.IsTransmitWhenPassCOM4 = structItem.IsTransmitWhenPassCOM4;
                this.SystemConfig.IsModbusRTUUsingConverterCOM1 = structItem.IsModbusRTUUsingConverterCOM1;
                this.SystemConfig.IsModbusRTUUsingConverterCOM3 = structItem.IsModbusRTUUsingConverterCOM3;
                this.SystemConfig.IsModbusRTUUsingConverterCOM4 = structItem.IsModbusRTUUsingConverterCOM4;

                this.SystemConfig.TransmissionDelayTimeCOM1 = structItem.TransmissionDelayTimeCOM1;
                this.SystemConfig.TransmissionDelayTimeCOM3 = structItem.TransmissionDelayTimeCOM3;
                this.SystemConfig.TransmissionDelayTimeCOM4 = structItem.TransmissionDelayTimeCOM4;
                this.SystemConfig.TransmissionDelayTimeEthernet = structItem.TransmissionDelayTimeEthernet;
                this.SystemConfig.ModbusRTUSelectFunction = structItem.ModbusRTUSelectFunction;
                this.SystemConfig.ModbusRTUSlaveIDCOM1 = structItem.ModbusRTUSlaveIDCOM1;
                this.SystemConfig.ModbusRTUSlaveIDCOM3 = structItem.ModbusRTUSlaveIDCOM3;
                this.SystemConfig.ModbusRTUSlaveIDCOM4 = structItem.ModbusRTUSlaveIDCOM4;
                this.SystemConfig.ModbusTCPSelectFunction = structItem.ModbusTCPSelectFunction;
                this.SystemConfig.EthernetLocalPort = structItem.EthernetLocalPort;
                this.SystemConfig.EthernetHostPort = structItem.EthernetHostPort;
                this.SystemConfig.EthernetCommMode = structItem.EthernetCommMode;
                this.SystemConfig.EthernetOperationMode = structItem.EthernetOperationMode;
                this.SystemConfig.StoragePeriod = structItem.StoragePeriod;
                this.SystemConfig.NumberOfLoginFailures = structItem.NumberOfLoginFailures;
                this.SystemConfig.ModbusTCPStartAddress = structItem.ModbusTCPStartAddress;
                this.SystemConfig.ModbusRTUStartAddressCOM1 = structItem.ModbusRTUStartAddressCOM1;
                this.SystemConfig.ModbusRTUStartAddressCOM3 = structItem.ModbusRTUStartAddressCOM3;
                this.SystemConfig.ModbusRTUStartAddressCOM4 = structItem.ModbusRTUStartAddressCOM4;
                this.SystemConfig.CommunicationControlCharacter = structItem.CommunicationControlCharacter;
                this.SystemConfig.SelectLaneCOM1 = structItem.SelectLaneCOM1;
                this.SystemConfig.SelectLaneCOM3 = structItem.SelectLaneCOM3;
                this.SystemConfig.SelectLaneCOM4 = structItem.SelectLaneCOM4;
                this.SystemConfig.SelectLaneEthernet = structItem.SelectLaneEthernet;

                this.SystemConfig.UserGroupLevel1Name = structItem.UserGroupLevel1Name;
                this.SystemConfig.UserGroupLevel2Name = structItem.UserGroupLevel2Name;
                this.SystemConfig.UserGroupLevel3Name = structItem.UserGroupLevel3Name;
                this.SystemConfig.EthernetAddress = structItem.EthernetAddress;
            }
            catch
            {
                // 초기화를 실행해 주세요
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion

        #region SystemParameter3
        private void CreateSystemParameter3File()
        {
            StructSystemParameter3 structItem;

            this.CurrentSystemParameter3.Initialization();

            structItem.ExternalOut1Mode = this.CurrentSystemParameter3.ExternalOut1Mode;
            structItem.ExternalOut1DelayTime = this.CurrentSystemParameter3.ExternalOut1DelayTime;
            structItem.ExternalOut1RunTime = this.CurrentSystemParameter3.ExternalOut1RunTime;

            structItem.ExternalOut2Mode = this.CurrentSystemParameter3.ExternalOut2Mode;
            structItem.ExternalOut2DelayTime = this.CurrentSystemParameter3.ExternalOut2DelayTime;
            structItem.ExternalOut2RunTime = this.CurrentSystemParameter3.ExternalOut2RunTime;

            structItem.ExternalOut3Mode = this.CurrentSystemParameter3.ExternalOut3Mode;
            structItem.ExternalOut3DelayTime = this.CurrentSystemParameter3.ExternalOut3DelayTime;
            structItem.ExternalOut3RunTime = this.CurrentSystemParameter3.ExternalOut3RunTime;

            structItem.ExternalOut4Mode = this.CurrentSystemParameter3.ExternalOut4Mode;
            structItem.ExternalOut4DelayTime = this.CurrentSystemParameter3.ExternalOut4DelayTime;
            structItem.ExternalOut4RunTime = this.CurrentSystemParameter3.ExternalOut4RunTime;

            structItem.ExternalOut9Mode = this.CurrentSystemParameter3.ExternalOut9Mode;
            structItem.ExternalOut9DelayTime = this.CurrentSystemParameter3.ExternalOut9DelayTime;
            structItem.ExternalOut9RunTime = this.CurrentSystemParameter3.ExternalOut9RunTime;

            structItem.ExternalOut10Mode = this.CurrentSystemParameter3.ExternalOut10Mode;
            structItem.ExternalOut10DelayTime = this.CurrentSystemParameter3.ExternalOut10DelayTime;
            structItem.ExternalOut10RunTime = this.CurrentSystemParameter3.ExternalOut10RunTime;

            structItem.Dummy1 = "0";
            structItem.Dummy2 = "0";

            this.smartFileIO.WriteStructure(structItem, 0);
        }
        public void SaveSystemParameter3File(SystemParameter3 item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemParameter3 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "SystemParameter3.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemParameter3File();
            }

            structItem.ExternalOut1Mode = item.ExternalOut1Mode;
            structItem.ExternalOut1DelayTime = item.ExternalOut1DelayTime;
            structItem.ExternalOut1RunTime = item.ExternalOut1RunTime;

            structItem.ExternalOut2Mode = item.ExternalOut2Mode;
            structItem.ExternalOut2DelayTime = item.ExternalOut2DelayTime;
            structItem.ExternalOut2RunTime = item.ExternalOut2RunTime;

            structItem.ExternalOut3Mode = item.ExternalOut3Mode;
            structItem.ExternalOut3DelayTime = item.ExternalOut3DelayTime;
            structItem.ExternalOut3RunTime = item.ExternalOut3RunTime;

            structItem.ExternalOut4Mode = item.ExternalOut4Mode;
            structItem.ExternalOut4DelayTime = item.ExternalOut4DelayTime;
            structItem.ExternalOut4RunTime = item.ExternalOut4RunTime;

            structItem.ExternalOut9Mode = item.ExternalOut9Mode;
            structItem.ExternalOut9DelayTime = item.ExternalOut9DelayTime;
            structItem.ExternalOut9RunTime = item.ExternalOut9RunTime;

            structItem.ExternalOut10Mode = item.ExternalOut10Mode;
            structItem.ExternalOut10DelayTime = item.ExternalOut10DelayTime;
            structItem.ExternalOut10RunTime = item.ExternalOut10RunTime;

            structItem.Dummy1 = "0";
            structItem.Dummy2 = "0";

            this.smartFileIO.WriteStructure(structItem, 0);
            this.smartFileIO.Close();
        }
        public void LoadSystemParameter3File(ref SystemParameter3 pItem)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemParameter3 structItem;

            fullFilePath = this.PathSystemFileFolder1 + "SystemParameter3.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemParameter3File();
            }

            try
            {
                structItem = (StructSystemParameter3)this.smartFileIO.ReadStructure(0, typeof(StructSystemParameter3));

                pItem.ExternalOut1Mode = structItem.ExternalOut1Mode;
                pItem.ExternalOut1DelayTime = structItem.ExternalOut1DelayTime;
                pItem.ExternalOut1RunTime = structItem.ExternalOut1RunTime;

                pItem.ExternalOut2Mode = structItem.ExternalOut2Mode;
                pItem.ExternalOut2DelayTime = structItem.ExternalOut2DelayTime;
                pItem.ExternalOut2RunTime = structItem.ExternalOut2RunTime;

                pItem.ExternalOut3Mode = structItem.ExternalOut3Mode;
                pItem.ExternalOut3DelayTime = structItem.ExternalOut3DelayTime;
                pItem.ExternalOut3RunTime = structItem.ExternalOut3RunTime;

                pItem.ExternalOut4Mode = structItem.ExternalOut4Mode;
                pItem.ExternalOut4DelayTime = structItem.ExternalOut4DelayTime;
                pItem.ExternalOut4RunTime = structItem.ExternalOut4RunTime;

                pItem.ExternalOut9Mode = structItem.ExternalOut9Mode;
                pItem.ExternalOut9DelayTime = structItem.ExternalOut9DelayTime;
                pItem.ExternalOut9RunTime = structItem.ExternalOut9RunTime;

                pItem.ExternalOut10Mode = structItem.ExternalOut10Mode;
                pItem.ExternalOut10DelayTime = structItem.ExternalOut10DelayTime;
                pItem.ExternalOut10RunTime = structItem.ExternalOut10RunTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion

        #region UserGroupFile
        private void CreateUserGroupFile()
        {
            StructUserGroupItem structItem;
            UserGroupItem item = new UserGroupItem();

            for (int i = 0; i < 3; i++)
            {
                #region StructItem
                structItem.IsBasic = item.IsBasic;
                structItem.IsBasicDataBackup = item.IsBasicDataBackup;
                structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
                structItem.IsBasicProduct = item.IsBasicProduct;
                structItem.IsBasicTime = item.IsBasicTime;

                structItem.IsConfiSerial = item.IsConfiSerial;
                structItem.IsConfiguration = item.IsConfiguration;
                structItem.IsConfiOptionBoard = item.IsConfiOptionBoard;

                structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
                structItem.IsEquipInitialize = item.IsEquipInitialize;
                structItem.IsEquipment = item.IsEquipment;
                structItem.IsEquipUpdate = item.IsEquipUpdate;
                structItem.IsEquipUser = item.IsEquipUser;

                structItem.IsInforAS = item.IsInforAS;
                structItem.IsInformation = item.IsInformation;
                structItem.IsInforSystem = item.IsInforSystem;

                structItem.IsSystem = item.IsSystem;
                structItem.IsSystemAutoZero = item.IsSystemAutoZero;
                structItem.IsSystemCalibration = item.IsSystemCalibration;
                structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
                structItem.IsSystemIOTest = item.IsSystemIOTest;
                structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
                structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

                structItem.IsConfiEthernet = false;
                structItem.Dummy2 = false;
                structItem.Dummy3 = false;
                structItem.Dummy4 = false;
                structItem.Dummy5 = false;
                structItem.Dummy6 = false;
                structItem.Dummy7 = false;
                structItem.Dummy8 = false;
                structItem.Dummy9 = false;
                structItem.Dummy10 = false;
                structItem.Dummy11 = false;
                structItem.Dummy12 = false;
                structItem.Dummy13 = false;
                structItem.Dummy14 = false;
                structItem.Dummy15 = false;
                structItem.Dummy16 = false;
                structItem.Dummy17 = false;
                structItem.Dummy18 = false;
                structItem.Dummy19 = false;
                structItem.Dummy20 = false;
                #endregion

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserGroupFile(UserGroup item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level1
            structItem.IsBasic = item.Level1.IsBasic;
            structItem.IsBasicDataBackup = item.Level1.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level1.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level1.IsBasicProduct;
            structItem.IsBasicTime = item.Level1.IsBasicTime;

            structItem.IsConfiSerial = item.Level1.IsConfiSerial;
            structItem.IsConfiguration = item.Level1.IsConfiguration;
            structItem.IsConfiOptionBoard = item.Level1.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.Level1.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level1.IsEquipInitialize;
            structItem.IsEquipment = item.Level1.IsEquipment;
            structItem.IsEquipUpdate = item.Level1.IsEquipUpdate;
            structItem.IsEquipUser = item.Level1.IsEquipUser;

            structItem.IsInforAS = item.Level1.IsInforAS;
            structItem.IsInformation = item.Level1.IsInformation;
            structItem.IsInforSystem = item.Level1.IsInforSystem;

            structItem.IsSystem = item.Level1.IsSystem;
            structItem.IsSystemAutoZero = item.Level1.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level1.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level1.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level1.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level1.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level1.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f0_Level1);
            #endregion

            #region Level2
            structItem.IsBasic = item.Level2.IsBasic;
            structItem.IsBasicDataBackup = item.Level2.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level2.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level2.IsBasicProduct;
            structItem.IsBasicTime = item.Level2.IsBasicTime;

            structItem.IsConfiSerial = item.Level2.IsConfiSerial;
            structItem.IsConfiguration = item.Level2.IsConfiguration;
            structItem.IsConfiOptionBoard = item.Level2.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.Level2.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level2.IsEquipInitialize;
            structItem.IsEquipment = item.Level2.IsEquipment;
            structItem.IsEquipUpdate = item.Level2.IsEquipUpdate;
            structItem.IsEquipUser = item.Level2.IsEquipUser;

            structItem.IsInforAS = item.Level2.IsInforAS;
            structItem.IsInformation = item.Level2.IsInformation;
            structItem.IsInforSystem = item.Level2.IsInforSystem;

            structItem.IsSystem = item.Level2.IsSystem;
            structItem.IsSystemAutoZero = item.Level2.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level2.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level2.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level2.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level2.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level2.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f1_Level2);
            #endregion

            #region Level3
            structItem.IsBasic = item.Level3.IsBasic;
            structItem.IsBasicDataBackup = item.Level3.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level3.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level3.IsBasicProduct;
            structItem.IsBasicTime = item.Level3.IsBasicTime;

            structItem.IsConfiSerial = item.Level3.IsConfiSerial;
            structItem.IsConfiguration = item.Level3.IsConfiguration;
            structItem.IsConfiOptionBoard = item.Level3.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.Level3.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level3.IsEquipInitialize;
            structItem.IsEquipment = item.Level3.IsEquipment;
            structItem.IsEquipUpdate = item.Level3.IsEquipUpdate;
            structItem.IsEquipUser = item.Level3.IsEquipUser;

            structItem.IsInforAS = item.Level3.IsInforAS;
            structItem.IsInformation = item.Level3.IsInformation;
            structItem.IsInforSystem = item.Level3.IsInforSystem;

            structItem.IsSystem = item.Level3.IsSystem;
            structItem.IsSystemAutoZero = item.Level3.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level3.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level3.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level3.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level3.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level3.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f2_Level3);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level1(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level1
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiSerial = item.IsConfiSerial;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOptionBoard = item.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f0_Level1);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level2(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level2
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiSerial = item.IsConfiSerial;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOptionBoard = item.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f1_Level2);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level3(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level3
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiSerial = item.IsConfiSerial;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOptionBoard = item.IsConfiOptionBoard;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            structItem.IsConfiEthernet = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)Define.E_EnumFileUserGroup.f2_Level3);
            #endregion

            this.smartFileIO.Close();
        }
        private void LoadUserGroupFile(ref UserGroup item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            try
            {
                #region Level1
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)Define.E_EnumFileUserGroup.f0_Level1, typeof(StructUserGroupItem));

                item.Level1.IsBasic = structItem.IsBasic;
                item.Level1.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level1.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level1.IsBasicProduct = structItem.IsBasicProduct;
                item.Level1.IsBasicTime = structItem.IsBasicTime;

                item.Level1.IsConfiSerial = structItem.IsConfiSerial;
                item.Level1.IsConfiguration = structItem.IsConfiguration;
                item.Level1.IsConfiOptionBoard = structItem.IsConfiOptionBoard;

                item.Level1.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level1.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level1.IsEquipment = structItem.IsEquipment;
                item.Level1.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level1.IsEquipUser = structItem.IsEquipUser;

                item.Level1.IsInforAS = structItem.IsInforAS;
                item.Level1.IsInformation = structItem.IsInformation;
                item.Level1.IsInforSystem = structItem.IsInforSystem;

                item.Level1.IsSystem = structItem.IsSystem;
                item.Level1.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level1.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level1.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level1.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level1.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level1.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion

                #region Level2
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)Define.E_EnumFileUserGroup.f1_Level2, typeof(StructUserGroupItem));

                item.Level2.IsBasic = structItem.IsBasic;
                item.Level2.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level2.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level2.IsBasicProduct = structItem.IsBasicProduct;
                item.Level2.IsBasicTime = structItem.IsBasicTime;

                item.Level2.IsConfiSerial = structItem.IsConfiSerial;
                item.Level2.IsConfiguration = structItem.IsConfiguration;
                item.Level2.IsConfiOptionBoard = structItem.IsConfiOptionBoard;

                item.Level2.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level2.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level2.IsEquipment = structItem.IsEquipment;
                item.Level2.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level2.IsEquipUser = structItem.IsEquipUser;

                item.Level2.IsInforAS = structItem.IsInforAS;
                item.Level2.IsInformation = structItem.IsInformation;
                item.Level2.IsInforSystem = structItem.IsInforSystem;

                item.Level2.IsSystem = structItem.IsSystem;
                item.Level2.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level2.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level2.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level2.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level2.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level2.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion

                #region Level3
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)Define.E_EnumFileUserGroup.f2_Level3, typeof(StructUserGroupItem));

                item.Level3.IsBasic = structItem.IsBasic;
                item.Level3.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level3.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level3.IsBasicProduct = structItem.IsBasicProduct;
                item.Level3.IsBasicTime = structItem.IsBasicTime;

                item.Level3.IsConfiSerial = structItem.IsConfiSerial;
                item.Level3.IsConfiguration = structItem.IsConfiguration;
                item.Level3.IsConfiOptionBoard = structItem.IsConfiOptionBoard;

                item.Level3.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level3.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level3.IsEquipment = structItem.IsEquipment;
                item.Level3.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level3.IsEquipUser = structItem.IsEquipUser;

                item.Level3.IsInforAS = structItem.IsInforAS;
                item.Level3.IsInformation = structItem.IsInformation;
                item.Level3.IsInforSystem = structItem.IsInforSystem;

                item.Level3.IsSystem = structItem.IsSystem;
                item.Level3.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level3.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level3.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level3.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level3.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level3.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserGroupPassword File
        private void CreateUserGroupPasswordFile()
        {
            this.CurrentSystemStatus.CurrentUserPasswordType.Initialization();

            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level1Password, (int)Define.E_EnumFileUserPassword.f0_Level1);
            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level2Password, (int)Define.E_EnumFileUserPassword.f1_Level2);
            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level3Password, (int)Define.E_EnumFileUserPassword.f2_Level3);
        }
        public void SaveUserGroupPasswordFile(UserPasswordType item)
        {
            string fullFilePath = "";
            bool fileCheck = false;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroupPassword.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupPasswordFile();
            }

            this.smartFileIO.WriteString(item.Level1Password, (int)Define.E_EnumFileUserPassword.f0_Level1);
            this.smartFileIO.WriteString(item.Level2Password, (int)Define.E_EnumFileUserPassword.f1_Level2);
            this.smartFileIO.WriteString(item.Level3Password, (int)Define.E_EnumFileUserPassword.f2_Level3);

            this.smartFileIO.Close();
        }
        private void LoadUserGroupPasswordFile()
        {
            string fullFilePath = "";
            bool fileCheck = false;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroupPassword.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupPasswordFile();
            }

            try
            {
                this.CurrentSystemStatus.CurrentUserPasswordType.Level1Password = this.smartFileIO.ReadString((int)Define.E_EnumFileUserPassword.f0_Level1);
                this.CurrentSystemStatus.CurrentUserPasswordType.Level2Password = this.smartFileIO.ReadString((int)Define.E_EnumFileUserPassword.f1_Level2);
                this.CurrentSystemStatus.CurrentUserPasswordType.Level3Password = this.smartFileIO.ReadString((int)Define.E_EnumFileUserPassword.f2_Level3);
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel1File
        private void CreateUserLevel1File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L1";
            structItem.Password = "1111";
            structItem.Group = Define.E_UserGroup.Level1;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel1File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel1File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel1File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel1File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel2File
        private void CreateUserLevel2File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L2";
            structItem.Password = "2222";
            structItem.Group = Define.E_UserGroup.Level2;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel2File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel2File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel2File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel2File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel3File
        private void CreateUserLevel3File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L3";
            structItem.Password = "3333";
            structItem.Group = Define.E_UserGroup.Level3;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel3File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel3.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel3File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel3File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel3.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel3File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion

        #region Product File #1
        private void CreateProductFile1()
        {
            StructProductItem structItem;

            this.CurrentProductItem1.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Number = i + 1;
                structItem.Name = string.Format("Product {0}", i + 1);
                structItem.LotNo = string.Format("Lot {0}", i + 1);
                structItem.PassRange = this.CurrentProductItem1.PassRange;
                structItem.OverRange = this.CurrentProductItem1.OverRange;
                structItem.UnderRange = this.CurrentProductItem1.UnderRange;
                structItem.TareRange = this.CurrentProductItem1.TareRange;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveProductFile1(ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;
            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateProductFile1();
            }

            structItem.Number = item.Number;
            structItem.Name = item.Name;
            structItem.LotNo = item.LotNo;
            structItem.OverRange = item.OverRange;
            structItem.PassRange = item.PassRange;
            structItem.UnderRange = item.UnderRange;
            structItem.TareRange = item.TareRange;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadProductFile1(ref ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateProductFile1();
            }

            try
            {
                structItem = (StructProductItem)this.smartFileIO.ReadStructure(index, typeof(StructProductItem));

                item.Number = structItem.Number;
                item.Name = structItem.Name;
                item.LotNo = structItem.LotNo;
                item.PassRange = structItem.PassRange;
                item.OverRange = structItem.OverRange;
                item.UnderRange = structItem.UnderRange;
                item.TareRange = structItem.TareRange;
            }
            catch
            {
                // 초기화를 실행해 주세요
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        public void LoadProductName1(ref Collection<string> values)
        {
            string fullFilePath = "";
            StructProductItem structItem;

            values.Clear();

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            this.smartFileIO.Open(this.BufferSmartUart);

            if (this.smartFileIO.ReadStructureAllBuffer() == true)
            {
                for (int i = 0; i < 1000; i++)
                {
                    structItem = (StructProductItem)this.smartFileIO.ReadStructureBuffer(typeof(StructProductItem), i);

                    values.Add(structItem.Name);
                }
            }

            this.smartFileIO.Close();
        }
        #endregion
        #region Product File #2
        private void CreateProductFile2()
        {
            StructProductItem structItem;

            this.CurrentProductItem2.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Number = i + 1;
                structItem.Name = string.Format("Product {0}", i + 1);
                structItem.LotNo = string.Format("Lot {0}", i + 1);
                structItem.PassRange = this.CurrentProductItem2.PassRange;
                structItem.OverRange = this.CurrentProductItem2.OverRange;
                structItem.UnderRange = this.CurrentProductItem2.UnderRange;
                structItem.TareRange = this.CurrentProductItem2.TareRange;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveProductFile2(ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;
            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateProductFile2();
            }

            structItem.Number = item.Number;
            structItem.Name = item.Name;
            structItem.LotNo = item.LotNo;
            structItem.OverRange = item.OverRange;
            structItem.PassRange = item.PassRange;
            structItem.UnderRange = item.UnderRange;
            structItem.TareRange = item.TareRange;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadProductFile2(ref ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateProductFile2();
            }

            try
            {
                structItem = (StructProductItem)this.smartFileIO.ReadStructure(index, typeof(StructProductItem));

                item.Number = structItem.Number;
                item.Name = structItem.Name;
                item.LotNo = structItem.LotNo;
                item.PassRange = structItem.PassRange;
                item.OverRange = structItem.OverRange;
                item.UnderRange = structItem.UnderRange;
                item.TareRange = structItem.TareRange;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        public void LoadProductName2(ref Collection<string> values)
        {
            string fullFilePath = "";
            StructProductItem structItem;

            values.Clear();

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            this.smartFileIO.Open(this.BufferSmartUart);

            if (this.smartFileIO.ReadStructureAllBuffer() == true)
            {
                for (int i = 0; i < 1000; i++)
                {
                    structItem = (StructProductItem)this.smartFileIO.ReadStructureBuffer(typeof(StructProductItem), i);

                    values.Add(structItem.Name);
                }
            }

            this.smartFileIO.Close();
        }
        #endregion

        #region JudgmentSet File #1
        private void CreateJudgmentSetFile1()
        {
            StructJudgmentSetItem structItem;

            this.CurrentJudgmentSetItem1.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.CurrentJudgmentSetItem1.Filter;
                structItem.JudgmentDelayTime = this.CurrentJudgmentSetItem1.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CurrentJudgmentSetItem1.DoubleDelayTime;
                structItem.JudgmentCount = this.CurrentJudgmentSetItem1.JudgmentCount;
                structItem.FeedSpeed1 = this.CurrentJudgmentSetItem1.FeedSpeed1;
                structItem.FeedSpeed2 = this.CurrentJudgmentSetItem1.FeedSpeed2;
                structItem.FeedSpeed3 = this.CurrentJudgmentSetItem1.FeedSpeed3;
                structItem.DynamicCorrection = this.CurrentJudgmentSetItem1.DynamicCorrection;

                structItem.Sorter1Mode = this.CurrentJudgmentSetItem1.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CurrentJudgmentSetItem1.Sorter1DelayTime;
                structItem.Sorter1RunTime = this.CurrentJudgmentSetItem1.Sorter1RunTime;
                structItem.Sorter2Mode = this.CurrentJudgmentSetItem1.Sorter2Mode;
                structItem.Sorter2DelayTime = this.CurrentJudgmentSetItem1.Sorter2DelayTime;
                structItem.Sorter2RunTime = this.CurrentJudgmentSetItem1.Sorter2RunTime;

                structItem.AutoJudgmentLength = this.CurrentJudgmentSetItem1.AutoJudgmentLength;
                structItem.AutoJudgment1 = this.CurrentJudgmentSetItem1.AutoJudgment1;
                structItem.AutoJudgment2 = this.CurrentJudgmentSetItem1.AutoJudgment2;
                structItem.AutoJudgment3 = this.CurrentJudgmentSetItem1.AutoJudgment3;

                structItem.DescendDelayTime = this.CurrentJudgmentSetItem1.DescendDelayTime;
                structItem.AscendDelayTime = this.CurrentJudgmentSetItem1.AscendDelayTime;
                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveJudgmentSetFile1(JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile1();
            }

            structItem.Filter = item.Filter;
            structItem.JudgmentDelayTime = item.JudgmentDelayTime;
            structItem.DoubleDelayTime = item.DoubleDelayTime;
            structItem.JudgmentCount = item.JudgmentCount;
            structItem.FeedSpeed1 = item.FeedSpeed1;
            structItem.FeedSpeed2 = item.FeedSpeed2;
            structItem.FeedSpeed3 = item.FeedSpeed3;
            structItem.DynamicCorrection = item.DynamicCorrection;

            structItem.Sorter1Mode = item.Sorter1Mode;
            structItem.Sorter1DelayTime = item.Sorter1DelayTime;
            structItem.Sorter1RunTime = item.Sorter1RunTime;
            structItem.Sorter2Mode = item.Sorter2Mode;
            structItem.Sorter2DelayTime = item.Sorter2DelayTime;
            structItem.Sorter2RunTime = item.Sorter2RunTime;

            structItem.AutoJudgmentLength = item.AutoJudgmentLength;
            structItem.AutoJudgment1 = item.AutoJudgment1;
            structItem.AutoJudgment2 = item.AutoJudgment2;
            structItem.AutoJudgment3 = item.AutoJudgment3;

            structItem.DescendDelayTime = item.DescendDelayTime;
            structItem.AscendDelayTime = item.AscendDelayTime;
            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadJudgmentSetFile1(ref JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile1();
            }

            try
            {
                structItem = (StructJudgmentSetItem)this.smartFileIO.ReadStructure(index, typeof(StructJudgmentSetItem));

                item.Filter = structItem.Filter;
                item.JudgmentDelayTime = structItem.JudgmentDelayTime;
                item.DoubleDelayTime = structItem.DoubleDelayTime;
                item.JudgmentCount = structItem.JudgmentCount;
                item.FeedSpeed1 = structItem.FeedSpeed1;
                item.FeedSpeed2 = structItem.FeedSpeed2;
                item.FeedSpeed3 = structItem.FeedSpeed3;
                item.DynamicCorrection = structItem.DynamicCorrection;

                item.Sorter1Mode = structItem.Sorter1Mode;
                item.Sorter1DelayTime = structItem.Sorter1DelayTime;
                item.Sorter1RunTime = structItem.Sorter1RunTime;
                item.Sorter2Mode = structItem.Sorter2Mode;
                item.Sorter2DelayTime = structItem.Sorter2DelayTime;
                item.Sorter2RunTime = structItem.Sorter2RunTime;

                item.AutoJudgmentLength = structItem.AutoJudgmentLength;
                item.AutoJudgment1 = structItem.AutoJudgment1;
                item.AutoJudgment2 = structItem.AutoJudgment2;
                item.AutoJudgment3 = structItem.AutoJudgment3;

                item.DescendDelayTime = structItem.DescendDelayTime;
                item.AscendDelayTime = structItem.AscendDelayTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region JudgmentSet File #2
        private void CreateJudgmentSetFile2()
        {
            StructJudgmentSetItem structItem;

            this.CurrentJudgmentSetItem2.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.CurrentJudgmentSetItem2.Filter;
                structItem.JudgmentDelayTime = this.CurrentJudgmentSetItem2.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CurrentJudgmentSetItem2.DoubleDelayTime;
                structItem.JudgmentCount = this.CurrentJudgmentSetItem2.JudgmentCount;
                structItem.FeedSpeed1 = this.CurrentJudgmentSetItem2.FeedSpeed1;
                structItem.FeedSpeed2 = this.CurrentJudgmentSetItem2.FeedSpeed2;
                structItem.FeedSpeed3 = this.CurrentJudgmentSetItem2.FeedSpeed3;
                structItem.DynamicCorrection = this.CurrentJudgmentSetItem2.DynamicCorrection;

                structItem.Sorter1Mode = this.CurrentJudgmentSetItem2.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CurrentJudgmentSetItem2.Sorter1DelayTime;
                structItem.Sorter1RunTime = this.CurrentJudgmentSetItem2.Sorter1RunTime;
                structItem.Sorter2Mode = this.CurrentJudgmentSetItem2.Sorter2Mode;
                structItem.Sorter2DelayTime = this.CurrentJudgmentSetItem2.Sorter2DelayTime;
                structItem.Sorter2RunTime = this.CurrentJudgmentSetItem2.Sorter2RunTime;

                structItem.AutoJudgmentLength = this.CurrentJudgmentSetItem2.AutoJudgmentLength;
                structItem.AutoJudgment1 = this.CurrentJudgmentSetItem2.AutoJudgment1;
                structItem.AutoJudgment2 = this.CurrentJudgmentSetItem2.AutoJudgment2;
                structItem.AutoJudgment3 = this.CurrentJudgmentSetItem2.AutoJudgment3;

                structItem.DescendDelayTime = this.CurrentJudgmentSetItem2.DescendDelayTime;
                structItem.AscendDelayTime = this.CurrentJudgmentSetItem2.AscendDelayTime;
                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveJudgmentSetFile2(JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile2();
            }

            structItem.Filter = item.Filter;
            structItem.JudgmentDelayTime = item.JudgmentDelayTime;
            structItem.DoubleDelayTime = item.DoubleDelayTime;
            structItem.JudgmentCount = item.JudgmentCount;
            structItem.FeedSpeed1 = item.FeedSpeed1;
            structItem.FeedSpeed2 = item.FeedSpeed2;
            structItem.FeedSpeed3 = item.FeedSpeed3;
            structItem.DynamicCorrection = item.DynamicCorrection;

            structItem.Sorter1Mode = item.Sorter1Mode;
            structItem.Sorter1DelayTime = item.Sorter1DelayTime;
            structItem.Sorter1RunTime = item.Sorter1RunTime;
            structItem.Sorter2Mode = item.Sorter2Mode;
            structItem.Sorter2DelayTime = item.Sorter2DelayTime;
            structItem.Sorter2RunTime = item.Sorter2RunTime;

            structItem.AutoJudgmentLength = item.AutoJudgmentLength;
            structItem.AutoJudgment1 = item.AutoJudgment1;
            structItem.AutoJudgment2 = item.AutoJudgment2;
            structItem.AutoJudgment3 = item.AutoJudgment3;

            structItem.DescendDelayTime = item.DescendDelayTime;
            structItem.AscendDelayTime = item.AscendDelayTime;
            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadJudgmentSetFile2(ref JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile2();
            }

            try
            {
                structItem = (StructJudgmentSetItem)this.smartFileIO.ReadStructure(index, typeof(StructJudgmentSetItem));

                item.Filter = structItem.Filter;
                item.JudgmentDelayTime = structItem.JudgmentDelayTime;
                item.DoubleDelayTime = structItem.DoubleDelayTime;
                item.JudgmentCount = structItem.JudgmentCount;
                item.FeedSpeed1 = structItem.FeedSpeed1;
                item.FeedSpeed2 = structItem.FeedSpeed2;
                item.FeedSpeed3 = structItem.FeedSpeed3;
                item.DynamicCorrection = structItem.DynamicCorrection;

                item.Sorter1Mode = structItem.Sorter1Mode;
                item.Sorter1DelayTime = structItem.Sorter1DelayTime;
                item.Sorter1RunTime = structItem.Sorter1RunTime;
                item.Sorter2Mode = structItem.Sorter2Mode;
                item.Sorter2DelayTime = structItem.Sorter2DelayTime;
                item.Sorter2RunTime = structItem.Sorter2RunTime;

                item.AutoJudgmentLength = structItem.AutoJudgmentLength;
                item.AutoJudgment1 = structItem.AutoJudgment1;
                item.AutoJudgment2 = structItem.AutoJudgment2;
                item.AutoJudgment3 = structItem.AutoJudgment3;

                item.DescendDelayTime = structItem.DescendDelayTime;
                item.AscendDelayTime = structItem.AscendDelayTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion

        #region Counter File #1
        private void CreateCounterFile1()
        {
            StructCounterItem structItem;
            WeightData item = new WeightData();
            item.ClearCount();

            for (int i = 0; i < 1000; i++)
            {
                structItem.OverCount = item.OverCount;
                structItem.OverSumWeight = item.OverSumWeight;
                structItem.PassCount = item.PassCount;
                structItem.PassSumWeight = item.PassSumWeight;
                structItem.UnderCount = item.UnderCount;
                structItem.UnderSumWeight = item.UnderSumWeight;
                structItem.ExNGCount = item.ETCExNGCount;

                structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
                structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
                structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
                structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
                structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
                structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
                structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
                structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
                structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
                structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

                structItem.StartTime = item.StartTime;
                structItem.StopTime = item.StopTime;

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveCounterFile1(WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile1();
            }

            structItem.OverCount = item.OverCount;
            structItem.OverSumWeight = item.OverSumWeight;
            structItem.PassCount = item.PassCount;
            structItem.PassSumWeight = item.PassSumWeight;
            structItem.UnderCount = item.UnderCount;
            structItem.UnderSumWeight = item.UnderSumWeight;
            structItem.ExNGCount = item.ETCExNGCount;

            structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
            structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
            structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
            structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
            structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
            structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
            structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
            structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
            structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
            structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

            structItem.StartTime = item.StartTime;
            structItem.StopTime = item.StopTime;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadCounterFile1(ref WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile1();
            }

            try
            {
                structItem = (StructCounterItem)this.smartFileIO.ReadStructure(index, typeof(StructCounterItem));

                item.UnderCount = structItem.UnderCount;
                item.UnderSumWeight = structItem.UnderSumWeight;
                item.PassCount = structItem.PassCount;
                item.PassSumWeight = structItem.PassSumWeight;
                item.OverCount = structItem.OverCount;
                item.OverSumWeight = structItem.OverSumWeight;
                item.ETCExNGCount = structItem.ExNGCount;

                item.CollectionNormalDistributionCount[0] = structItem.NormalDistribution1;
                item.CollectionNormalDistributionCount[1] = structItem.NormalDistribution2;
                item.CollectionNormalDistributionCount[2] = structItem.NormalDistribution3;
                item.CollectionNormalDistributionCount[3] = structItem.NormalDistribution4;
                item.CollectionNormalDistributionCount[4] = structItem.NormalDistribution5;
                item.CollectionNormalDistributionCount[5] = structItem.NormalDistribution6;
                item.CollectionNormalDistributionCount[6] = structItem.NormalDistribution7;
                item.CollectionNormalDistributionCount[7] = structItem.NormalDistribution8;
                item.CollectionNormalDistributionCount[8] = structItem.NormalDistribution9;
                item.CollectionNormalDistributionCount[9] = structItem.NormalDistribution10;

                if (structItem.StartTime.Year == 1111)
                    item.StartTime = DateTime.Now;
                else
                    item.StartTime = structItem.StartTime;

                if (structItem.StopTime.Year == 1111)
                    item.StopTime = DateTime.Now;
                else
                    item.StopTime = structItem.StopTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region Counter File #2
        private void CreateCounterFile2()
        {
            StructCounterItem structItem;
            WeightData item = new WeightData();
            item.ClearCount();

            for (int i = 0; i < 1000; i++)
            {
                structItem.OverCount = item.OverCount;
                structItem.OverSumWeight = item.OverSumWeight;
                structItem.PassCount = item.PassCount;
                structItem.PassSumWeight = item.PassSumWeight;
                structItem.UnderCount = item.UnderCount;
                structItem.UnderSumWeight = item.UnderSumWeight;
                structItem.ExNGCount = item.ETCExNGCount;

                structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
                structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
                structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
                structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
                structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
                structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
                structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
                structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
                structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
                structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

                structItem.StartTime = item.StartTime;
                structItem.StopTime = item.StopTime;

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveCounterFile2(WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile2();
            }

            structItem.OverCount = item.OverCount;
            structItem.OverSumWeight = item.OverSumWeight;
            structItem.PassCount = item.PassCount;
            structItem.PassSumWeight = item.PassSumWeight;
            structItem.UnderCount = item.UnderCount;
            structItem.UnderSumWeight = item.UnderSumWeight;
            structItem.ExNGCount = item.ETCExNGCount;

            structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
            structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
            structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
            structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
            structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
            structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
            structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
            structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
            structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
            structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

            structItem.StartTime = item.StartTime;
            structItem.StopTime = item.StopTime;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadCounterFile2(ref WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile2();
            }

            try
            {
                structItem = (StructCounterItem)this.smartFileIO.ReadStructure(index, typeof(StructCounterItem));

                item.UnderCount = structItem.UnderCount;
                item.UnderSumWeight = structItem.UnderSumWeight;
                item.PassCount = structItem.PassCount;
                item.PassSumWeight = structItem.PassSumWeight;
                item.OverCount = structItem.OverCount;
                item.OverSumWeight = structItem.OverSumWeight;
                item.ETCExNGCount = structItem.ExNGCount;

                item.CollectionNormalDistributionCount[0] = structItem.NormalDistribution1;
                item.CollectionNormalDistributionCount[1] = structItem.NormalDistribution2;
                item.CollectionNormalDistributionCount[2] = structItem.NormalDistribution3;
                item.CollectionNormalDistributionCount[3] = structItem.NormalDistribution4;
                item.CollectionNormalDistributionCount[4] = structItem.NormalDistribution5;
                item.CollectionNormalDistributionCount[5] = structItem.NormalDistribution6;
                item.CollectionNormalDistributionCount[6] = structItem.NormalDistribution7;
                item.CollectionNormalDistributionCount[7] = structItem.NormalDistribution8;
                item.CollectionNormalDistributionCount[8] = structItem.NormalDistribution9;
                item.CollectionNormalDistributionCount[9] = structItem.NormalDistribution10;

                item.StartTime = structItem.StartTime;
                item.StopTime = structItem.StopTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #endregion

        #region Override Member
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // 변수 초기 셋팅
            this.DefaultSetting();

            // SystemConfiguration 파일 읽기
            this.LoadSystemConfigurationFile1();
            this.LoadSystemConfigurationFile2();
            Thread.Sleep(50);

            // SystemParameter3
            this.LoadSystemParameter3File(ref this.CurrentSystemParameter3);
            Thread.Sleep(50);

            // Counter 파일 읽기
            this.LoadCounterFile1(ref this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
            this.LoadCounterFile2(ref this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // 품목 파일 읽기
            this.LoadProductFile1(ref this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
            this.LoadProductFile2(ref this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // SystemParameter 파일 읽기
            this.LoadJudgmentSetFile1(ref this.CurrentJudgmentSetItem1, this.SystemConfig.ProductNumber - 1);
            this.LoadJudgmentSetFile2(ref this.CurrentJudgmentSetItem2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // UserGroupPassword 파일 읽기
            this.LoadUserGroupPasswordFile();

            // UserGroup 파일 읽기
            this.LoadUserGroupFile(ref this.CurrentUserGroup);
            // User 파일 읽기
            this.LoadUserLevel1File(this.CurrentUser.Level1Users);
            this.LoadUserLevel2File(this.CurrentUser.Level2Users);
            this.LoadUserLevel3File(this.CurrentUser.Level3Users);

            // 폼 생성
            this.CreateForm();

            this.SmartSplashProgramLoad.Finish();
            this.smartForm.Show((int)Define.E_FormStore.FormMainDisplay);
            this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);

            this.TimerSensorErrorInterval();
            this.TimerEntryNotDetectedIgnoreTimeInverval();

            // 메인 통신 OPEN
            this.OpenSmartUartLink();
            // COM1 OPEN
            this.OpenSerialCOM1();
            // COM3 OPEN
            this.OpenSerialCOM3();
            // COM4 OPEN
            this.OpenSerialCOM4();
            // Read SystemParameter1
            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9507_SystemParameterRead, "");

            // 변수 초기 셋팅2(바코드 셋팅, 이더넷)
            this.DefaultSetting2();

            // Mouse On
            //this.smartForm.Mode = SmartForm.RUNMODE.DEVELOPER;
            //this.smartForm.MouseCursor = SmartForm.OnOff.ON;
        }
        #endregion

        #region Event Handler
        private void CurrentAlarmList_Change(Define.E_TrackingAlarm alarm, string status)
        {
            if (status == "ON")
            {
                this.CurrentAlarm.Add((short)alarm);
            }
            else
            {
                for (int i = 0; i < this.CurrentAlarm.Count; i++)
                {
                    if (this.CurrentAlarm[i] == (short)alarm)
                    {
                        this.CurrentAlarm.RemoveAt(i);
                        break;
                    }
                }
            }
            //this.SetTrackingHistoryData(alarm, status);
        }

        private void smartTCPMultiServer_OnReceiveHandler(SmartTCPMultiServer.CHandleClinet.READINFO datas)
        {
            int ret = 0;
            byte[] readByte;
            string strRecData = "";
            byte[] sendOPCDatas = new byte[57];
            byte[] sendModbusDatas;

            try
            {
                readByte = datas.receiveDatas;
                strRecData = SmartTCPMultiServer.ConvertAsciiByteToString(readByte);
            }
            catch
            {
                return;
            }

            switch (this.SystemConfig.EthernetCommMode)
            {
                case (int)Define.E_CommMode.f99_Modbus:
                    #region Modbus TCP
                    if (this.smartTCPMultiServer.ClientInfoList != null)
                    {
                        this.ChildFormMainDisplay.MainModbus.UpdateReceiveCount();

                        //Console.Write("\n" + string.Format("Receive Modbus {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, Helper.ByteToHexString(readByte)));

                        if (readByte[7] == 0x03) // Read Holding Register
                        {
                            #region Read Holding Register
                            try
                            {
                                byte[] responseData;
                                byte errorCheck = this.Modbus.CheckRequestDataErrorTCP(readByte, ModbusFunctionCode.FunctionCode_03);

                                if (errorCheck == 0x00)
                                    responseData = this.Modbus.MakeTCPResponseData(readByte, this.Transfer_5_Modbus_Read_TCP(readByte), ModbusFunctionCode.FunctionCode_03);
                                else
                                    responseData = this.Modbus.MakeTCPErrorResponseData(readByte, errorCheck, ModbusFunctionCode.FunctionCode_03);

                                foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                {
                                    this.smartTCPMultiServer.SendByteByClientID(client.strID, responseData);
                                }

                                // 로그
                                if (this.IsCommunicationLogOpen == true)
                                {
                                    this.smartFileCommunicationLog.WriteString(string.Format("Receive TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                    this.smartFileCommunicationLog.WriteString(string.Format("Send TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                        }
                        else if (readByte[7] == 0x10) // Write Multiple Register
                        {
                            #region Write Multiple Register
                            try
                            {
                                byte[] errorResponseData = new byte[9];
                                byte[] responseData = new byte[12];
                                byte errorCheck = this.Modbus.CheckRequestDataErrorTCP(readByte, ModbusFunctionCode.FunctionCode_16);

                                if (errorCheck == 0x00)
                                {
                                    for (int i = 0; i < 12; i++)
                                        responseData[i] = readByte[i];
                                    responseData[5] = 0x06;

                                    foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                    {
                                        this.smartTCPMultiServer.SendByteByClientID(client.strID, responseData);
                                    }

                                    this.ReceiveModbusTCPWriteManager(readByte);
                                }
                                else
                                {
                                    for (int i = 0; i < 5; i++)
                                        errorResponseData[i] = readByte[i];

                                    // Length
                                    errorResponseData[5] = 0x03;
                                    // Unit ID
                                    errorResponseData[6] = 0x01;
                                    // Function Code
                                    errorResponseData[7] = 0x90;
                                    // Error Code
                                    errorResponseData[8] = errorCheck;

                                    foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                    {
                                        this.smartTCPMultiServer.SendByteByClientID(client.strID, responseData);
                                    }
                                }

                                // 로그
                                if (this.IsCommunicationLogOpen == true)
                                {
                                    this.smartFileCommunicationLog.WriteString(string.Format("Receive TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                    this.smartFileCommunicationLog.WriteString(string.Format("Send TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                        }
                        else // Read Input Register(0x04)
                        {
                            if (this.SystemConfig.ModbusTCPSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister)
                            {
                                #region Read Input Register
                                try
                                {
                                    byte[] responseData;
                                    byte errorCheck = this.Modbus.CheckRequestDataErrorTCP(readByte, ModbusFunctionCode.FunctionCode_04);

                                    if (errorCheck == 0x00)
                                        responseData = this.Modbus.MakeTCP04ResponseData(readByte, this.Transfer_5_Modbus_Read_TCP(readByte));
                                    else
                                        responseData = this.Modbus.MakeTCP04ErrorResponseData(readByte, errorCheck);

                                    foreach (SmartTCPMultiServer.CLIENTSINFOS client in this.smartTCPMultiServer.ClientInfoList)
                                    {
                                        this.smartTCPMultiServer.SendByteByClientID(client.strID, responseData);
                                    }

                                    //Console.Write("\n" + string.Format("Send Modbus {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, Helper.ByteToHexString(responseData)));

                                    // 로그
                                    if (this.IsCommunicationLogOpen == true)
                                    {
                                        this.smartFileCommunicationLog.WriteString(string.Format("Receive TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, Helper.ByteToHexString(readByte)));
                                        this.smartFileCommunicationLog.WriteString(string.Format("Send TCP ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, Helper.ByteToHexString(responseData)));
                                    }
                                }
                                catch
                                {
                                }
                                #endregion
                            }
                        }
                    }
                    #endregion
                    break;
                default:
                    break;
            }
        }
                
        private void smartSerialPort1_OnReadQueueEvent()
        {
            int ret = 0;
            string strTemp = "";
            byte[] readByte;

            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPort1.ReadQueue(out readByte);
                if (this.SystemConfig.SerialCOM1Mode != (int)Define.E_CommMode.f99_Modbus)
                {
                    strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);

                    if (this.ChildFormMainDisplay.labelBarcode.Visible == true)
                        this.ChildFormMainDisplay.labelBarcode.Text = strTemp;

                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
                }
                else
                {
                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                }

            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
            {
                return;
            }

            switch (this.SystemConfig.SerialCOM1Mode)
            {
                case (int)Define.E_CommMode.f99_Modbus:
                    #region Modbus RTU
                    this.ChildFormMainDisplay.MainModbus.UpdateReceiveCount();

                    if (this.SystemConfig.ModbusRTUSlaveIDCOM1 != Convert.ToInt32(readByte[0]))
                        return;

                    if (readByte[1] == 0x03) // Read Holding Register
                    {
                        #region Read Holding Register
                        try
                        {
                            byte[] responseData;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_03);

                            if (errorCheck == 0x00)
                                responseData = this.Modbus.MakeRTUResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM1, ModbusFunctionCode.FunctionCode_03);
                            else
                                responseData = this.Modbus.MakeRTUErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM1, ModbusFunctionCode.FunctionCode_03);

                            this.TransferSerialCOM1(responseData);

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else if (readByte[1] == 0x10) // Write Multiple Register
                    {
                        #region Write Multiple Register
                        try
                        {
                            byte[] errorResponseData = new byte[5];
                            byte[] responseData = new byte[8];
                            byte[] crc;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_16);

                            if (errorCheck == 0x00)
                            {
                                for (int i = 0; i < 6; i++)
                                    responseData[i] = readByte[i];

                                crc = this.Modbus.MakeRTUCRC(responseData, responseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    responseData[6 + i] = crc[i];

                                this.TransferSerialCOM1(responseData);

                                this.ReceiveModbusRTUWriteManager(readByte);
                            }
                            else
                            {
                                errorResponseData[0] = readByte[0];
                                errorResponseData[1] = 0x90;
                                errorResponseData[2] = errorCheck;

                                crc = this.Modbus.MakeRTUCRC(errorResponseData, errorResponseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    errorResponseData[3 + i] = crc[i];

                                this.TransferSerialCOM1(errorResponseData);
                            }

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else // Read Input Register(0x04)
                    {
                        if (this.SystemConfig.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister)
                        {
                            #region Read Input Register
                            try
                            {
                                byte[] responseData;
                                byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_04);

                                if (errorCheck == 0x00)
                                    responseData = this.Modbus.MakeRTU04ResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM1);
                                else
                                    responseData = this.Modbus.MakeRTU04ErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM1);

                                this.TransferSerialCOM1(responseData);

                                // 로그
                                if (this.IsCommunicationLogOpen == true)
                                {
                                    this.smartFileCommunicationLog.WriteString(string.Format("Receive COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                    this.smartFileCommunicationLog.WriteString(string.Format("Send COM1 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                        }
                    }
                    #endregion
                    break;
                default:
                    break;
            }

        }
        private void smartSerialPort2_OnReadQueueEvent()
        {
            this.ReceiveData();

            // 통신 확인
            if (this.CommunicationCheckCount / 3 == 1)
            {
                this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = true;
                this.CommunicationCheckCount = 0;
            }
            else
            {
                this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = false;
                this.CommunicationCheckCount += 1;
            }
        }
        private void smartSerialPort3_OnReadQueueEvent()
        {
            int productNo = 0;
            string strTemp = "", value = "";
            byte[] readByte;
            byte[] sendModbusDatas;
            byte[] madeDatas;
            BarcodeStatus status = BarcodeStatus.None;
            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPort3.ReadQueue(out readByte);

                if (this.SystemConfig.SerialCOM3Mode != (int)Define.E_CommMode.f99_Modbus)
                {
                    strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);

                    if (this.ChildFormMainDisplay.labelBarcode.Visible == true)
                        this.ChildFormMainDisplay.labelBarcode.Text = strTemp;

                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
                }
                else
                {
                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                }
            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
            {
                return;
            }

            switch (this.SystemConfig.SerialCOM3Mode)
            {
                case (int)Define.E_CommMode.f99_Modbus:
                    #region Modbus RTU
                    this.ChildFormMainDisplay.MainModbus.UpdateReceiveCount();

                    if (this.SystemConfig.ModbusRTUSlaveIDCOM3 != Convert.ToInt32(readByte[0]))
                        return;

                    if (readByte[1] == 0x03) // Read Holding Register
                    {
                        #region Read Holding Register
                        try
                        {
                            byte[] responseData;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_03);

                            if (errorCheck == 0x00)
                                responseData = this.Modbus.MakeRTUResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM3, ModbusFunctionCode.FunctionCode_03);
                            else
                                responseData = this.Modbus.MakeRTUErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM3, ModbusFunctionCode.FunctionCode_03);

                            this.TransferSerialCOM3(responseData);

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else if (readByte[1] == 0x10) // Write Multiple Register
                    {
                        #region Write Multiple Register
                        try
                        {
                            byte[] errorResponseData = new byte[5];
                            byte[] responseData = new byte[8];
                            byte[] crc;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_16);

                            if (errorCheck == 0x00)
                            {
                                for (int i = 0; i < 6; i++)
                                    responseData[i] = readByte[i];

                                crc = this.Modbus.MakeRTUCRC(responseData, responseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    responseData[6 + i] = crc[i];

                                this.TransferSerialCOM3(responseData);

                                this.ReceiveModbusRTUWriteManager(readByte);
                            }
                            else
                            {
                                errorResponseData[0] = readByte[0];
                                errorResponseData[1] = 0x90;
                                errorResponseData[2] = errorCheck;

                                crc = this.Modbus.MakeRTUCRC(errorResponseData, errorResponseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    errorResponseData[3 + i] = crc[i];

                                this.TransferSerialCOM3(errorResponseData);
                            }

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else // Read Input Register(0x04)
                    {
                        if (this.SystemConfig.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister)
                        {
                            #region Read Input Register
                            try
                            {
                                byte[] responseData;
                                byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_04);

                                if (errorCheck == 0x00)
                                    responseData = this.Modbus.MakeRTU04ResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM3);
                                else
                                    responseData = this.Modbus.MakeRTU04ErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM3);

                                this.TransferSerialCOM3(responseData);

                                // 로그
                                if (this.IsCommunicationLogOpen == true)
                                {
                                    this.smartFileCommunicationLog.WriteString(string.Format("Receive COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                    this.smartFileCommunicationLog.WriteString(string.Format("Send COM3 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                        }
                    }
                    #endregion
                    break;
                default:
                    break;
            }

        }
        private void smartSerialPort4_OnReadQueueEvent()
        {
            int ret = 0;
            string strTemp = "";
            byte[] readByte;

            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPort4.ReadQueue(out readByte);
                if (this.SystemConfig.SerialCOM4Mode != (int)Define.E_CommMode.f99_Modbus)
                {
                    strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);

                    if (this.ChildFormMainDisplay.labelBarcode.Visible == true)
                        this.ChildFormMainDisplay.labelBarcode.Text = strTemp;

                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
                }
                else
                {
                    // 로그
                    if (this.IsCommunicationLogOpen == true)
                        this.smartFileCommunicationLog.WriteString(string.Format("Receive COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                }
            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
            {
                return;
            }

            switch (this.SystemConfig.SerialCOM4Mode)
            {
                case (int)Define.E_CommMode.f99_Modbus:
                    #region Modbus RTU
                    this.ChildFormMainDisplay.MainModbus.UpdateReceiveCount();

                    if (this.SystemConfig.ModbusRTUSlaveIDCOM4 != Convert.ToInt32(readByte[0]))
                        return;

                    if (readByte[1] == 0x03) // Read Holding Register
                    {
                        #region Read Holding Register
                        try
                        {
                            byte[] responseData;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_03);

                            if (errorCheck == 0x00)
                                responseData = this.Modbus.MakeRTUResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM4, ModbusFunctionCode.FunctionCode_03);
                            else
                                responseData = this.Modbus.MakeRTUErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM4, ModbusFunctionCode.FunctionCode_03);

                            this.TransferSerialCOM4(responseData);

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else if (readByte[1] == 0x10) // Write Multiple Register
                    {
                        #region Write Multiple Register
                        try
                        {
                            byte[] errorResponseData = new byte[5];
                            byte[] responseData = new byte[8];
                            byte[] crc;
                            byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_16);

                            if (errorCheck == 0x00)
                            {
                                for (int i = 0; i < 6; i++)
                                    responseData[i] = readByte[i];

                                crc = this.Modbus.MakeRTUCRC(responseData, responseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    responseData[6 + i] = crc[i];

                                this.TransferSerialCOM4(responseData);

                                this.ReceiveModbusRTUWriteManager(readByte);
                            }
                            else
                            {
                                errorResponseData[0] = readByte[0];
                                errorResponseData[1] = 0x90;
                                errorResponseData[2] = errorCheck;

                                crc = this.Modbus.MakeRTUCRC(errorResponseData, errorResponseData.Length - 2);
                                for (int i = 0; i < 2; i++)
                                    errorResponseData[3 + i] = crc[i];

                                this.TransferSerialCOM4(errorResponseData);
                            }

                            // 로그
                            if (this.IsCommunicationLogOpen == true)
                            {
                                this.smartFileCommunicationLog.WriteString(string.Format("Receive COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                this.smartFileCommunicationLog.WriteString(string.Format("Send COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                            }
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else // Read Input Register(0x04)
                    {
                        if (this.SystemConfig.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister)
                        {
                            #region Read Input Register
                            try
                            {
                                byte[] responseData;
                                byte errorCheck = this.Modbus.CheckRequestDataErrorRTU(readByte, ModbusFunctionCode.FunctionCode_04);

                                if (errorCheck == 0x00)
                                    responseData = this.Modbus.MakeRTU04ResponseData(this.Transfer_5_Modbus_Read_RTU(readByte), this.SystemConfig.ModbusRTUSlaveIDCOM4);
                                else
                                    responseData = this.Modbus.MakeRTU04ErrorResponseData(errorCheck, this.SystemConfig.ModbusRTUSlaveIDCOM4);

                                this.TransferSerialCOM4(responseData);

                                // 로그
                                if (this.IsCommunicationLogOpen == true)
                                {
                                    this.smartFileCommunicationLog.WriteString(string.Format("Receive COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(readByte)));
                                    this.smartFileCommunicationLog.WriteString(string.Format("Send COM4 ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, BitConverter.ToString(responseData)));
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                        }
                    }
                    #endregion
                    break;
                default:
                    break;
            }
        }

        private void timerEntryNotDetectedIgnoreTime1_Tick(object sender, EventArgs e)
        {
            this.timerEntryNotDetectedIgnoreTime1.Enabled = false;

            if (this.IsJudgmentNow1 == true)
                this.IsJudgmentNow1 = false;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow1 ({0:yyyy-MM-dd HH:mm:ss}): false", DateTime.Now));
        }
        private void timerEntryNotDetectedIgnoreTime2_Tick(object sender, EventArgs e)
        {
            this.timerEntryNotDetectedIgnoreTime2.Enabled = false;

            if (this.IsJudgmentNow2 == true)
                this.IsJudgmentNow2 = false;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow2 ({0:yyyy-MM-dd HH:mm:ss}): false", DateTime.Now));
        }
        private void timerSensorError1_Tick(object sender, EventArgs e)
        {
            this.timerSensorError1.Enabled = false;
            if (this.SystemConfig.Language == Define.E_LanguageID.Korean)
                this.ChildFormMainDisplay.PopUpWarning("#1 진입센서 이상");
            else
                this.ChildFormMainDisplay.PopUpWarning("#1 Entry Sensor stucked");

            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void timerSensorError2_Tick(object sender, EventArgs e)
        {
            this.timerSensorError2.Enabled = false;
            if (this.SystemConfig.Language == Define.E_LanguageID.Korean)
                this.ChildFormMainDisplay.PopUpWarning("#2 진입센서 이상");
            else
                this.ChildFormMainDisplay.PopUpWarning("#2 Entry Sensor stucked");

            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void timerClientTryConnect_Tick(object sender, EventArgs e)
        {
            this.DelegateTimerTryConnect(false);
            this.EthernetClientConnect();
        }

        private void timerCOM1_Tick(object sender, EventArgs e)
        {
            System.Windows.Forms.Timer timer = sender as System.Windows.Forms.Timer;
            timer.Enabled = false;

            if (this.QueueCOM1.Count > 0)
            {
                Type type = this.QueueCOM1.Peek().GetType();

                if (type == typeof(string))
                    this.TransferDirectSerialCOM1((string)this.QueueCOM1.Dequeue());
                else if (type == typeof(byte[]))
                    this.TransferDirectSerialCOM1((byte[])this.QueueCOM1.Dequeue());
            }

            timer.Dispose();
            timer = null;
        }
        private void timerCOM3_Tick(object sender, EventArgs e)
        {
            System.Windows.Forms.Timer timer = sender as System.Windows.Forms.Timer;
            timer.Enabled = false;

            if (this.QueueCOM3.Count > 0)
            {
                Type type = this.QueueCOM3.Peek().GetType();

                if (this.smartSerialPort3.FrameSeparationType == SmartSerialPort.FRAMESEPARATIONTYPES.ETXONLY)
                {
                    if (type == typeof(string))
                        this.TransferDirectSerialCOM3RawData((string)this.QueueCOM3.Dequeue());
                    else if (type == typeof(byte[]))
                        this.TransferDirectSerialCOM3RawData((byte[])this.QueueCOM3.Dequeue());
                }
                else
                {
                    if (type == typeof(string))
                        this.TransferDirectSerialCOM3((string)this.QueueCOM3.Dequeue());
                    else if (type == typeof(byte[]))
                        this.TransferDirectSerialCOM3((byte[])this.QueueCOM3.Dequeue());
                }
            }

            timer.Dispose();
            timer = null;
        }
        private void timerCOM4_Tick(object sender, EventArgs e)
        {
            System.Windows.Forms.Timer timer = sender as System.Windows.Forms.Timer;
            timer.Enabled = false;

            if (this.QueueCOM4.Count > 0)
            {
                Type type = this.QueueCOM4.Peek().GetType();

                if (type == typeof(string))
                    this.TransferDirectSerialCOM4((string)this.QueueCOM4.Dequeue());
                else if (type == typeof(byte[]))
                    this.TransferDirectSerialCOM4((byte[])this.QueueCOM4.Dequeue());
            }

            timer.Dispose();
            timer = null;
        }
        #endregion
    }
}