/// <summary>
        /// Handles the VirtualPortCreated event of the this._virtualComPortsFinder control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LaJust.EIDSS.Communications.Hardware.VirtualComPortEventArgs"/> instance containing the event data.</param>
        private void VirtualComPortsFinder_VirtualPortCreated(object sender, VirtualComPortEventArgs e)
        {
            Trace.TraceInformation("{0}.VirtualPortCreated: PNPDeviceID={1} DeviceId={2} Caption={3}", CLASSNAME, e.PnpDeviceId, e.DeviceID, e.Caption);
            Trace.Indent();
            IReceiver receiver = new Receiver(e.PnpDeviceId, e.DeviceID, this.courtNumber++);
            int       count;

            // Hook up event handlers
            receiver.StrikeDetected     += this.OnStrikeDetected;
            receiver.PanelButtonPressed += this.OnPanelButtonPressed;
            receiver.DeviceStatusUpdate += this.OnDeviceStatusUpdate;
            receiver.DeviceRegistered   += this.OnDeviceRegistered;

            lock (this.recievers)
            {
                this.recievers.Add(e.PnpDeviceId, receiver);
                count = this.recievers.Count;
            }

            this.OnReceiverCountChanged(this, new ReceiverCountEventArgs()
            {
                Count = count
            });
            Trace.Unindent();
        }
Exemple #2
0
        /// <summary>
        /// Handles the VirtualPortRemoved event of the _virtualComPortsFinder control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LaJust.PowerMeter.Communications.VirtualComPortEventArgs"/> instance containing the event data.</param>
        private void VirtualComPortsFinder_VirtualPortRemoved(object sender, VirtualComPortEventArgs e)
        {
            Trace.TraceInformation("{0}.VirtualPortRemoved: PNPDeviceID={1}", CLASSNAME, e.PNPDeviceID);
            Trace.Indent();

            IReceiver receiver = null;
            int       count;

            lock (_recievers)
            {
                if (_recievers.ContainsKey(e.PNPDeviceID))
                {
                    receiver = _recievers[e.PNPDeviceID];
                    _recievers.Remove(e.PNPDeviceID);
                }
                count = _recievers.Count;
            }

            if (receiver != null)
            {
                // Clear out game registrations
                receiver.ClearGameRegistrations();

                // UnHook event handlers
                receiver.StrikeDetected     -= OnStrikeDetected;
                receiver.PanelButtonPressed -= OnPanelButtonPressed;
                receiver.DeviceStatusUpdate -= OnDeviceStatusUpdate;
                receiver.DeviceRegistered   -= OnDeviceRegistered;

                receiver.Dispose();
            }

            OnReceiverCountChanged(this, new ReceiverCountEventArgs()
            {
                Count = count
            });
            Trace.Unindent();
        }