/*------------------------------------------------------ * 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); } }
public void SetClientName(string p_Name) { m_IfCommon.SetClientName(p_Name); }