/*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardApplication constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardApplication(string instance, FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH)
        {
            m_instance = instance;
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardApplicationTOP.txt"; //  different logging file per target, this is default
                FiddleYardApplicationLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardApplicationBOT.txt"; //  different logging file per target, this is default
                FiddleYardApplicationLogging = new Log2LoggingFile(path);
            }

            // Sub programs
            FYAppVar = new FiddleYardApplicationVariables(m_FYIOHandleVar);                 // FiddleYard Application variables class, holds all variables and functions regarding variables
            FYMIP50 = new FiddleYardMip50(m_instance, m_FYIOHandleVar, m_iFYIOH, FYAppVar);
            FYAppRun = new FiddleYardAppRun(m_FYIOHandleVar, m_iFYIOH, FYAppVar, FYMIP50, FiddleYardApplicationLogging);
            FYTDT = new FiddleYardTrainDetection(m_FYIOHandleVar, FYAppVar, FYMIP50, FiddleYardApplicationLogging);
            FYAppInit = new FiddleYardAppInit(m_FYIOHandleVar, FYAppVar, FYMIP50, FYTDT, FiddleYardApplicationLogging);
            FYFORM = new FiddleYardForm(this);//, FYMip50SettingsForm);

            //Init and setup FYFORM (after the creation of the sensors and commands)
            if ("TOP" == m_instance)
                FYFORM.Name = "FiddleYardTOP";
            else if ("BOT" == m_instance)
                FYFORM.Name = "FiddleYardBOT";

            FYFORM.Show();
            FYFORM.Hide();
            FYFORM.Connect(m_FYIOHandleVar, FYAppVar); // connect the Form to the FYIOHandle interface
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardIOHandle
         *               Constructor
         *
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardIOHandle(string instance, iFiddleYardController iFYCtrl)
        {
            m_instance = instance;
            m_iFYCtrl = iFYCtrl;                            // connect to FYController interface, save interface in variable

            FYIOHandleVar = new FiddleYardIOHandleVariables();
            FYSimulator = new FiddleYardSimulator(m_instance, FYIOHandleVar);
            FYApp = new FiddleYardApplication(m_instance, FYIOHandleVar, this);
        }
 /*#--------------------------------------------------------------------------#*/
 /*  Description: FiddleYardAppInit()
  *               Constructor
  *
  *
  *  Input(s)   :
  *
  *  Output(s)  :
  *
  *  Returns    :
  *
  *  Pre.Cond.  :
  *
  *  Post.Cond. :
  *
  *  Notes      :
  */
 /*#--------------------------------------------------------------------------#*/
 public FiddleYardAppInit(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, FiddleYardTrainDetection FYTDT, Log2LoggingFile FiddleYardApplicationLogging)
 {
     m_FYIOHandleVar = FYIOHandleVar;
     m_FYAppVar = FYAppVar;
     m_FYMIP50 = FYMIP50;
     m_FYTDT = FYTDT;
     m_FYAppLog = FiddleYardApplicationLogging;
     FiddleYardInitStarted = new MessageUpdater();
     State_Machine = State.Idle;
     Message Msg_uControllerReady = new Message("uControllerReady", " uControllerReady ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
     m_FYIOHandleVar.uControllerReady.Attach(Msg_uControllerReady);
 }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardTrainDetection
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardTrainDetection(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            State_Machine = State.Idle;

            Sensor Sns_CL_10_Heart = new Sensor("CL10Heart", " CL 10 Heart ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            FYAppVar.CL10Heart.Attach(Sns_CL_10_Heart);
            Sensor Sns_F10 = new Sensor("F10", " F10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            FYAppVar.F10.Attach(Sns_F10);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardAppTrainDrive()
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardAppTrainDrive(FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar,
            FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            TrainDriveIn_Machine = State.Start;
            TrainDriveOut_Machine = State.Start;
            TrainDriveThrough_Machine = State.Start;

            Message Msg_uControllerReady = new Message("uControllerReady", " uControllerReady ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYIOHandleVar.uControllerReady.Attach(Msg_uControllerReady);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardAppRun()
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardAppRun(FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_iFYIOH = iFYIOH;
            m_FYIOHandleVar = FYIOHandleVar;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            FYAppTrainDrive = new FiddleYardAppTrainDrive(m_FYIOHandleVar, m_iFYIOH, m_FYAppVar, m_FYMIP50, m_FYAppLog);
            State_Machine = State.Idle;

            Message Msg_TrackPower15VDown = new Message("TrackPower15VDown", " TrackPower15VDown ", (name, log) => SetMessage(name, 0, log)); // initialize and subscribe readback action, Message
            m_FYIOHandleVar.TrackPower15VDown.Attach(Msg_TrackPower15VDown);
            Sensor Sns_TrackPower15V = new Sensor("15VTrackPower", " 15V Track Power ", 0, (name, val, log) => SetMessage(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackPower15V.Attach(Sns_TrackPower15V);
            Command Act_Collect = new Command("Collect", (name) => SetMessage(name, 0, "")); // initialize and subscribe Commands
            m_FYAppVar.FormCollect.Attach(Act_Collect);
        }
        //private const int TEMPOFFSET = 700;
        //public uint[] TrackForward = new uint[12] { 0, 0, 42800, 85600, 128400, 171200, 214000, 256800, 299600, 342400, 385200, 428000 };// New track coordinates forward movement 1 --> 11
        //public uint[] TrackBackwardOffset = new uint[12] { 0, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, 0 };   // New track coordinates forward movement 11 --> 1 offset number
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardApplication constructor
         *
         *  Input(s)   : instance == TOP || BOTTOM, FYIOHancleVar (FY IO handle variables class)
                         and interface to FY IO Handler
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardMip50(string instance, FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar)
        {
            m_instance = instance;
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;
            m_FYAppVar = FYAppVar;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardMIP50TOP.txt"; //  different logging file per target, this is default
                FiddleYardMIP50Logging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardMIP50BOT.txt"; //  different logging file per target, this is default
                FiddleYardMIP50Logging = new Log2LoggingFile(path);
            }
        }
        private UInt32[] TrackForward = new UInt32[12] { 0, 0, 42800, 85600, 128400, 171200, 214000, 256800, 299600, 342400, 385200, 428000 }; // New track coordinates forward movement 1 --> 11 to be moved and get from Application Variables

        #endregion Fields

        #region Constructors

        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardSimulator constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardSimulator(string Instance, FiddleYardIOHandleVariables FYIOHandleVar)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_instance = Instance;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimulatorTOP.txt"; //  different logging file per target, this is default
                FiddleYardSimulatorLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimulatorBOT.txt"; //  different logging file per target, this is default
                FiddleYardSimulatorLogging = new Log2LoggingFile(path);
            }

            FYSimVar = new FiddleYardSimulatorVariables();
            FYSimMove = new FiddleYardSimMove(this, FiddleYardSimulatorLogging, FYSimVar);
            FYSimTrDt = new FiddleYardSimTrainDetect(this, FiddleYardSimulatorLogging, FYSimVar, FYSimMove);

            FYSimVar.TrackNo.Count = 1;

            Sensor Sns_FYSimSpeedSetting = new Sensor("FYSimSpeedSetting", " FYSimSpeedSetting ", 0, (name, val, log) => SimulatorSettings(name, val, log)); // initialize and subscribe sensors
            Siebwalde_Application.Properties.Settings.Default.FYSimSpeedSetting.Attach(Sns_FYSimSpeedSetting);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: Connect
         *               hookup sensors/messages etc
         *
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public void Connect(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar)
        {
            m_FYIOHandleVar = FYIOHandleVar;    // connect to FYIOHandle interface, save interface in variable
            m_FYAppVar = FYAppVar;                  // connect to FYApplication variables, save interface in variable

            if (this.Name == "FiddleYardTOP")
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardFormTOP.txt"; //  different logging file per target, this is default
                FiddleYardFormLogging = new Log2LoggingFile(path);
            }
            else if (this.Name == "FiddleYardBOT")
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardFormBOT.txt"; //  different logging file per target, this is default
                FiddleYardFormLogging = new Log2LoggingFile(path);
            }

            #region Attach sensors
            //Sensors -----------------------------> to be pushed from Application variables
            Sensor Led_CL_10_Heart = new Sensor("LLed_Heart", " CL 10 Heart ",0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.CL10Heart.Attach(Led_CL_10_Heart);
            Sensor Led_F11 = new Sensor("LLed_F11", " F11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F11.Attach(Led_F11);
            Sensor Led_EOS10 = new Sensor("LLed_EOS10", " EOS 10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.EOS10.Attach(Led_EOS10);
            Sensor Led_EOS11 = new Sensor("LLed_EOS11", " EOS 11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.EOS11.Attach(Led_EOS11);
            Sensor Led_F13 = new Sensor("LLed_F13", " F13 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F13.Attach(Led_F13);
            Sensor Led_F12 = new Sensor("LLed_F12", " F12 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F12.Attach(Led_F12);
            Sensor Led_Block5B = new Sensor("LLed_Block5B", " Occupied from 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block5B.Attach(Led_Block5B);
            Sensor Led_Block8A = new Sensor("LLed_Block8A", " Occupied from 8A ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block8A.Attach(Led_Block8A);
            Sensor Led_TrackPowerTop = new Sensor("LLed_TrackPower", " Enable Track ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackPower.Attach(Led_TrackPowerTop);
            Sensor Led_Block5BIn = new Sensor("LLed_Block5BIn", " Occupied to 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block5BIn.Attach(Led_Block5BIn);
            Sensor Led_Block6In = new Sensor("LLed_Block6In", " Occupied to 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block6In.Attach(Led_Block6In);
            Sensor Led_Block7In = new Sensor("LLed_Block7In", " Occupied to 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block7In.Attach(Led_Block7In);
            Sensor Led_ResistorTop = new Sensor("LLed_Resistor", " Occupied Resistor ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Resistor.Attach(Led_ResistorTop);
            Sensor Led_Track1Top = new Sensor("LLed_Track1", " Trains On Fiddle Yard Track1 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track1.Attach(Led_Track1Top);
            Sensor Led_Track2Top = new Sensor("LLed_Track2", " Trains On Fiddle Yard Track2 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track2.Attach(Led_Track2Top);
            Sensor Led_Track3Top = new Sensor("LLed_Track3", " Trains On Fiddle Yard Track3 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track3.Attach(Led_Track3Top);
            Sensor Led_Track4Top = new Sensor("LLed_Track4", " Trains On Fiddle Yard Track4 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track4.Attach(Led_Track4Top);
            Sensor Led_Track5Top = new Sensor("LLed_Track5", " Trains On Fiddle Yard Track5 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track5.Attach(Led_Track5Top);
            Sensor Led_Track6Top = new Sensor("LLed_Track6", " Trains On Fiddle Yard Track6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track6.Attach(Led_Track6Top);
            Sensor Led_Track7Top = new Sensor("LLed_Track7", " Trains On Fiddle Yard Track7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track7.Attach(Led_Track7Top);
            Sensor Led_Track8Top = new Sensor("LLed_Track8", " Trains On Fiddle Yard Track8 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track8.Attach(Led_Track8Top);
            Sensor Led_Track9Top = new Sensor("LLed_Track9", " Trains On Fiddle Yard Track9 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track9.Attach(Led_Track9Top);
            Sensor Led_Track10Top = new Sensor("LLed_Track10", " Trains On Fiddle Yard Track10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track10.Attach(Led_Track10Top);
            Sensor Led_Track11Top = new Sensor("LLed_Track11", " Trains On Fiddle Yard Track11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track11.Attach(Led_Track11Top);
            Sensor Led_Block6 = new Sensor("LLed_Block6", " Occupied from 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block6.Attach(Led_Block6);
            Sensor Led_Block7 = new Sensor("LLed_Block7", " Occupied from 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block7.Attach(Led_Block7);
            Sensor Led_F10 = new Sensor("LLed_F10", " F10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F10.Attach(Led_F10);
            Sensor Led_M10 = new Sensor("LLed_M10", " M10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.M10.Attach(Led_M10);
            Sensor Led_TrackNoTop = new Sensor("Track_No", " Track Nr ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackNo.Attach(Led_TrackNoTop);
            Sensor Led_TrackPower15VTOP = new Sensor("LLed_TrackPower15V", " 15V Track Power ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackPower15V.Attach(Led_TrackPower15VTOP);

            Sensor Sns_ForceNextTrack = new Sensor("ForceNextTrack", " ForceNextTrack ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrainDriveOutPointer.Attach(Sns_ForceNextTrack);

            //Messages
            Message Msg_TrainDetectionTop = new Message("TrainDetectionFinished", " Train Detection Finished ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYAppVar.TrainDetection.Attach(Msg_TrainDetectionTop);
            Message Msg_TrainDetectionStarted = new Message("TrainDetectionStarted", " Train Detection Started ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYAppVar.TrainDetectionStarted.Attach(Msg_TrainDetectionStarted);
            Message Msg_FiddleYardStopped = new Message("FiddleYardStopped", " FiddleYard Auto mode Stopped ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardStopped.Attach(Msg_FiddleYardStopped);
            Message Msg_FiddleYardStart = new Message("FiddleYardStart", " FiddleYard Auto mode Start ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardStart.Attach(Msg_FiddleYardStart);
            Message Msg_FiddleYardNotHomed = new Message("FiddleYardNotHomed", " FiddleYard not homed, start homing ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardNotHomed.Attach(Msg_FiddleYardNotHomed);
            Message Msg_FiddleYardHomingFinished = new Message("FiddleYardHomingFinished", " FiddleYard homing finished ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardHomingFinished.Attach(Msg_FiddleYardHomingFinished);
            Message Msg_FiddleYardTrainObstruction = new Message("FiddleYardTrainObstruction", " FiddleYard train obstruction... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardTrainObstruction.Attach(Msg_FiddleYardTrainObstruction);
            Message Msg_FiddleYardTrackAligned = new Message("FiddleYardTrackAligned", " FiddleYard track aligned ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardTrackAligned.Attach(Msg_FiddleYardTrackAligned);
            Message Msg_TrainHasLeftFiddleYardSuccessfully = new Message("TrainHasLeftFiddleYardSuccessfully", " Train has left FiddleYard successfully ", (name, log) => SetMessage(name, log));
            m_FYAppVar.TrainHasLeftFiddleYardSuccessfully.Attach(Msg_TrainHasLeftFiddleYardSuccessfully);
            Message Msg_EMOPressed15VTrackPowerDown = new Message("EMOPressed15VTrackPowerDown", " EMO pressed, 15V Track Power down! ", (name, log) => SetMessage(name, log));
            m_FYAppVar.EMOPressed15VTrackPowerDown.Attach(Msg_EMOPressed15VTrackPowerDown);
            Message Msg_EMOPressed15VTrackPowerUp = new Message("EMOPressed15VTrackPowerUp", " EMO released, 15V Track Power up! ", (name, log) => SetMessage(name, log));
            m_FYAppVar.EMOPressed15VTrackPowerUp.Attach(Msg_EMOPressed15VTrackPowerUp);
            Message Msg_FiddleYardAutoModeStart = new Message("FiddleYardAutoModeStart", " FiddleYard Auto mode Start ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeStart.Attach(Msg_FiddleYardAutoModeStart);
            Message Msg_FiddleYardInit = new Message("FiddleYardInit", " FiddleYard init... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardInit.Attach(Msg_FiddleYardInit);
            Message Msg_FiddleYardAutoModeIsGoingToStop = new Message("FiddleYardAutoModeIsGoingToStop", " FiddleYard Auto mode is going to stop... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeIsGoingToStop.Attach(Msg_FiddleYardAutoModeIsGoingToStop);
            Message Msg_FiddleYardReset = new Message("FiddleYardReset", " FiddleYard Reset ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardReset.Attach(Msg_FiddleYardReset);
            Message Msg_FiddleYardInitFinished = new Message("FiddleYardInitFinished", " FiddleYard init Finished ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardInitFinished.Attach(Msg_FiddleYardInitFinished);
            Message Msg_FiddleYardApplicationRunning = new Message("FiddleYardApplicationRunning", " FiddleYard Application running... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardApplicationRunning.Attach(Msg_FiddleYardApplicationRunning);
            Message Msg_FiddleYardAutoModeIsStopped = new Message("FiddleYardAutoModeIsStopped", " FiddleYard Auto mode is Stopped ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeIsStopped.Attach(Msg_FiddleYardAutoModeIsStopped);
            Message Msg_CollectingTrainsEnabled = new Message("CollectingTrainsEnabled", " Collecting Trains enabled ", (name, log) => SetMessage(name, log));
            m_FYAppVar.CollectingTrainsEnabled.Attach(Msg_CollectingTrainsEnabled);
            Message Msg_CollectingTrainsDisabled = new Message("CollectingTrainsDisabled", " Collecting Trains disabled ", (name, log) => SetMessage(name, log));
            m_FYAppVar.CollectingTrainsDisabled.Attach(Msg_CollectingTrainsDisabled);
            //Message Msg_FiddleYardMoveAndF12Assert = new Message("FiddleYardMoveAndF12Assert", " FiddleYard Moving And F12 Assert!!! FiddleYard Stopped!!! ", (name, log) => SetMessage(name, log));
            //m_FYIOHandleVar.FiddleYardMoveAndF12Assert.Attach(Msg_FiddleYardMoveAndF12Assert);
            //Message Msg_FiddleYardMoveAndF13Assert = new Message("FiddleYardMoveAndF13Assert", " FiddleYard Moving And F13 Assert!!! FiddleYard Stopped!!! ", (name, log) => SetMessage(name, log));
            //m_FYIOHandleVar.FiddleYardMoveAndF13Assert.Attach(Msg_FiddleYardMoveAndF13Assert);
            Message Msg_FYNotHomed = new Message("FYNotHomed", " Fiddle Yard Not Homed! Press Home FY Button to start Homing... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FYNotHomed.Attach(Msg_FYNotHomed);
            #endregion Attach sensors

            // Init Track colors
            LLed_Track1.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track2.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track3.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track4.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track5.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track5.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track6.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track7.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track8.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track9.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track10.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track11.BackColor = m_FYAppVar.TrackNotInitializedColor;

            LLed_F10.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F10.ForeColor = Color.Black;
            LLed_F11.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F11.ForeColor = Color.Black;
            LLed_F12.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F12.ForeColor = Color.Black;
            LLed_F13.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F13.ForeColor = Color.Black;

            PB_Tr1_Active.BackColor = LLed_Track1.BackColor;
            PB_Tr1_Inline.BackColor = LLed_Track1.BackColor;
            PB_Tr1_Train.BackColor = LLed_Track1.BackColor;
            PB_Tr2_Active.BackColor = LLed_Track2.BackColor;
            PB_Tr2_Inline.BackColor = LLed_Track2.BackColor;
            PB_Tr2_Train.BackColor = LLed_Track2.BackColor;
            PB_Tr3_Active.BackColor = LLed_Track3.BackColor;
            PB_Tr3_Inline.BackColor = LLed_Track3.BackColor;
            PB_Tr3_Train.BackColor = LLed_Track3.BackColor;
            PB_Tr4_Active.BackColor = LLed_Track4.BackColor;
            PB_Tr4_Inline.BackColor = LLed_Track4.BackColor;
            PB_Tr4_Train.BackColor = LLed_Track4.BackColor;
            PB_Tr5_Active.BackColor = LLed_Track5.BackColor;
            PB_Tr5_Inline.BackColor = LLed_Track5.BackColor;
            PB_Tr5_Train.BackColor = LLed_Track5.BackColor;
            PB_Tr6_Active.BackColor = LLed_Track6.BackColor;
            PB_Tr6_Inline.BackColor = LLed_Track6.BackColor;
            PB_Tr6_Train.BackColor = LLed_Track6.BackColor;
            PB_Tr7_Active.BackColor = LLed_Track7.BackColor;
            PB_Tr7_Inline.BackColor = LLed_Track7.BackColor;
            PB_Tr7_Train.BackColor = LLed_Track7.BackColor;
            PB_Tr8_Active.BackColor = LLed_Track8.BackColor;
            PB_Tr8_Inline.BackColor = LLed_Track8.BackColor;
            PB_Tr8_Train.BackColor = LLed_Track8.BackColor;
            PB_Tr9_Active.BackColor = LLed_Track9.BackColor;
            PB_Tr9_Inline.BackColor = LLed_Track9.BackColor;
            PB_Tr9_Train.BackColor = LLed_Track9.BackColor;
            PB_Tr10_Active.BackColor = LLed_Track10.BackColor;
            PB_Tr10_Inline.BackColor = LLed_Track10.BackColor;
            PB_Tr10_Train.BackColor = LLed_Track10.BackColor;
            PB_Tr11_Active.BackColor = LLed_Track11.BackColor;
            PB_Tr11_Inline.BackColor = LLed_Track11.BackColor;
            PB_Tr11_Train.BackColor = LLed_Track11.BackColor;

            PB_Bk5_Train.Hide();
            PB_Bk6_Train.Hide();
            PB_Bk8A_Train.Hide();
            PB_Bk7_Train.Hide();

            PB_Bk7_Train.Image = null;
            PB_Bk8A_Train.Image = null;
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardSimTrain constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardSimTrain(string instance, iFiddleYardSimulator iFYSim, FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardSimulatorVariables FYSimVar)
        {
            m_FYSimVar = FYSimVar;
            m_iFYSim = iFYSim;
            m_FYIOHandleVar = FYIOHandleVar;
            m_instance = instance;

            Sensor Cmd_TargetAlive = new Sensor("TargetAlive", "TargetAlive", 0, (name, val, log) => SimulatorCmd(name, val, log)); // initialize and subscribe sensors
            m_FYSimVar.TargetAlive.Attach(Cmd_TargetAlive);
            Sensor TrackNo = new Sensor("Track_No", " Track Nr ", 0, (name, val, log) => SimulatorCmd(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackNo.Attach(TrackNo);

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimTrainTOP.txt"; //  different logging file per target, this is default
                FiddleYardSimTrainLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimTrainBOT.txt"; //  different logging file per target, this is default
                FiddleYardSimTrainLogging = new Log2LoggingFile(path);
            }

            Sensor Sns_FYSimSpeedSetting = new Sensor("FYSimSpeedSetting", " FYSimSpeedSetting ", 0, (name, val, log) => SimulatorSettings(name, val, log)); // initialize and subscribe sensors
            Siebwalde_Application.Properties.Settings.Default.FYSimSpeedSetting.Attach(Sns_FYSimSpeedSetting);
        }
        private FiddleYardIOHandleVariables m_FYIOHandleVar; // connect variable to connect to FYIOH class for defined variables

        #endregion Fields

        #region Constructors

        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardVariables constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardApplicationVariables(FiddleYardIOHandleVariables FYIOHandleVar)
        {
            m_FYIOHandleVar = FYIOHandleVar;

            // Instantiate Commands from FYFORM
            CmdFiddleOneLeft = new CommandUpdater();
            CmdFiddleOneRight = new CommandUpdater();
            CmdCouple = new CommandUpdater();
            CmdUncouple = new CommandUpdater();
            CmdFiddleGo1 = new CommandUpdater();
            CmdFiddleGo2 = new CommandUpdater();
            CmdFiddleGo3 = new CommandUpdater();
            CmdFiddleGo4 = new CommandUpdater();
            CmdFiddleGo5 = new CommandUpdater();
            CmdFiddleGo6 = new CommandUpdater();
            CmdFiddleGo7 = new CommandUpdater();
            CmdFiddleGo8 = new CommandUpdater();
            CmdFiddleGo9 = new CommandUpdater();
            CmdFiddleGo10 = new CommandUpdater();
            CmdFiddleGo11 = new CommandUpdater();
            CmdTrainDetect = new CommandUpdater();
            CmdFYStart = new CommandUpdater();
            CmdFYStop = new CommandUpdater();
            CmdReset = new CommandUpdater();
            CmdOcc5BOnTrue = new CommandUpdater();
            CmdOcc5BOnFalse = new CommandUpdater();
            CmdOcc6OnTrue = new CommandUpdater();
            CmdOcc6OnFalse = new CommandUpdater();
            CmdOcc7OnTrue = new CommandUpdater();
            CmdOcc7OnFalse = new CommandUpdater();
            CmdCollect = new CommandUpdater();
            CmdHomeFY = new CommandUpdater();

            // Instantiate actuators for sending command out to the target or simulator
            FiddleOneLeft = new ActuatorUpdater();
            FiddleOneRight = new ActuatorUpdater();
            Couple = new ActuatorUpdater();
            Uncouple = new ActuatorUpdater();
            //FiddleGo1 = new ActuatorUpdater();
            //FiddleGo2 = new ActuatorUpdater();
            //FiddleGo3 = new ActuatorUpdater();
            //FiddleGo4 = new ActuatorUpdater();
            //FiddleGo5 = new ActuatorUpdater();
            //FiddleGo6 = new ActuatorUpdater();
            //FiddleGo7 = new ActuatorUpdater();
            //FiddleGo8 = new ActuatorUpdater();
            //FiddleGo9 = new ActuatorUpdater();
            //FiddleGo10 = new ActuatorUpdater();
            //FiddleGo11 = new ActuatorUpdater();
            TrainDetect = new ActuatorUpdater();
            FYStart = new ActuatorUpdater();
            FYStop = new ActuatorUpdater();
            Reset = new ActuatorUpdater();
            Occ5BOnTrue = new ActuatorUpdater();
            Occ5BOnFalse = new ActuatorUpdater();
            Occ6OnTrue = new ActuatorUpdater();
            Occ6OnFalse = new ActuatorUpdater();
            Occ7OnTrue = new ActuatorUpdater();
            Occ7OnFalse = new ActuatorUpdater();
            HomeFY = new ActuatorUpdater();
            Collect = new ActuatorUpdater();

            CL10Heart = new SensorUpdater();
            F11 = new SensorUpdater();
            EOS10 = new SensorUpdater();
            EOS11 = new SensorUpdater();
            F13 = new SensorUpdater();
            F12 = new SensorUpdater();
            Block5B = new SensorUpdater();
            Block8A = new SensorUpdater();
            TrackPower = new SensorUpdater();
            Block5BIn = new SensorUpdater();
            Block6In = new SensorUpdater();
            Block7In = new SensorUpdater();
            Resistor = new SensorUpdater();
            // Trackx sensor is used internally in C#, not from target anymore
            Track1 = new SensorUpdater();
            Track2 = new SensorUpdater();
            Track3 = new SensorUpdater();
            Track4 = new SensorUpdater();
            Track5 = new SensorUpdater();
            Track6 = new SensorUpdater();
            Track7 = new SensorUpdater();
            Track8 = new SensorUpdater();
            Track9 = new SensorUpdater();
            Track10 = new SensorUpdater();
            Track11 = new SensorUpdater();
            Block6 = new SensorUpdater();
            Block7 = new SensorUpdater();
            F10 = new SensorUpdater();
            M10 = new SensorUpdater();
            TrackNo = new SensorUpdater();
            TrackPower15V = new SensorUpdater();
            CmdBusy = new SensorUpdater();
            TrainDriveOutPointer = new SensorUpdater();
            ReceivedDataFromMip50 = new SensorUpdater();

            FiddleYardStopped = new MessageUpdater();
            FiddleYardStart = new MessageUpdater();
            FiddleYardNotHomed = new MessageUpdater();
            FiddleYardTrainObstruction = new MessageUpdater();
            FiddleYardTrackAligned = new MessageUpdater();
            TrainHasLeftFiddleYardSuccessfully = new MessageUpdater();
            EMOPressed15VTrackPowerDown = new MessageUpdater();
            EMOPressed15VTrackPowerUp = new MessageUpdater();
            FiddleYardAutoModeStart = new MessageUpdater();
            FiddleYardInit = new MessageUpdater();
            FiddleYardAutoModeIsGoingToStop = new MessageUpdater();
            FiddleYardReset = new MessageUpdater();
            FiddleYardInitFinished = new MessageUpdater();
            FiddleYardApplicationRunning = new MessageUpdater();
            FiddleYardAutoModeIsStopped = new MessageUpdater();
            CollectingTrainsEnabled = new MessageUpdater();
            CollectingTrainsDisabled = new MessageUpdater();
            FYNotHomed = new MessageUpdater();
            TrainDetection = new MessageUpdater();
            FiddleYardHomingFinished = new MessageUpdater();
            TrainDetectionStarted = new MessageUpdater();

            FormCollect = new CommandUpdater();

            //Sensors
            Sensor Sns_CL_10_Heart = new Sensor("CL10Heart", " CL 10 Heart ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.CL10Heart.Attach(Sns_CL_10_Heart);
            Sensor Sns_F11 = new Sensor("F11", " F11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.F11.Attach(Sns_F11);
            Sensor Sns_EOS10 = new Sensor("EOS10", " EOS 10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.EOS10.Attach(Sns_EOS10);
            Sensor Sns_EOS11 = new Sensor("EOS11", " EOS 11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.EOS11.Attach(Sns_EOS11);
            Sensor Sns_F13 = new Sensor("F13", " F13 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.F13.Attach(Sns_F13);
            Sensor Sns_F12 = new Sensor("F12", " F12 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.F12.Attach(Sns_F12);
            Sensor Sns_Block5B = new Sensor("Block5B", " Occupied from 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block5B.Attach(Sns_Block5B);
            Sensor Sns_Block8A = new Sensor("Block8A", " Occupied from 8A ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block8A.Attach(Sns_Block8A);
            Sensor Sns_TrackPower = new Sensor("TrackPower", " Enable Track ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackPower.Attach(Sns_TrackPower);
            Sensor Sns_Block5BIn = new Sensor("Block5BIn", " Occupied to 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block5BIn.Attach(Sns_Block5BIn);
            Sensor Sns_Block6In = new Sensor("Block6In", " Occupied to 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block6In.Attach(Sns_Block6In);
            Sensor Sns_Block7In = new Sensor("Block7In", " Occupied to 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block7In.Attach(Sns_Block7In);
            Sensor Sns_Resistor = new Sensor("Resistor", " Occupied Resistor ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Resistor.Attach(Sns_Resistor);
            //Sensor Sns_Track1 = new Sensor("Track1", " Train On Fiddle Yard Track1 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track1.Attach(Sns_Track1);
            //Sensor Sns_Track2 = new Sensor("Track2", " Train On Fiddle Yard Track2 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track2.Attach(Sns_Track2);
            //Sensor Sns_Track3 = new Sensor("Track3", " Train On Fiddle Yard Track3 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track3.Attach(Sns_Track3);
            //Sensor Sns_Track4 = new Sensor("Track4", " Train On Fiddle Yard Track4 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track4.Attach(Sns_Track4);
            //Sensor Sns_Track5 = new Sensor("Track5", " Train On Fiddle Yard Track5 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track5.Attach(Sns_Track5);
            //Sensor Sns_Track6 = new Sensor("Track6", " Train On Fiddle Yard Track6 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track6.Attach(Sns_Track6);
            //Sensor Sns_Track7 = new Sensor("Track7", " Train On Fiddle Yard Track7 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track7.Attach(Sns_Track7);
            //Sensor Sns_Track8 = new Sensor("Track8", " Train On Fiddle Yard Track8 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track8.Attach(Sns_Track8);
            //Sensor Sns_Track9 = new Sensor("Track9", " Train On Fiddle Yard Track9 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track9.Attach(Sns_Track9);
            //Sensor Sns_Track10 = new Sensor("Track10", " Train On Fiddle Yard Track10 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track10.Attach(Sns_Track10);
            //Sensor Sns_Track11 = new Sensor("Track11", " Train On Fiddle Yard Track11 ", 0, (name, val, log) => UpdateTrainsOnFY(name, val, log)); // initialize and subscribe sensors
            //m_FYIOHandleVar.Track11.Attach(Sns_Track11);
            Sensor Sns_Block6 = new Sensor("Block6", " Occupied from 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block6.Attach(Sns_Block6);
            Sensor Sns_Block7 = new Sensor("Block7", " Occupied from 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.Block7.Attach(Sns_Block7);
            Sensor Sns_F10 = new Sensor("F10", " F10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.F10.Attach(Sns_F10);
            Sensor Sns_M10 = new Sensor("M10", " M10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.M10.Attach(Sns_M10);
            Sensor Sns_TrackNo = new Sensor("Track_No", " Track Nr ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackNo.Attach(Sns_TrackNo);
            Sensor Sns_CmdBusy = new Sensor("CmdBusy", " uController busy ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.CmdBusy.Attach(Sns_CmdBusy);
            Sensor Sns_TrackPower15V = new Sensor("TrackPower15V", " 15V Track Power ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackPower15V.Attach(Sns_TrackPower15V);

            Command Act_Collect = new Command(" Collect ", (name) => FormCmd(name)); // Catch Form command pass to subscribers
            CmdCollect.Attach(Act_Collect);

            Colorc Clr_FYTrackOccupiedColorSetting = new Colorc(Color.Transparent, "Clr_FYTrackOccupiedColorSetting", (NewColor, log) => SetColorIndicator(NewColor, log));
            Siebwalde_Application.Properties.Settings.Default.SWSetColorTrainOccupied.Attach(Clr_FYTrackOccupiedColorSetting);

            Colorc Clr_FYTrackNotInitializedColorSetting = new Colorc(Color.Transparent, "Clr_FYTrackNotInitializedColorSetting", (NewColor, log) => SetColorIndicator(NewColor, log));
            Siebwalde_Application.Properties.Settings.Default.SWSetColorTrackNotInitialized.Attach(Clr_FYTrackNotInitializedColorSetting);

            Colorc Clr_FYTrackNotActiveColorSetting = new Colorc(Color.Transparent, "Clr_FYTrackNotActiveColorSetting", (NewColor, log) => SetColorIndicator(NewColor, log));
            Siebwalde_Application.Properties.Settings.Default.SWSetColorTrackNotActive.Attach(Clr_FYTrackNotActiveColorSetting);

            Colorc Clr_FYTrackDisabledColorSetting = new Colorc(Color.Transparent, "Clr_FYTrackDisabledColorSetting", (NewColor, log) => SetColorIndicator(NewColor, log));
            Siebwalde_Application.Properties.Settings.Default.SWSetColorTrackDisabled.Attach(Clr_FYTrackDisabledColorSetting);

            Colorc Clr_FYTrackDisabledNotOccupiedColorSetting = new Colorc(Color.Transparent, "Clr_FYTrackDisabledNotOccupiedColorSetting", (NewColor, log) => SetColorIndicator(NewColor, log));
            Siebwalde_Application.Properties.Settings.Default.SWSetColorTrackDisabledNotOccupied.Attach(Clr_FYTrackDisabledNotOccupiedColorSetting);

            for (int i = 1; i < 12; i++)
            {
                icheckBoxTrack[i] = 1;      // Init all tracks disabled
            }

            FYHomed.BoolVariable = false;   // Init variable
        }