Ejemplo n.º 1
0
        /// <summary>
        /// Handles the VirtualPortCreated 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_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, _courtNumber++);
            int count;

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

            // Clear any existing registrations from receiver
            receiver.ClearGameRegistrations();

            lock (_recievers)
            {
                _recievers.Add(e.PNPDeviceID, receiver);
                count = _recievers.Count;
            }

            OnReceiverCountChanged(this, new ReceiverCountEventArgs() { Count = count });
            Trace.Unindent();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts this instance to manage new receivers.
        /// </summary>
        /// <param name="courtNumber">The court number.</param>
        private void Start()
        {
            Trace.TraceInformation("{0}.Start: Starting monitoring CourtNumber={1}", CLASSNAME, _courtNumber);
            Trace.Indent();

            // Populate the receiver manager with any existing receivers
            foreach (VirtualComPortEventArgs port in _virtualComPortsFinder.GetPorts())
            {
                try
                {
                    IReceiver receiver = new Receiver(port.PNPDeviceID, port.DeviceID, _courtNumber++);
                    // Hook up event handlers
                    receiver.StrikeDetected += OnStrikeDetected;
                    receiver.PanelButtonPressed += OnPanelButtonPressed;
                    receiver.DeviceStatusUpdate += OnDeviceStatusUpdate;
                    receiver.DeviceRegistered += OnDeviceRegistered;
                    // Clear any existing registrations from receiver
                    receiver.ClearGameRegistrations();
                    _recievers.Add(port.PNPDeviceID, receiver);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("{0}.Start: Exception={1}", CLASSNAME, ex.GetBaseException());
                }
            }

            _virtualComPortsFinder.StartMonitoring(VirtualComPortsFinderMode.Both);
            OnReceiverCountChanged(this, new ReceiverCountEventArgs() { Count = _recievers.Count });
            Trace.Unindent();
        }