} // end OpcServer //-- #endregion #region Public Methods //-------------------------- public void CreateOpcServer() { if (m_opcServer == null) { m_opcServer = new OpcServer(); } // end if } // end CreateOpcClient
} // end StartSimulationThread //-- #endregion public static void Main(String[] args) { try { int result = (int)EnumResultCode.S_OK; EndEvent = new AutoResetEvent(false); Console console = new Console(); MyWin32.HandlerRoutine handlerRoutine = new MyWin32.HandlerRoutine(MyWin32.Handler); MyWin32.SetConsoleCtrlHandler( handlerRoutine, true); // create and initialize the OpcServer instance console.CreateOpcServer(); OpcServer server = Console.OpcServer; // TODO - binary license activation // Fill in your binary license activation keys here // // NOTE: you can activate one or all of the features at the same time // firstly activate the COM-DA Server feature // result = Application.Instance.Activate(EnumFeature.DA_SERVER, "XXXX-XXXX-XXXX-XXXX-XXXX"); if (!ResultCode.SUCCEEDED(result)) { return; } // activate the XML-DA Server Feature // result = Application.Instance.Activate(EnumFeature.XMLDA_SERVER, "XXXX-XXXX-XXXX-XXXX-XXXX"); if (!ResultCode.SUCCEEDED(result)) { return; } // END TODO - binary license activation server.Initialize(); MyCreator creator = new MyCreator(); if (!ResultCode.SUCCEEDED(server.Prepare(creator))) { server.Terminate(); MyWin32.Handler(MyWin32.CtrlTypes.CTRL_CLOSE_EVENT); server = null; return; } // end if // handle the command line arguments (register/unregister, etc) string commandline = Environment.CommandLine; result = server.ProcessCommandLine(commandline); if (result != (uint)EnumResultCode.S_OK) { if (result == (uint)EnumResultCode.S_FALSE) { //registration operation succesful server.Trace( EnumTraceLevel.INF, EnumTraceGroup.USER1, "Console::Main", "Registration succeeded"); } else { server.Trace( EnumTraceLevel.INF, EnumTraceGroup.USER1, "Console::Main", "Registration failed"); } // end if...else // no matter what close the application if //processCommandLine returned something different of S_OK server.Terminate(); server = null; return; } // end if // start the OPC server's I/O internal mechanism if (ResultCode.SUCCEEDED(server.Start())) { // build the namespace server.BuildAddressSpace(); // declare the namespaces built and the server ready for clients to connect server.Ready(); } // end if // start the simulation thread if (ResultCode.SUCCEEDED(result)) { console.StartSimulationThread(); console.StartRequestHandlesThread(); } // end if System.Console.WriteLine("Press Ctrl-C to exit\n"); while (!Console.End) { // TODO: place your cyclic code here Thread.Sleep(1000); } // end while // terminate the simulation console.SimulationEnd = true; console.SimulationMutex.WaitOne(); console.SimulationMutex.ReleaseMutex(); server.Stop(); // terminate request handling console.HandleRequestsEnd = true; console.HandleRequestsMutex.WaitOne(); console.HandleRequestsMutex.ReleaseMutex(); server.Terminate(); server = null; MyWin32.Handler(MyWin32.CtrlTypes.CTRL_CLOSE_EVENT); } catch (Exception exc) { System.Console.WriteLine(exc.ToString()); } // end try...catch } // end Main