Beispiel #1
0
        /// <summary>
        /// Pass the given locobuffer on to all components.
        /// </summary>
        internal void Setup(LocoBuffer lb, LocoNetConfiguration configuration)
        {
            // Allow for null arguments
            lb = lb ?? ConfiguredLocoBuffer;
            configuration = configuration ?? Configuration;

            if ((ConfiguredLocoBuffer != lb) || (Configuration != configuration))
            {
                CloseLocoBuffer();
                locoNet = new LocoNet(lb, configuration);
                asyncLb = new AsyncLocoBuffer(ui, lb);

                lb.SendMessage += LbForwardSendMessage;
                lb.PreviewMessage += LbForwardPreviewMessage;

                var lnState = locoNet.State;
                lnState.StateChanged += LnStateStateChanged;
                lnState.LocoIOQuery += LnStateLocoIoQuery;
                lnState.LocoIOFound += LnStateLocoIoFound;
                lnState.Idle += LnStateIdle;

                LocoNetChanged.Fire(this);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Close any active locobuffer connection
        /// </summary>
        private void CloseLocoBuffer()
        {
            if (locoNet == null)
                return;

            var lb = ConfiguredLocoBuffer;
            if (lb != null)
            {
                lb.SendMessage -= LbForwardSendMessage;
                lb.PreviewMessage -= LbForwardPreviewMessage;
            }

            if (asyncLb != null)
            {
                asyncLb.Dispose();
                asyncLb = null;
            }

            var lnState = locoNet.State;
            if (lnState != null)
            {
                lnState.StateChanged -= LnStateStateChanged;
                lnState.LocoIOQuery -= LnStateLocoIoQuery;
                lnState.LocoIOFound -= LnStateLocoIoFound;
                lnState.Idle -= LnStateIdle;
            }

            locoNet.Dispose();
            locoNet = null;
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 internal UnknownLocoIODetector(LocoNet locoNet)
 {
     this.locoNet = locoNet;
     locoNet.State.Idle += OnIdle;
 }