示例#1
0
        public string ReadStatus()
        {
            String str = String.Empty;

            if (_opcserver == null)
            {
                return("OPC Server Not Connected");
            }

            try
            {
                // FIXME : status is a memory leak this memory must be freed!
                SERVERSTATUS status = _opcserver.GetServerStatus();

                LogMessage(sOPCProgId + "\n" + status.ToString(), Logger.DEBUG);
                //pStatus = System.Runtime.InteropServices.(status, typeof(SERVERSTATUS));
                //Marshal.DestroyStructure(pStatus, typeof(SERVERSTATUS));
                //Marshal.FreeCoTaskMem(pStatus);
            }
            catch (Exception e)
            {
                str = "ReadStatus Error: " + e.Message;
                throw new Exception(str);
            }
            finally
            {
            }
            return(str);
        }
        internal static SERVERSTATUS GetServerStatus(ref IntPtr pInput, bool deallocate)
        {
            SERVERSTATUS output = new SERVERSTATUS();;

            if (pInput != IntPtr.Zero)
            {
                tagOPCSERVERSTATUS status = (tagOPCSERVERSTATUS)Marshal.PtrToStructure(pInput, typeof(tagOPCSERVERSTATUS));

                output.szVendorInfo   = status.szVendorInfo;
                output.ProductVersion = String.Format("{0}.{1}.{2}", status.wMajorVersion, status.wMinorVersion, status.wBuildNumber);
                output.eServerState   = (OPCSERVERSTATE)status.dwServerState;
                output.StatusInfo     = null;
                if (output.eServerState == OPCSERVERSTATE.OPC_STATUS_RUNNING)
                {
                    output.StatusInfo = "OPC_STATUS_RUNNING";
                }
                else if (output.eServerState == OPCSERVERSTATE.OPC_STATUS_FAILED)
                {
                    output.StatusInfo = "OPC_STATUS_FAILED";
                }
                else if (output.eServerState == OPCSERVERSTATE.OPC_STATUS_NOCONFIG)
                {
                    output.StatusInfo = "OPC_STATUS_NOCONFIG";
                }
                else if (output.eServerState == OPCSERVERSTATE.OPC_STATUS_SUSPENDED)
                {
                    output.StatusInfo = "OPC_STATUS_SUSPENDED";
                }
                else if (output.eServerState == OPCSERVERSTATE.OPC_STATUS_TEST)
                {
                    output.StatusInfo = "OPC_STATUS_TEST";
                }

                long fileT = (((long)status.ftCurrentTime.dwHighDateTime) << 32) + status.ftCurrentTime.dwLowDateTime;

                //output.StartTime = DateTime.FromFileTime(fileT);
                output.CurrentTime = DateTime.FromFileTime(fileT);
                //output.LastUpdateTime = DateTime.FromFileTime(fileT);

                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(tagOPCSERVERSTATUS));
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return(output);
        }
示例#3
0
        internal static SERVERSTATUS GetServerStatus(ref IntPtr pInput, bool deallocate)
        {
            SERVERSTATUS output = new SERVERSTATUS();;

            if (pInput != IntPtr.Zero)
            {
                tagOPCSERVERSTATUS status = (tagOPCSERVERSTATUS)Marshal.PtrToStructure(pInput, typeof(tagOPCSERVERSTATUS));

                output.szVendorInfo = status.szVendorInfo;
                output.ProductVersion = String.Format("{0}.{1}.{2}", status.wMajorVersion, status.wMinorVersion, status.wBuildNumber);
                output.eServerState = (OPCSERVERSTATE)status.dwServerState;
                output.StatusInfo = null;
                 if(output.eServerState == OPCSERVERSTATE.OPC_STATUS_RUNNING ) output.StatusInfo= "OPC_STATUS_RUNNING";
                 else  if(output.eServerState == OPCSERVERSTATE.OPC_STATUS_FAILED ) output.StatusInfo= "OPC_STATUS_FAILED";
                 else  if(output.eServerState == OPCSERVERSTATE.OPC_STATUS_NOCONFIG ) output.StatusInfo= "OPC_STATUS_NOCONFIG";
                 else  if(output.eServerState == OPCSERVERSTATE.OPC_STATUS_SUSPENDED ) output.StatusInfo= "OPC_STATUS_SUSPENDED";
                 else  if(output.eServerState == OPCSERVERSTATE.OPC_STATUS_TEST ) output.StatusInfo= "OPC_STATUS_TEST";

                 long fileT = (((long)status.ftCurrentTime.dwHighDateTime) << 32) + status.ftCurrentTime.dwLowDateTime;

                 //output.StartTime = DateTime.FromFileTime(fileT);
                 output.CurrentTime = DateTime.FromFileTime(fileT);
                 //output.LastUpdateTime = DateTime.FromFileTime(fileT);

                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(tagOPCSERVERSTATUS));
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return output;
        }