Exemplo n.º 1
0
 public void Connect(string serverID)
 {
     this.itemMgtInterface = typeof(IOPCItemMgt).GUID;
     Type typeFromProgID = Type.GetTypeFromProgID(serverID);
     this.pIOPCServer = (IOPCServer) Activator.CreateInstance(typeFromProgID);
     this.groups = new OPCGroupCollection();
 }
Exemplo n.º 2
0
 public void Connect(string ProgID,string ServerName)
 {
     this.itemMgtInterface = typeof(IOPCItemMgt).GUID;
     Type typeFromProgID;
     if (ProgID == null)
         typeFromProgID = Type.GetTypeFromProgID(ServerName);
     else
         typeFromProgID = Type.GetTypeFromProgID(ProgID, ServerName);
     this.pIOPCServer = (IOPCServer)Activator.CreateInstance(typeFromProgID);
     this.groups = new OPCGroupCollection();
 }
		internal ItemProperties(IOPCServer server)
		{
			try
			{
				itemProperties = (IOPCItemProperties) server;
			}
			catch (InvalidCastException)
			{
				throw new NotSupportedException();
			}
		}
        internal ServerAddressSpaceBrowser(IOPCServer server, int blockSize)
        {
            this.blockSize = blockSize;
			try
			{
				browseServerSpace = (IOPCBrowseServerAddressSpace) server;
			}
			catch (InvalidCastException)
			{
				throw new NotSupportedException();
			}
		}
Exemplo n.º 5
0
        public OpcGroup(ref IOPCServer ifServerLink, bool isPublic, string groupName, bool setActive, int requestedUpdateRate)
        {
            ifServer = ifServerLink;

            state.Name = groupName;
            state.Public = isPublic;
            state.UpdateRate = requestedUpdateRate;
            state.Active = setActive;
            state.TimeBias = 0;
            state.PercentDeadband = 0.0f;
            state.LocaleID = 0;
            state.HandleClient = this.GetHashCode();
            state.HandleServer = 0;

            // marshaling helpers:
            typeOPCITEMDEF = typeof(OPCITEMDEFintern);
            sizeOPCITEMDEF = Marshal.SizeOf(typeOPCITEMDEF);
            typeOPCITEMRESULT = typeof(OPCITEMRESULTintern);
            sizeOPCITEMRESULT = Marshal.SizeOf(typeOPCITEMRESULT);
        }
Exemplo n.º 6
0
        public void Remove(bool bForce)
        {
            ifItems = null;
            ifSync = null;

            if (!(ifMgt == null))
            {
                int rc = Marshal.ReleaseComObject(ifMgt);
                ifMgt = null;
            }

            if (!(ifServer == null))
            {
                if (!state.Public)
                    ifServer.RemoveGroup(state.HandleServer, bForce);
                ifServer = null;
            }

            state.HandleServer = 0;
        }
Exemplo n.º 7
0
        public void Connect(Guid clsidOPCserver, string szPCName)
        {
            try
            {
                Disconnect();
                Guid[] iids = new System.Guid[1] { new System.Guid("39c13a4d-011e-11d0-9675-0020afd8adb3") }; // IOPServer - maybe unknown better
                if (nSimpleOPCActivate == 1)
                {
                    Type typeofOPCserver;

                    if (szPCName.Length > 0)
                        typeofOPCserver = Type.GetTypeFromCLSID(clsidOPCserver, szPCName);
                    else
                        typeofOPCserver = Type.GetTypeFromCLSID(clsidOPCserver);

                    if (typeofOPCserver == null)
                        Marshal.ThrowExceptionForHR(HRESULTS.E_FAIL);

                    OPCserverObj = Activator.CreateInstance(typeofOPCserver);
                }
                else
                {
                    object[] ptrs = DCOM.CoCreateInstanceEx(clsidOPCserver,
                        ClsCtx.All, szPCName, iids,
                        eRpcAuthzSrv,
                        RpcAuthzSrv.None,
                        "",
                        eRpcAuthnLevel,
                        eRpcImpersLevel,
                        sDomain,
                        sUser,
                        sPassword);
                    OPCserverObj = ptrs[0];
                }
                ifServer = (IOPCServer)OPCserverObj;
                if (ifServer == null)
                    Marshal.ThrowExceptionForHR(HRESULTS.CONNECT_E_NOCONNECTION);
                Logger.LogMessage("OPC Server Connected\n", Logger.INFORMATION );
            }
            catch (Exception e)
            {
                ifServer = null;
                Logger.LogMessage("OPC Connect Exception: " + e.Message, Logger.INFORMATION);
                throw e;
            }
        }
Exemplo n.º 8
0
 public void Disconnect()
 {
     ifServer = null;
     if (!(OPCserverObj == null))
     {
         int rc = Marshal.ReleaseComObject(OPCserverObj);
         OPCserverObj = null;
     }
 }
        public void Remove( bool bForce )
        {
            if( ! (callbackcpoint == null) )
            {
            if( callbackcookie != 0 )
                {
                callbackcpoint.Unadvise( callbackcookie );
                callbackcookie = 0;
                }
            int	rc = Marshal.ReleaseComObject( callbackcpoint );
            callbackcpoint = null;
            }

            cpointcontainer	= null;
            ifItems		= null;
            ifSync		= null;
            ifAsync		= null;

            if( ! (ifMgt == null) )
            {
            int	rc = Marshal.ReleaseComObject( ifMgt );
            ifMgt = null;
            }

            if( ! (ifServer == null) )
            {
            if( ! state.Public )
                ifServer.RemoveGroup( state.HandleServer, bForce );
            ifServer	= null;
            }

            state.HandleServer = 0;
        }
Exemplo n.º 10
0
        public void Disconnect()
        {
            if( ! (shutdowncpoint == null) )
            {
            if( shutdowncookie != 0 )
                {
                shutdowncpoint.Unadvise( shutdowncookie );
                shutdowncookie = 0;
                }
            int	rc = Marshal.ReleaseComObject( shutdowncpoint );
            shutdowncpoint = null;
            }

            cpointcontainer = null;
            ifBrowse		= null;
            ifItmProps		= null;
            ifCommon		= null;
            ifServer		= null;
            if( ! (OPCserverObj == null) )
            {
            int rc = Marshal.ReleaseComObject( OPCserverObj );
            OPCserverObj = null;
            }
        }
Exemplo n.º 11
0
        public void Connect( string	clsidOPCserver )
        {
            Disconnect();

            Type	typeofOPCserver = Type.GetTypeFromProgID( clsidOPCserver );
            if( typeofOPCserver == null )
            Marshal.ThrowExceptionForHR( HRESULTS.OPC_E_NOTFOUND );

            OPCserverObj = Activator.CreateInstance( typeofOPCserver );
            ifServer = (IOPCServer) OPCserverObj;
            if( ifServer == null )
            Marshal.ThrowExceptionForHR( HRESULTS.CONNECT_E_NOCONNECTION );

            // connect all interfaces
            ifCommon		= (IOPCCommon)						OPCserverObj;
            ifBrowse		= (IOPCBrowseServerAddressSpace)	ifServer;
            ifItmProps		= (IOPCItemProperties)				ifServer;
            cpointcontainer	= (UCOMIConnectionPointContainer)	OPCserverObj;
            AdviseIOPCShutdown();
        }