Exemplo n.º 1
0
        }               //	end OpcServer
        //--
        #endregion

        #region Public Methods
        //--------------------------
        public void CreateOpcServer()
        {
            if (m_opcServer == null)
            {
                m_opcServer = new OpcServer();
            }           //	em=nd if
        }               //	end CreateOpcClient
Exemplo n.º 2
0
        public Form1(OutProc anOutProc)
        {
            InitializeComponent();

            try{
                m_outProc = anOutProc;

                m_opcServer = m_outProc.OpcServer;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }           //	end try...catch
        }               //	end constructor
Exemplo n.º 3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            OutProc outProc = new OutProc();
            int     result  = (int)EnumResultCode.S_OK;

            try{
                //	create and initialize the OpcServer instance
                outProc.CreateOpcServer();
                OpcServer opcServer = outProc.OpcServer;
                opcServer.Initialize();

                MyCreator creator = new MyCreator();
                if (!ResultCode.SUCCEEDED(opcServer.Prepare(creator)))
                {
                    opcServer.Terminate();
                    opcServer = null;
                    return;
                }                       //	end if
                //	handle the command line arguments (register/unregister, etc)
                string commandline = Environment.CommandLine;
                result = opcServer.ProcessCommandLine(commandline);

                if (result != (uint)EnumResultCode.S_OK)
                {
                    if (result == (uint)EnumResultCode.S_FALSE)
                    {
                        //registration operation succesful
                        opcServer.Trace(
                            EnumTraceLevel.INF,
                            EnumTraceGroup.USER1,
                            "OpcForm::Main",
                            "Registration succeeded");
                    }
                    else
                    {
                        opcServer.Trace(
                            EnumTraceLevel.INF,
                            EnumTraceGroup.USER1,
                            "OpcForm::Main",
                            "Registration failed");
                    }                           //	end if...else

                    //	no matter what close the application if
                    //processCommandLine returned something different of S_OK
                    opcServer.Terminate();
                    opcServer = null;
                    return;
                }

                //	start the OPC server's I/O internal mechanism
                if (ResultCode.SUCCEEDED(opcServer.Start()))
                {
                    //	build the namespace
                    opcServer.BuildAddressSpace();
                    //	declare the namespaces built and the server ready for clients to connect
                    opcServer.Ready();
                }                       //	end if

                Form1 opcForm = new Form1(outProc);

                opcServer.MainForm = opcForm;

                Application.Run(opcForm);


                opcServer.Stop();
                opcServer.Terminate();
                opcServer = null;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            } //	end try...catch
        }     //	end Main