Esempio n. 1
0
        /// <summary>
        /// デバイスを開きます。
        /// </summary>
        /// <param name="client">クライアント情報。</param>
        /// <param name="deviceEventHandler">デバイス上で発生したイベントのハンドラー。</param>
        public void Open( WpdClient client, Action< WpdEventArgs > deviceEventHandler )
        {
            if( client == null ) { throw new ArgumentNullException( "'client' is null." ); }

            if( this.IsOpened ) { return; }

            // 接続
            this._device.Open( this.Id, client.CreateDeviceValue() );
            this._client  = client;
            this.IsOpened = true;

            // プロパティ更新
            this.UpdateValues();

            // イベント ハンドラの設定
            this._deviceEventHandler = new WpdEventCallback( deviceEventHandler );
            this._device.Advise( 0, this._deviceEventHandler, null, out this._deviceEventCookie );
        }
Esempio n. 2
0
        /// <summary>
        /// デバイスを閉じます。
        /// </summary>
        public void Close()
        {
            if( !this.IsOpened ) { return; }

            this._device.Unadvise( this._deviceEventCookie );
            this._deviceEventHandler = null;
            this._deviceEventCookie  = null;

            this._device.Close();
            this._client  = null;
            this.IsOpened = false;
        }