Beispiel #1
0
        public MyProgram()
        {
            // IF THIS ISNT HERE -  BUG ALERT!!!!!!!!!!!!!
            MTConnectAgentCore.Configuration.defaultDirectory = Utils.GetDirectoryExe();
            MTConnectAgentCore.Configuration.confDirectory    = "";

            bTerminating = false;
            // Configuration
            try
            {
                nDebug            = Convert.ToInt32(ConfigurationManager.AppSettings["Debug"]);
                Logger.debuglevel = nDebug;
                nMTCPort          = Convert.ToInt32(ConfigurationManager.AppSettings["MTConnectPort"]);
                opcflag           = Convert.ToBoolean(ConfigurationManager.AppSettings["opcflag"]);
                nResetCycleWait   = Convert.ToInt32(ConfigurationManager.AppSettings["ResetCycleWait"]);

                dtResetTime = TimeSpan.Parse(ConfigurationManager.AppSettings["ResetTime"]);
                bReset      = Convert.ToBoolean(ConfigurationManager.AppSettings["ResetFlag"]);

                devices = ConfigurationManager.AppSettings["devices"].Split(',');// other.AppSettings.Settings["devices"].Value.Split(',');
                for (int i = 0; i < devices.Count(); i++)
                {
                    devices[i] = devices[i].Trim();
                }
                ipaddrs = ConfigurationManager.AppSettings["ipaddrs"].Split(',');// other.AppSettings.Settings["devices"].Value.Split(',');
                for (int i = 0; i < ipaddrs.Count(); i++)
                {
                    ipaddrs[i] = ipaddrs[i].Trim();
                }

                /* Create timer */
                aTimer           = new System.Timers.Timer();
                aTimer.Elapsed  += new System.Timers.ElapsedEventHandler(OnTimedEvent);
                aTimer.Interval  = 1000;
                aTimer.AutoReset = false;

                MtConnect();

                if (opcflag)
                {
                    for (int i = 0; i < ipaddrs.Count(); i++)
                    {
                        OPCMgr opc = new OPCMgr(agent, devices[i], ipaddrs[i]);
                        opc.Init();
                        opcClients.Add(opc);
                        agent.StoreEvent(DateTime.Now.ToString("s"), devices[i], "power", "OFF", null, null, null, null, null, null);
                    }
                    if (opcClients.Count < 1)
                    {
                        throw new Exception("Illegal Host Name");
                    }
                    aTimer.Interval = opcClients[0].nServerUpdatePeriod;
                }
            }
            catch (Exception e)
            {
                dtResetTime = new TimeSpan(0, 0, 0, 60, 0);
                Logger.LogMessage("Configuration Error: " + e.Message, Logger.FATAL);
            }
        }
Beispiel #2
0
        public void MyProgramSetup()
        {
            bTerminating = false;
            // Configuration
            try
            {
                nDebug            = Convert.ToInt32(ConfigurationManager.AppSettings["Debug"]);
                Logger.debuglevel = nDebug;
                nMTCPort          = Convert.ToInt32(ConfigurationManager.AppSettings["MTConnectPort"]);
                opcflag           = Convert.ToBoolean(ConfigurationManager.AppSettings["opcflag"]);
                nResetCycleWait   = Convert.ToInt32(ConfigurationManager.AppSettings["ResetCycleWait"]);
                nShdrScanDelay    = Convert.ToInt32(ConfigurationManager.AppSettings["ShdrScanDelay"]);
                dtResetTime       = TimeSpan.Parse(ConfigurationManager.AppSettings["ResetTime"]);
                bReset            = Convert.ToBoolean(ConfigurationManager.AppSettings["ResetFlag"]);

                sports = ConfigurationManager.AppSettings["shdrports"].Split(',');// other.AppSettings.Settings["devices"].Value.Split(',');
                for (int j = 0; j < sports.Count(); j++)
                {
                    ports.Add(Convert.ToInt16(sports[j].Trim()));
                }

                ipaddrs = ConfigurationManager.AppSettings["opcipaddrs"].Split(',');// other.AppSettings.Settings["devices"].Value.Split(',');
                for (int i = 0; i < ipaddrs.Count(); i++)
                {
                    ipaddrs[i] = ipaddrs[i].Trim();
                }

                devices = ConfigurationManager.AppSettings["devices"].Split(',');// other.AppSettings.Settings["devices"].Value.Split(',');
                for (int i = 0; i < devices.Count(); i++)
                {
                    devices[i] = devices[i].Trim();
                }

                /* Create timer */
                aTimer           = new System.Timers.Timer();
                aTimer.Elapsed  += new System.Timers.ElapsedEventHandler(OnTimedEvent);
                aTimer.Interval  = 1000;
                aTimer.AutoReset = false;

                if (opcflag)
                {
                    for (int i = 0; i < ipaddrs.Count(); i++)
                    {
                        Agent  agent = new Agent(ports[i], nShdrScanDelay);
                        OPCMgr opc   = new OPCMgr(agent, devices[i], ipaddrs[i]);
                        opc.Init();
                        opcClients.Add(opc);
                        agent.StoreEvent(DateTime.Now.ToString("s"), devices[i], "power", "OFF", null, null, null, null, null, null);
                        agent.Start();
                    }
                    if (opcClients.Count < 1)
                    {
                        throw new Exception("Illegal Host Name");
                    }
                    aTimer.Interval = opcClients[0].nServerUpdatePeriod;
                }
            }
            catch (Exception e)
            {
                dtResetTime = new TimeSpan(0, 0, 0, 60, 0);
                Logger.LogMessage("Configuration Error: " + e.Message, Logger.FATAL);
            }
        }