Ejemplo n.º 1
0
        /// <summary>
        /// Reads the status from the server.
        /// </summary>
        public OPCSERVERSTATUS?GetStatus()
        {
            string methodName = "IOPCServer.GetStatus";

            try
            {
                IOPCServer server = BeginComCall <IOPCServer>(methodName, true);

                IntPtr ppServerStatus;
                server.GetStatus(out ppServerStatus);

                OpcRcw.Da.OPCSERVERSTATUS pStatus = (OpcRcw.Da.OPCSERVERSTATUS)Marshal.PtrToStructure(ppServerStatus, typeof(OpcRcw.Da.OPCSERVERSTATUS));

                Marshal.DestroyStructure(ppServerStatus, typeof(OpcRcw.Da.OPCSERVERSTATUS));
                Marshal.FreeCoTaskMem(ppServerStatus);

                return(pStatus);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the current server status.
        /// </summary>
        /// <returns>The current server status.</returns>
        public ServerStatus GetStatus()
        {
            ServerStatus output = null;

            lock (this)
            {
                if (m_server == null)
                {
                    throw new Exception("The remote server is not currently connected.");
                }

                // initialize arguments.
                IntPtr pStatus = IntPtr.Zero;

                // invoke COM method.
                try
                {
                    ((IOPCServer)m_server).GetStatus(out pStatus);
                }
                catch (Exception e)
                {
                    throw Interop.CreateException("IOPCServer.GetStatus", e);
                }


                if (pStatus != IntPtr.Zero)
                {
                    OpcRcw.Da.OPCSERVERSTATUS status = (OpcRcw.Da.OPCSERVERSTATUS)Marshal.PtrToStructure(pStatus, typeof(OpcRcw.Da.OPCSERVERSTATUS));

                    output = new ServerStatus();

                    output.VendorInfo     = status.szVendorInfo;
                    output.ProductVersion = String.Format("{0}.{1}.{2}", status.wMajorVersion, status.wMinorVersion, status.wBuildNumber);
                    output.ServerState    = (serverState)status.dwServerState;
                    output.StatusInfo     = null;
                    output.StartTime      = Interop.GetFILETIME(OpcDa.Client.Com.Convert.GetFileTime(status.ftStartTime));
                    output.CurrentTime    = Interop.GetFILETIME(OpcDa.Client.Com.Convert.GetFileTime(status.ftCurrentTime));
                    output.LastUpdateTime = Interop.GetFILETIME(OpcDa.Client.Com.Convert.GetFileTime(status.ftLastUpdateTime));

                    Marshal.DestroyStructure(pStatus, typeof(OpcRcw.Da.OPCSERVERSTATUS));
                    Marshal.FreeCoTaskMem(pStatus);
                    pStatus = IntPtr.Zero;
                }
            }
            return(output);
        }
Ejemplo n.º 3
0
        ///<summary>
        /// IOPCServer::GetStatus - Gets a current status information about the Server.
        ///</summary>
		public void GetStatus(out System.IntPtr ppServerStatus)
		{
			lock (m_lock)
			{
                // intialize default values.
                OpcRcw.Da.OPCSERVERSTATUS status = new OPCSERVERSTATUS();

                status.ftStartTime      = ComUtils.GetFILETIME(m_startTime);
                status.ftCurrentTime    = ComUtils.GetFILETIME(DateTime.UtcNow);
                status.ftLastUpdateTime = ComUtils.GetFILETIME(m_lastUpdateTime);  
			    status.dwBandWidth      = -1;
			    status.dwGroupCount     = m_groups.Count;
			    status.wReserved        = 0;
                status.dwServerState    = OPCSERVERSTATE.OPC_STATUS_FAILED;
                status.wMajorVersion    = 0;
                status.wMinorVersion    = 0;
                status.wBuildNumber     = 0;
                status.szVendorInfo     = null;
                
				try
				{
                    UpdateServerStatus(ref status);
				}
				catch (Exception e)
				{
                    Utils.Trace(e, "Error reading server status.");
                    // return a status structure with a failed state.
				}

                // marshal parameters.
				ppServerStatus = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OpcRcw.Da.OPCSERVERSTATUS)));
				Marshal.StructureToPtr(status, ppServerStatus, false);
			}
		}