コード例 #1
0
        /*------------------------------------------------------
        *  Connect OPC Server
        *
        *  (ret)   True    OK
        *                  False   NG
        *  ------------------------------------------------------*/
        public bool Connect(DEF_OPCDA OpcdaVer, string sNodeName, string sSvrName, string sGrpName, int iUpdateRate)
        {
            if (m_OPCServer != null)
            {
                return(true);
            }

            m_OpcdaVer = OpcdaVer;
            try
            {
                // instantiate the serverlist using CoCreateInstanceEx.
                IOPCServerList svrList = (IOPCServerList)CreateInstance(CLSID_SERVERLIST, sNodeName);
                Guid           clsidList;
                svrList.CLSIDFromProgID(sSvrName, out clsidList);
                m_OPCServer = (IOPCServer)CreateInstance(clsidList, sNodeName);
                if (m_OPCServer != null)
                {
                    // 2011/11/14 シャットダウンイベントを受けれるようにする	(
                    IConnectionPointContainer OPCConnPointCntnr = (IConnectionPointContainer)m_OPCServer;
                    Guid guidShutdown = Marshal.GenerateGuidForType(typeof(IOPCShutdown));
                    OPCConnPointCntnr.FindConnectionPoint(ref guidShutdown, out m_OpcShutdownConnectionPoint);

                    m_OpcShutdownConnectionPoint.Advise(this, out m_iShutdownConnectionCookie);
                    // 2011/11/14 シャットダウンイベントを受けれるようにする	)

                    if (AddGroup(sGrpName, iUpdateRate))
                    {
                        IOPCCommon m_com = (IOPCCommon)m_OPCServer;
                        m_com.SetClientName("TestClient");

                        m_bConnect = true;

                        Marshal.ReleaseComObject(svrList);                                      // 1.0.0.5 10/06/21 Kishimoto	Release Com Object
                        svrList = null;                                                         // 1.0.0.5 10/06/21 Kishimoto	Release Com Object

                        return(true);
                    }
                }

                Marshal.ReleaseComObject(svrList);                              // 1.0.0.5 10/06/21 Kishimoto	Release Com Object
                svrList = null;                                                 // 1.0.0.5 10/06/21 Kishimoto	Release Com Object

                MessageBox.Show("Cannot connect OPC Server.", "Connect");
                return(false);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString(), "Connect");
                return(false);
            }
        }
コード例 #2
0
ファイル: DxpSimpleClass.cs プロジェクト: kumo203/YascPcDcs
        // Token: 0x06000005 RID: 5 RVA: 0x000020D4 File Offset: 0x000002D4
        public bool Connect(string sNodeName, string sServerName)
        {
            if (this.m_OPCServer != null)
            {
                return(true);
            }
            IOPCServerList iopcserverList = (IOPCServerList)DxpSimpleClass.CreateInstance(DxpSimpleClass.CLSID_SERVERLIST, sNodeName);
            bool           result;

            try
            {
                Guid clsid;
                iopcserverList.CLSIDFromProgID(sServerName, out clsid);
                this.m_OPCServer = (IOPCServer)DxpSimpleClass.CreateInstance(clsid, sNodeName);
                if (this.m_OPCServer != null)
                {
                    ((IOPCCommon)this.m_OPCServer).SetClientName("TestClient");
                    this.m_bConnect = true;
                    result          = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Debug.WriteLine(ex);
#endif
                result = false;
            }
            finally
            {
                Marshal.ReleaseComObject(iopcserverList);
                iopcserverList = null;
            }
            return(result);
        }
コード例 #3
0
 public void CLSIDFromProgID(string progId, out Guid clsid)
 {
     ifSrvList.CLSIDFromProgID(progId, out clsid);
 }