Example #1
0
        // 2011/11/14 シャットダウンイベントを受けれるようにする	)


        // 2012/01/12 グループのアクティブ/非アクティブを切り替え	(
        //=====================================================
        //Function		: SetGroupActiveStatus(bool bSetActiveState, out string sErrMsg)
        //Distribution	: グループのアクティブ状態を設定
        //return		: true	接続完了
        //				  false	接続失敗
        //=====================================================
        public bool SetGroupActiveStatus(bool bSetActiveState, out string sErrMsg)
        {
            sErrMsg = string.Empty;
            if (m_OPCServer == null)
            {
                sErrMsg = "No connecting";
                return(false);
            }

            if (((m_OPCGroup == null) && (m_OPCGroup2 == null)) || m_iServerGroup == 0)
            {
                sErrMsg = "No connecting";
                return(false);
            }

            // アクティブ状態指定用
            IntPtr pActive = IntPtr.Zero;

            try
            {
                int    nUpdateRate        = 0;
                int    nActive            = 0;
                string sName              = "";
                int    nTimeBias          = 0;
                float  fDeadband          = 0;
                int    nLCID              = 0;
                int    nClientGroup       = 0;
                int    nServerGroup       = 0;
                int    nRevisedUpdateRate = 0;
                int    nActiveState       = (bSetActiveState == true) ? 1 : 0;

                // ポインタ実体メモリエリアを確保し、nActiveStateをコピー(アンセーフコードで確保)
                pActive = Marshal.AllocHGlobal(sizeof(int));
                Marshal.StructureToPtr(nActiveState, pActive, false);

                switch (m_OpcdaVer)
                {
                case DEF_OPCDA.VER_30:
                {
                    IOPCGroupStateMgt2 OPCGroup = (IOPCGroupStateMgt2)m_OPCGroup2;
                    OPCGroup.GetState(out nUpdateRate, out nActive, out sName, out nTimeBias, out fDeadband, out nLCID, out nClientGroup, out nServerGroup);
                    OPCGroup.SetState(IntPtr.Zero, out nRevisedUpdateRate, pActive, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                break;

                case DEF_OPCDA.VER_10:
                case DEF_OPCDA.VER_20:
                default:
                {
                    IOPCGroupStateMgt OPCGroup = (IOPCGroupStateMgt)m_OPCGroup;
                    OPCGroup.GetState(out nUpdateRate, out nActive, out sName, out nTimeBias, out fDeadband, out nLCID, out nClientGroup, out nServerGroup);
                    OPCGroup.SetState(IntPtr.Zero, out nRevisedUpdateRate, pActive, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                break;
                }
                return(true);
            }
            catch (Exception exc)
            {
                // 例外処理
                sErrMsg = exc.ToString();
                return(false);
            }
            finally
            {
                // 確保したメモリエリアを解放(アンセーフコードで確保したため)
                Marshal.FreeHGlobal(pActive);
            }
        }
Example #2
0
 private void SetState(OPCGROUPSTATE state)
 {
     _grpState.SetState(new int[] { state.UpdateRate },
                        out state.UpdateRate, new bool[] { state.Active }, new int[] { state.TimeBias },
                        new float[] { state.Deadband }, new int[] { state.LocaleId }, new int[] { state.ClientId });
 }
Example #3
0
        // 2011/11/14 �V���b�g?�E���C�x���g���󂯂��悤�ɂ���	)


        // 2012/01/12 �O��?�v�̃A�N�e�B�u/��A�N�e�B�u��؂�ւ�	(
        //=====================================================
        //Function		: SetGroupActiveStatus(bool bSetActiveState, out string sErrMsg)
        //Distribution	: �O��?�v�̃A�N�e�B�u��Ԃ�ݒ�
        //return		: true	�ڑ�����
        //				  false	�ڑ����s
        //=====================================================
        public bool SetGroupActiveStatus(bool bSetActiveState, out string sErrMsg)
        {
            sErrMsg = string.Empty;
            if (m_OPCServer == null)
            {
                sErrMsg = "No connecting";
                return(false);
            }

            if (((m_OPCGroup == null) && (m_OPCGroup2 == null)) || m_iServerGroup == 0)
            {
                sErrMsg = "No connecting";
                return(false);
            }

            // �A�N�e�B�u��Ԏw��p
            IntPtr pActive = IntPtr.Zero;

            try
            {
                int    nUpdateRate        = 0;
                int    nActive            = 0;
                string sName              = "";
                int    nTimeBias          = 0;
                float  fDeadband          = 0;
                int    nLCID              = 0;
                int    nClientGroup       = 0;
                int    nServerGroup       = 0;
                int    nRevisedUpdateRate = 0;
                int    nActiveState       = (bSetActiveState == true) ? 1 : 0;

                // ?�C��?���̃������G���A���m�ۂ��AnActiveState���R�s?(�A���Z?�t�R?�h�Ŋm�ہj
                pActive = Marshal.AllocHGlobal(sizeof(int));
                Marshal.StructureToPtr(nActiveState, pActive, false);

                switch (m_OpcdaVer)
                {
                case DEF_OPCDA.VER_30:
                {
                    IOPCGroupStateMgt2 OPCGroup = (IOPCGroupStateMgt2)m_OPCGroup2;
                    OPCGroup.GetState(out nUpdateRate, out nActive, out sName, out nTimeBias, out fDeadband, out nLCID, out nClientGroup, out nServerGroup);
                    OPCGroup.SetState(IntPtr.Zero, out nRevisedUpdateRate, pActive, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                break;

                case DEF_OPCDA.VER_10:
                case DEF_OPCDA.VER_20:
                default:
                {
                    IOPCGroupStateMgt OPCGroup = (IOPCGroupStateMgt)m_OPCGroup;
                    OPCGroup.GetState(out nUpdateRate, out nActive, out sName, out nTimeBias, out fDeadband, out nLCID, out nClientGroup, out nServerGroup);
                    OPCGroup.SetState(IntPtr.Zero, out nRevisedUpdateRate, pActive, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                break;
                }
                return(true);
            }
            catch (Exception exc)
            {
                // ��O����
                sErrMsg = exc.ToString();
                return(false);
            }
            finally
            {
                // �m�ۂ����������G���A�����(�A���Z?�t�R?�h�Ŋm�ۂ������߁j
                Marshal.FreeHGlobal(pActive);
            }
        }