Exemple #1
0
        public bool Run(bool isSimulationMode)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

            if (config.AppSettings.Settings["HIPAS_SERVER_IP"] == null)
            {
                config.AppSettings.Settings.Add("HIPAS_SERVER_IP", "127.0.0.1");
            }

            if (config.AppSettings.Settings["HIPAS_SERVER_WEB_PORT"] == null)
            {
                config.AppSettings.Settings.Add("HIPAS_SERVER_WEB_PORT", "1337");
            }

            UIHelper.LogInfo(string.Format("HIPAS Server IP : {0}, Port : {1}",
                                           config.AppSettings.Settings["HIPAS_SERVER_IP"].Value,
                                           config.AppSettings.Settings["HIPAS_SERVER_WEB_PORT"].Value));


            if (config.AppSettings.Settings["REALTIME_DATA_COLLECT_INTERVAL"] == null)
            {
                config.AppSettings.Settings.Add("REALTIME_DATA_COLLECT_INTERVAL", "20000");
            }

            if (config.AppSettings.Settings["CYCLE_CHECK_INTERVAL"] == null)
            {
                config.AppSettings.Settings.Add("CYCLE_CHECK_INTERVAL", "500");
            }

            if (config.AppSettings.Settings["ERROR_CHECK_INTERVAL"] == null)
            {
                config.AppSettings.Settings.Add("ERROR_CHECK_INTERVAL", "1000");
            }

            if (config.AppSettings.Settings["SERVER_SEND_Q_COUNT"] == null)
            {
                config.AppSettings.Settings.Add("SERVER_SEND_Q_COUNT", "100");
            }


            _serverComm = new ServerComm(
                config.AppSettings.Settings["HIPAS_SERVER_IP"].Value,
                config.AppSettings.Settings["HIPAS_SERVER_WEB_PORT"].Value,
                Convert.ToInt32(config.AppSettings.Settings["SERVER_SEND_Q_COUNT"].Value));

            _serverComm.Start();

            _realTimeCollectInterval
                = Convert.ToInt32(config.AppSettings.Settings["REALTIME_DATA_COLLECT_INTERVAL"].Value);
            _cycleCheckInterval
                = Convert.ToInt32(config.AppSettings.Settings["CYCLE_CHECK_INTERVAL"].Value);
            _errorCheckInterval
                = Convert.ToInt32(config.AppSettings.Settings["ERROR_CHECK_INTERVAL"].Value);

            this._isSimulationMode = isSimulationMode;
            if (isSimulationMode == true)
            {
                _machineInterface = new SimComm();
            }
            else
            {
                _machineInterface = new DBComm();
            }

            config.Save();


            // Load Machine Config from Appconfig
            if (config.AppSettings.Settings["MACHINE_IDS"] == null ||
                config.AppSettings.Settings["MACHINE_IDS"].Value == string.Empty)
            {
                UIHelper.LogFatal("설정 파일에서 설비 정보를 찾을 수 없습니다.");
                return(false);
            }

            _listMachineInfo.Clear();

            string[] machineIDArray
                = config.AppSettings.Settings["MACHINE_IDS"].Value.Split(',');

            foreach (string mID in machineIDArray)
            {
                _listMachineInfo.Add(new MachineInfo("SC", "StackerCrane (" + mID + ")", Convert.ToInt32(mID), 300));
            }

            int realTimeDataCollectionCount = _realTimeCollectInterval / 1000;

            _machineInterface.InitMachineComm(_listMachineInfo.Count, realTimeDataCollectionCount);

            // Register Machine Informations
            RegisterMachine();

            // Start Data Collection and Transmit
            _realTimeWatchThread = new Thread(RealTimeWatcher);
            _realTimeWatchThread.Start();

            _cycleWatchThread = new Thread(CycleWatcher);
            _cycleWatchThread.Start();

            _errorWatchThread = new Thread(ErrorWatcher);
            _errorWatchThread.Start();

            return(true);
        }